Thursday, August 4, 2016

Re-cap on NAD 3020 Stereo Amplifier

A few weeks back I started hunting for a turntable and amplifier. My dad had his old kit boxed up in my parents' garage and he was happy to give the NAD 3020 amp and Onkyo CP-1010A turntable a new home!

After connecting all the gear, everything sounded good (so, so good), but occasionally the right stereo channel would drop out. A sharp tap on the amplifier would bring it back. Apparently this is symptomatic of failed or failing capacitors, because electrolytic capacitors are generally not designed to last 30 years or more.

I found the service manual for the NAD 3020 online and was amazed to find a full design circuit diagram, parts list, and labelled circuit board wiring diagram. Replacing the caps was going to be easy.

I put together a quick parts list of all the capacitors I had to replace - 42 in total. Only the electrolytic capacitors required replacement because the conductive electrolyte inside them can (and did) leak over time. The ceramic and mylar capacitors inside all passed a visual inspection.

I placed a Digikey order (~$60 for the bare minimum parts but I ordered spares and ended up around ~$90) and warmed up my soldering iron. Sure enough, a good number of the caps were trashed:

One daugherboard with caps removed. You can see the gunk where the electrolyte leaked in at least two places.

The order arrived and I started installing new caps Here's that daugherboard back in place. Anything blue or gold in this pic is brand new:

These 2200 μF caps were the biggest, and replaced 4 completely trashed caps on the input power filtering (I think). All the new parts were different brands and dimensions than the old ones, but that's okay. For cap replacements, as long as the capacitance is the same and the voltage rating matches or lightly exceeds the original, you should be good. Or so I read.

Powered back up!

The first thing I noticed was that everything sounded a bit sharper, but the amp still has a beautiful warm tone. When I listen to music on this setup, I am amazed to hear new details in songs I've heard hundreds of times - instrumental trills, soft vocals, basslines, and more.

Monday, June 20, 2016 Fantasy Baseball Score Checker

I've been hacking away on a project for my fantasy baseball league.'s fantasy baseball has its daily scoreboard in flash, so it doesn't work on mobile.

Not only did I want to check my score on mobile, I thought having easily accessible scores on mobile would make things more engaging for the whole league!

I wrote a python script to scrape values from MLB servers and display them in a simple interface:

