Mousse au Chocolat or Chocolate Mousse Recipe

Serves 8 to 10

  • 4 x 1 ounce-squares unsweetened chocolate
  • 3/4 cup sugar
  • 1/4 cup water
  • 6 eggs, separated
  • 2 tablespoons dark rum
  1. In top of double saucepan combine chocolate, sugar and water. Cook over hot water, stirring occasionally, until chocolate is melted.
  2. Add egg yolks, one at a time, beating well after each addition. Remove from heat; cool.
  3. Meanwhile, in mixing bowl beat egg whites until stiff but not dry.
  4. Stir rum into chocolate mixture; pour over egg whites. Fold gently until well blended.
  5. Turn into individual dishes or large serving bowl. Refrigerate for 12 hours.

message=class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext When Mocking Static Methods in Class

When mocking static classes with Junit4, Mockito and PowerMock, you may see the following log messages after annotating your test class if the code that you are testing is making HTTP connections:

message=class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLSContext not a SSLContext

Your annotations for the class (or method) typically include the following:

@RunWith(PowerMockRunner.class)
@PrepareForTest({ SomeClassYouWantToMock.class })

This may cause some confusion, especially if whatever other code that you may have ONLY uses HTTP. Add the following to your annotations to tell PowerMock loading of the following classes.

@PowerMockIgnore({ "javax.net.ssl.*" })

This should prevent PowerMock from loading different class definitions that are used by your HTTP library.

Creating a Counter or Progress Bar for a Python Program

I’ve written a number of Python apps where I would like it to print some sort of counter or progress bar to STDOUT to let me know that it is still running instead of locked up or died somehow without me being able to see it.

I had tried using a couple of different existing progress bar related modules but none of them really worked except in a very specific use case.

So, after a bit of futzing around I came up with a very simple way to print out a updating counter to STDOUT. The synchronization code was gleaned from this post here, thank you Daniel.

Following is a working example for Python 3.7. You could write your own implementation of the progress function to render whatever you want to STDOUT.

import threading
import sys
import time

def synchronized(func):
    func.__lock__ = threading.Lock()
    def synced_func(*args, **kws):
        with func.__lock__:
            return func(*args, **kws)
    return synced_func

total = 0

@synchronized
def progress(count):
    global total
    total += count
    sys.stdout.write(f'\rtotal: [{total}]')
    sys.stdout.flush()

for i in range(500):
    progress(1)
    time.sleep(0.01)

print(f'\nFinished...')

Running this will generate the following output with the total value dynamically updating as the application runs:

(progressbar) rchapin@leviathan:progressbar$ python progressbar.py 
total: [500]
Finished...

How To Spy and Verify a Static Void Method in Java

The Mockito and PowerMockito libraries for JUnit4 are not always the most intuitive.

Following is an example of how to spy and verify a static void method.

    @Test
    public void testAdd() {

        // Prepare the Utils class to be spied.
        PowerMockito.spy(Utils.class);

        // Run the test and get the actual value from the OUT
        int actualValue = App.add("Test1", 1, 1);

        /*
         * To verify the number of times that we called Utils.doSomething we
         * first need to tell the PowerMockito library which class we are
         * verifying and how many times we are verifying that action.
         */
        PowerMockito.verifyStatic(Utils.class, Mockito.times(1));

        /*
         * Then, and this is not at all intuitive, we have to call the method
         * ourselves with the same parameters that we are expecting to have been
         * called. This tells PowerMockito which method invocation is to be
         * verified.
         */
        Utils.doSomething(Mockito.anyString(), Mockito.anyInt(), Mockito.anyInt());

        assertEquals(2, actualValue);
    }

The complete example can be found here.

Using sed with regex capture groups

There are many times when you have a file from which you want to extract specific strings based on a regex and using a capture group is a very efficient way to parse multiple strings from the same line.

I have found that sed is the easiest way to do so on the Linux command line.

Given the following input file:

This is a line of text with a year=2020 month=12 in it
This line of text does not have a year or month in it
This year=2021 is the current year the current month=1
This is the year=2021 the month=2

Let’s say that you want to extract the year and the month digits from each line and generate a line of output for each line if input that looks like:

my year: <year>, my month: <month>

You would run the following command defining two capture groups:

sed -rn 's/.*year=([0-9]+).*month=([0-9]+).*/my year: \1, my month: \2/p' input.txt

Which will output:

my year: 2020, my month: 12
my year: 2021, my month: 1
my year: 2021, my month: 2

The -rn flag tells sed to use extended regular expressions in the script and to suppress printing unless explicitly directed after we make a match.

The s command tells sed that we are going to execute a substitution and that we will define a regex, a replacement string, and optional flags.

.*year=([0-9]+).*month=([0-9]+).*

Defines two capture groups. One to look for any number of contiguous digits after year= and another for any number of contiguous digits after month=. The .* explicitly tells sed that we want to ignore any number of any type of characters between the defined groups.

my year: \1, my month: \2/p

Tells sed how to format the output to include each capture group, \1 for capture group 1 and \2 for capture group 2.

Configuring rsyslog to rotate log files from log messages streamed to it from a Systemd service

In general, I have moved to writing all of my applications to write their log output to STDOUT. This makes running them on the command line, in an IDE, on a bare metal box, VM, or in a container completely decoupled from how you store and view the logs. No more having multiple logging configs for each flavor of deployment.

In this particular case, I am running an application in a container (but it isn’t necessary that it is in a container) controlled by systemd and using rsyslog to forward all of the log messages to a specific output file. A requirement of writing log files to a local disk is that you must be able to rotate and truncate them by size so that you don’t fill up your disk; in either normal operation or some error condition that ends up inadvertently generating a large amount of log messages in a short period of time.

For the following example, we will us the service identifier my_program_identifier. You will update this to define something relevant to your deployment.

To configure your service in this manner you first need to add the appropriate options to the [Service] section of your unit file.

StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=my_program_identifier

Then you define an rsyslog.d config file as follows for my_program.conf

$outchannel my_program_log_rotation,/var/log/my_program/my_program.log, 1073741824, /etc/my_program/log-rotate.sh

if $programname == "my_program_identifier" then :omfile:$my_program_log_rotation
& stop

In the rsyslog conf file we define an Output Channel. The TLDR; is that an output channel enables you to define the file name to which you want to write, the max size (in bytes) and a command (or path to a script or program) to run when the file reaches the limit.

In the previous example, we declare an output channel with the $outchannel directive. We then give it the identifier my_program_log_rotation. Then define the path of the log file, the max size, and a shell script that will run to rotate the file for us.

The next line defines how to act upon each of the log messages with the "my_program_identifier" that we defined in the unit file.

Following is a working sample of the log-rotate.sh script.

#!/bin/bash
  
LOG_DIR=/var/log/my_program
FILE_NAME=my_program.log
MAX_NUM_FILES=10

for i in `ls -1 $LOG_DIR/${FILE_NAME}.* | sort --field-separator=. -k3 -nr`
do
  # Grab the number (last token) for all of the numbered files
  log_num=$(echo "$i" | awk -F\. '{print $NF}')

  # If it is equal to or greater than our max number of files
  # just delete it.
  if [ "$log_num" -ge $MAX_NUM_FILES ]
  then
    rm $i
    continue
  fi

  target_num=$((log_num + 1))
  target_file_name="$LOG_DIR/${FILE_NAME}.${target_num}"
  mv -f $i $target_file_name
done

mv -f $LOG_DIR/$FILE_NAME $LOG_DIR/${FILE_NAME}.1

Deploy your updated unit file, your rsyslog.d conf file, and the shell script and you should have it up and running.

12×9 Sheet Pan Cookie Cake

This is for a 12×9 inch sheet pan cookie cake.

Ingredients

  • 3 cups all-purpose flour
  • 1 TBSP cornstarch
  • 1 1/2 tsp baking soda
  • 1/2 tsp salt
  • 1 cup light brown sugar
  • 1/3 cup granulated sugar
  • 2 1/4 cups unsalted butter
  • 1 cup dark or semi-sweet chocolate chips
  • 2 eggs
  • 1 TBSP vanilla extract

If you have a stand mixer this is much easier, but if all you have is a hand mixer that will work too.

  1. Preheat oven to 350 F
  2. Line the sheet pan with parchment paper
  3. Cream the butter
  4. Mix the sugar into the creamed butter
  5. Add the egg and vanilla and mix well
  6. Mix the flour, cornstarch, baking soda and salt
  7. Add the flour slowly, mixing it into the butter/sugar mix
  8. Mix n the chocolate chips
  9. Press the dough into the pan, but don’t pack it too tightly. Ensure that you make it an even layer.
  10. Bake it on the center rack for about 15 minutes. Rotate it about one half way through so that it will cook evenly.
  11. Turn on the broiler and watch it very carefully. You’ll want to take it out as soon as you start to see it browning on the surface. Leave it too long and you can easily burn it. Most likely, less than 1 minute.
  12. Let cool to room temp and then decorate.

[SOLVED] Unable to Sign-In to Gmail with Thunderbird with OAuth2, Keeps Asking for Email or Phone Over and Over

If you are setting up Thunderbird to use your Gmail account you may find that when Thunderbird opens a new window to a Google web portal into which you are to provide your email address and password that it will keep asking you over and over again for your email and never enable to you to enter the password.

This occurs when Thunderbird’s privacy settings do not allow it to store cookies.

First, ensure that your gmail account has Allow insecure apps off. Unfortunately, it may take some time for this setting to propagate to your account.

Than, go to Preferences > Privacy and under Web Content check the Accept cookies from sites checkbox.

Return to your account settings when when prompted you should now be able to enter your credentials to grant Thunderbird access to your account.

How to Find Ingested Foreign Objects in Poop

Admittedly, not the most savory subject. But, for those of us with pets and/or children it is sometimes a necessity to try to find a previously ingested foreign object in feces to make sure that it does not cause medical problems in the person or animal that has accidentally eaten it.

Recently, we thought our dog had eaten a relatively small magnet and figured that we would have to be checking his feces over the next few days to ensure that he passed it. I’ve not had to do this before and off the top of my head I didn’t know the best way to go about it. Turning to the Internet, all of the searches with the exact same title as this blog article turned up other articles about how long things take to move through the digestive tract. That you should call your Dr. or Vet. But nothing that specifically said how to actually search for the object in the offending matter.

Eventually, I found a blog posting on some dog owner site with a very good suggestion and here is what I did.

  1. Collect the feces as you normally would in a poop bag and bring it home.
  2. Cut open the bag and dump it in a quart sized or bigger ziplock freezer bag. The bigger the bag (to a point) the better.
  3. Shake the feces to the bottom of the bag and lay it flat on your driveway, sidewalk, or similarly hard surface outside. Doing it outside makes clean-up much easier if the bag develops a rip.
  4. Squeeze as much air out of the bag as possible while smooshing the feces out such that it is transformed into a thin layer inside the bag.
  5. While doing so, you will easily find all but the smallest of objects just by feeling it through the bag without getting your hands dirty.
  6. Once you identify it, you can either retrieve it from the bag and clean it off, or just toss it knowing that your child/pet has passed the item safely.