This league has classy team names. 
The basic flow of the script is:
  1. Get the fantasy league schedule JSON data from this URL:
    Note the league_id can be found with CTRL-F if you "view source" on your league homepage.
  2. Process the fantasy league schedule and build a big Python dictionary called this_week (I should have built a class - maybe that's on the todo list). This step figures out all of the fantasy team_id's that belong to your league_id.
    Also, build each team's roster based on the fantasy team roster data. The period_id comes from the schedule data, and the player_ids come from here:
  3. Figure out which games are being currently played in real life. This can be done by counting the number of folders containing matching regex gid_[0-9]{4}_[0-9]{2}_[0-9]{2}[a-z0-9_]* from this directory: (substitute today's date)
    Specifically, we are looking for the boxscore.json files for each game:
    We are going to use these to calculate the fantasy points for each player's real-life stats.
  4. Grab every boxscore.json file for today's real-life games, read the data and build a monster dictionary called super_boxscore.
  5. Loop through all of the fantasy player rosters in the this_week variable,  and look up the player_ids in the super_boxscore variable. Calculate fantasy points for each player_id.
  6. Show the results!
I wrote most of this blog post a month ago, intending to add more features and make a richer blog post. Sadly, like many of my projects it has stalled at nowhere near completion and I have not put in any time over the last 4-5 weeks! 

But if you are running an fantasy league and you want a better mobile interface for your members, check out my project on Github: 

Thursday, May 12, 2016

Automatically Generate Screenshots of Foxboro I/A Graphics

At work we have a Foxboro I/A control system. I was getting a lot of requests to take screenshots of control system graphics - which I don't mind fulfilling, because usually someone wants to make something better.

I wanted a better way to fulfill these requests! Something that can do everything at once.

I found an old post on the "Foxboro Freelist", a user-run mailing list for Foxboro system maintainers. Back in November I posted an improved version, but I have improved it again since (continue reading).
for DISP in $(find /opt/graphics/disp/ /opt/graphics/control/ /opt/graphics/trend/ /opt/graphics/loadout/disp/ /opt/graphics/powerhouse/ -name "*.fdf")
cd d:
pref -SPR1SR dmcmd /opt/graphics/disp/BLANKSCRN.fdf
sleep 2
echo $DISP
pref -SPR1SR dmcmd $DISP
sleep 5
cd 'C:/Program Files (x86)/HyperSnap 6'
echo $PWD
FILE=$(echo `date +%Y-%m-%d`$DISP | sed 's/\//-/g')
echo $FILE
echo $SAV
HprSnap6 -snap:awin -save:png $SAV
pref -SPR2SR dmcmd close

  • In the first FOR statement, you can specify as many graphics subfolders as you want. 
  • Replace SPR1SR with the DM (Display Manager) name of the FoxView instance you will be working on. The script calls the graphic to the DM you specify, then calls HyperSnap via its command line interface to take a screenshot. 
    • Just to be clear, the script WILL open these graphics live on your AW (application workstation) and take a screenshot. It won't happen in the background. So if you have any graphics that invoke scripts when opened or closed, exclude those folders from the FOR statement. 
    • This will tie up your AW for however long it takes to open all of your graphics. I like to run the script at the end of the day. If the screensaver comes on, it does not seem to matter. 
  • Create a blank graphic (BLANKSCRN.fdf) for the script to call in between live process graphics. 
  • The sleep commands are necessary because Foxboro users know that graphics don't load instantly - graphics need to query data from the OM (Object Manager) before they're usable. 
  • Assumes you have HyperSnap 6 installed (should ship with all AW's)
  • The output file is named with the date, folder path and filename. For example, 2016-05-12-path-to-graphic-filename.fdf.png. 
  • The echo statements are unnecessary, but it is useful to see their output for debugging. 
  • Save the above as a .ksh file and run in the Kornshell environment. 
  • If you want to generate screenshots of overlay files (popups), change this:
    • pref -SPR1SR dmcmd $DISP
    • to this:
    • pref -SPR1SR dmcmd "dmcmd ov $DISP -l MIDDLE -move"
Since coming up with this script, we generate screenshots of 200+ graphics on a monthly basis and drop them in a network folder on our Business LAN. This way, anyone who is interested can take a look at the current state of the control graphics, find errors and suggest improvements. 

Drop me a line if you find this through Google - I'd love to know if this helped you out!

Update 2016-05-27: I've put this up on Github so people can download the .ksh directly, or contribute to making it better!

Wednesday, April 6, 2016

Quiche Lorraine

More Great British Bake Off-inspired cooking - I made Quiche Lorraine today. I've never made a quiche before in my life! It was fun and delicious.

I found this recipe that was the main inspiration, but I wanted to add broccoli so I took some hints from this recipe too. I also have a 22cm tin and the recipe called for 20cm, so I tried to scale everything up a bit.

Final ingredients list for my version:

100g butter, cubed
200g all-purpose flour
3 1/4 tbsp cold water

Hand mix flour & butter to crumb consistency, add water, form dough ball, roll out on floured counter, set in tin, refrigerate 20-30 minutes, blind bake 10 minutes at 450 degrees, remove blind and bake 10 more minutes.

6 strips of bacon
1 big onion, sliced & carmelized
1 medium broccoli crown, cut small and added to the onions for the last 10 min of carmelization
160g Gruyère cheese, grated 4 large eggs
200 ml whipping cream
100 ml whole milk
Salt & pepper

It ended up taking about 40-45 minutes in the oven at 350 degrees.


It was GREAT if I do say so myself! Could have used a bit more salt, a bit more filling overall, but I'd make this again for sure.

Sunday, February 28, 2016

Great British Bake Off

Robyn got me hooked on this show called the Great British Bake Off. It has inspired me to try baking a couple of the tastier looking things on the show.

Here is Mary Berry's Lemon Tart:

Not bad for a first crack!

Here is a fruit tart that uses the same sweet crust recipe as the lemon tart, with a crème pâtissière (from this recipe) filling. The crust turned out nicer looking this time:

The recipes are brilliant because they're in grams; you can't possibly muck up the measurements.

I made one slip up on the fruit tart. I used Masa Harina for "corn flour", but I should have used corn starch (only the US and Canada refer to "corn starch", the rest of the world calls it corn flour"). It still tastes fine, but the texture is a little bit off. The other UK-ism is that caster sugar is sold as berry sugar in Canada.

Saturday, February 6, 2016

Homemade Soylent (Schmilk)

In 2013 I read about Soylent, a "nutritionally complete" meal replacement beverage invented by a software engineer, who started a 30-day experiment to see if he could survive on the stuff. His experiment morphed into a crowdfunding campaign with a feed-the-world-cheaply theme and he raised millions of dollars to start mass-producing it for sale.

Do people need "real food" to survive and thrive, or can we break food into its macro- and micronutrient components and reassemble those pieces to create something equivalent? Possibly better?

A lot of people were intrigued by the same question and the "powdered food scene" seemed to grow a lot in 2013 & 2014.

The shipping date of Soylent to Canada was never confirmed. When I started getting serious about losing weight in 2015 I started doing some research on homemade, powdered food meal replacements. The appeal was:

  • Easily portionable and measureable (to meet caloric needs)
  • Inexpensive 
  • Easily hackable (for instance, easy to bump up the protein content or lower the carbohydrate content by adjusting the formula) 
  • The buzz-phrase "nutritionally complete" kept popping up. 

As it turns out, Soylent (the company) hosts a recipe section on their website where users can submit and review recipes.

A 450-calorie serving of homemade Soylent

I found one called Schmilk Chocolate that I thought I'd try. It uses whole milk as a source of fat and protein. I made a batch and had it for breakfast every day for a week. It was pretty good! Bland, but not offensively so.

Since early summer 2015, I have been eating/drinking this homemade Soylent every workday for both breakfast and lunch. For supper and meals on weekends I have "real food". I have observed no ill-effects whatsoever (including excess flatulence, which some Soylent users had trouble with).

The positives are:

  • Easy to make. I mix the powdered ingredients with whole milk a meal ahead; the consistency is better if it sits in the fridge for a while.  
  • Easy to measure (12.6 grams of powder + 100 ml of whole milk = 108 calories. Scale however is appropriate. I started drinking 670 calorie portions, then 550, currently 450). 
  • Easy to consume - you just drink it! 
  • Tastes okay. Hard to describe; it's so bland that there are not any defining offensive flavours. The balance of fat, salt, and everything else seems to tell the body "this is good". I usually add an espresso shot for flavour. 
  • Makes me feel satiated and satisfied until the next meal. 
  • Keeps me regular.
Now that I'm basically at my goal weight, I don't think I am going to stop with Soylent any time soon. It's a part of my routine, and something I miss if my routine is interrupted. 

Recipe - Schmilk Chocolate - "5 day" Batch

1 kg Oat Flour (Only Oats brand comes in 1 kg bags) 
60 g Cocoa powder
53 g Acacia Fibre
30 g Psyllium Husk powder
16 g Iodized Salt 
5.5 g Potassium Citrate 
5.5 g Choline Bitartrate 
2 g Stevia Powder 
1.5 g Xanthan Gum 
5 g (or 5 daily servings) Multivitamin (powder)
9500 ml Whole Milk

Recipe notes:
  • Most ingredients can be found in health food stores, all can be found online. 
  • Mix all dry ingredients ahead of time.
  • Food scale required. 
  • 12.6 g powdered mixture + 100 ml whole milk = 108 calories.
  • Recommend mixing at least 1 hour before consuming for better consistency. 

Friday, January 29, 2016

Weight Loss

I think I've got this weight loss thing figured out.

In Montreal in 2011, I started writing a blog post called "Losing weight with common sense", because I was going to make all of these "sensible" changes to melt off the pounds, and hold myself accountable by blogging. Thankfully, I never hit the submit button, and those sensible changes - like eating an enormous plate of salmon and broccoli with a side of four beers and a half bag of chips for an evening snack - never paid off.

I've been overweight since my early teens. By World Health Organization standards, that means having a BMI of >25. In at least part of my high school years I was obese (>30 BMI - at 6'5" that's >114.7 kg or >253 lbs). I wasn't interested in sports, and I sure wasn't interested in moderation. I didn't particularly care, and I didn't have the understanding/knowledge to do anything differently.

In October 2014 I got a Fitbit One to use as a silent wake-up alarm, because Robyn couldn't stand my old alarm clock. Putting a step tracker in my pocket piqued some interest in weight management and I started occasionally tracking my weight for the heck of it. I clocked in at 113.4 kg; just a hair under "obese" on the BMI scale.

In November of that year, Robyn's dad passed away suddenly and unexpectedly. He was in his 50's, healthy and active. This was shocking. I started thinking - a lot - about the limited time we have on Planet Earth. I was 28; about half Paul's age.

By Spring of 2015 I had been fiddling with the Fitbit app, and mustering up inspiration to get serious about changing my habits, health and appearance. I had been reading posts in reddit's r/Fitness, r/loseit and r/fatlogic. r/fatlogic was actually the best inspiration - the subreddit showcases examples of anything that "deviates from the scientific facts of body weight management". It was a wake-up call to recognize some of those behaviours in myself (those small internal justifications I made before smashing a whole bag of Ruffles All-Dressed potato chips).

I learned that diet is the key to weight management, not exercise (although I do not dispute the value of exercise!). I learned about calories, got a food scale, and started counting.

I couldn't believe how effective it was. I plugged in a weight loss target into the MyFitnessPal app (0.5 kg/week) and it gave me a calorie allowance. By maintaining the discipline to weigh and count everything that went into my body (and estimating generously when nutritional info was unavailable), the weight disappeared at a perfectly consistent rate:

Weight loss target was 0.5 kg/week from April to December. Slowed down to 0.25 kg/week in December. Almost at my "maintenance weight" target of 85kg. 


Starting weight: 113.4 kg (250 lbs) - October 2014
Starting BMI: 29.6
Starting waist: 38-40"

Current weight: 85.7 kg (189 lbs) - Today
Current BMI: 22.4
Current waist: 34"

A couple tricks I used to stay motivated:

  • Daily weigh-ins, but ignore daily fluctuations. This built a rich data set and let me see that the day-to-day doesn't matter so much as the week-to-week and month-to-month. It's about lifestyle changes, not daily changes. 
  • Didn't give up up my love for snacks, just found different snacks. Tomato basil rice cakes smothered in hot sauce and beef jerky, mmm. 
  • Log absolutely everything. Estimate high if unsure. 
  • Try my best to avoid going over daily calorie limits. If I go over, it's not the end of the world. Just hit my limit the next day. 
  • Ditched the calorie counting features in Fitbit for MyFitnessPal - a much better app and food database. 
  • The key has really been education and understanding. I failed in 2011 because I thought motivation was enough to succeed. Success, at least for me, is dependent on knowledge, goal-setting, and data. 
  • Because I have the knowledge, I feel I can maintain these habits indefinitely. It's not a quick fix, it's a lifestyle change. 
Next steps - turn 30 in April with a healthy BMI for the first time in over half of my life, maintain current weight around the 85kg mark, turn remaining fat stores into muscle starting this spring when I can get out and start running again. That's a blog post for another day! 

Feels good, man.