Running a PHP Script on a QNAP TS-431

I needed to setup a persistent cron job on my QNAP TS-431 that would run a PHP script (actually the script that let’s me always know what the IP address of my home router is from anywhere in the world). However, the QNAP has the php executable buried and the directory is not in the $PATH environment variable. It’s not too hard to find though, if you need to run a PHP script just do this:

mnt/ext/opt/apache/bin/php /path/to/some-php-script.php

Specify a SSH Key for rsync

If you use rsync with the -rsh=ssh option it looks for a private key called id_rsa in the ~/.ssh folder. If (for whatever reason) you want to specify a different private key from the default then you can do it with:

-e ‘ssh -i /some/path/some_key’

This can be useful if want a key per host. Or, if like me, you idiotically created the keys with a different name than the default.

Persist crontab Entries on QNAP TS-431

QNAP helpfully explains how to add items to crontab on one of the NAS machines on their wiki here. Less helpfully they don’t explain that adding jobs with crontab -e and then restarting the cron daemon won’t persist through a reboot. Yay. However, you get around this by adding jobs directly to /etc/config/crontab. Thanks fellas.

Brew Day 14 – Sweet Stout

It seems counter-intuitive to be brewing a stout on only the fifth day of Autumn in southern Australia as the weather is still hot, not exactly the best weather for a stout. Stouts, I am told, do benefit from a month or two in a secondary so if I want one to drink during the cooler weather now is the time to be be brewing it. Last year I brewed a “two can” stout using a can of Cooper’s Dark Ale and Cooper’s Stout and some dark malt extract and it turned out very nice but the ABV was above 8%, too much for a two pot screamer like myself. I’ll brew one of these again this year but I wanted something a bit easier to drink as well, something along the lines of a Guinness Irish Stout. The recipe on this page looked interesting so I decided to give it a go. I had to scale it down to 3 gallons (12L),to account for my BIAB efficiency (65%) and for the 5.7%AA East Kent Goldings hops I had on hand. I also wanted to add some flaked oats to the recipe for a bit of a silkier mouth feel. My trusty BIAB spreadsheet was given a workout and I arrived at the following:

Ale Maris Otter 2.4kg
Roasted Barley 0.24kg
Flaked Barley 0.16kg
CaraPils 0.16kg
Acidulated Malt 0.16kg
Flaked Oats 0.16kg

EKG 23g (5.7%AA) @ 90 minutes
EKG 8g (5.7% AA) @ 45 minutes
1/2 Whirlfloc @ 5 minutes

Nottingham Ale Yeast

Brew Type : 12L All Grain (BIAB)

OG: 1.049
FG: 1.013
ABV: 4.7%
IBU: 37.7
EBC: 76.5

I am doing no-chill again here and seeing that the hops additions are very early I am not making any hop adjustments to allow for the no chill. Given the cascading series of errors I made in the last brew I took some more care with this brew with regards to the mash volume and sparge volume. Working from my previous brews I allowed for a mash absorption of 0.7L/kg of grain. Given I wanted 12L of beer I allowed for 0.25L of fermenter loss and 0.5L of kettle loss meaning I wanted a post boil volume of 12.75L. My typical boil losses are 3L/hr so I wanted a post mash volume of 17.75L which meant a pre mash volume of 20L, split into a 15L mash and 5L sparge.

Mashing In

Mashing In

The Mash

The target mash temp was 68C and I heated 15L of strike water to 71C in my bag lined pot. Once I’d reached the temperature I poured in my crushed grains and mixed it thoroughly for a few minutes. The lid went on the pot and I wrapped it all in a thick doona. At this point the mash temperature was 68.9C. Last brew I had an awful mash efficiency which I suspected was due to not mixing the mash enough. I resolved to mix this mash every 20 minutes which I went ahead and did at 20 minutes and 40 minutes into the saccharification process. At the 40 minute point I returned the pot to my gas burner for a few minutes to bring the temperature back up to 68C. At the same time I heated 5L of sparge water to 70C.

When 60 minutes was up I collected up the edges of my brew bag and holding it with rubber gloves spun it tight to extract as much of the sweet wort as possible. Once that was done I topped my pot with a holed pizza tray that happens to fit perfectly into the opening and pressed down on the bag to extract more wort. I then put the bag straight into the 5L of sparge water and pressed down on it again to rinse off the remaining sugars before squeezing the bag again on my pizza tray topped pot and tipping in the sparge water.

Expended Grain Bag

Expended Grain Bag

Hop Additions

Hop Additions

Boiling Wort

Boiling Wort

The Boil

At this point I had 19L of wort in my pot, 1.25L more than I had expected. I took at gravity reading (1.031 at 53C) and brought the wort to the boil (which took about 45 minutes) before making my first 23g East Kent Goldings hop addition. The second 8g addition was made at 45 minutes and finally half a Whirlfloc tablet went in with 5 minutes remaining. At the end of the boil there was 14L of wort in the pot. The pot with lid in place was then put into my temperature controlled refrigerator to cool to pitching temperature overnight.

Taking a Gravity Reading

Taking a Gravity Reading

Fermentation

At 10AM the next day (6 March 2016) the wort was sitting at a steady 18.5C. I sterilised my fermenter and poured the wort into the vessel, took a gravity reading (1.051) and aerated thoroughly with a large sterilised plastic spoon. I pitched the Nottingham yeast, put the airlock in place on the fermenter and put it into my fermentation chamber with a set temperature of 18.5C. Funnily enough just two hours later I saw signs of fermentation in the airlock and the next morning it was bubbling vigorously.

Yeast Pitched

Yeast Pitched

Taking another SG Reading

Taking another SG Reading

Mash Efficiency

It appears that the steps I took to improve mash efficiency worked as I managed 75% on this brew. I did my usual calculations in Excel to arrive at the mash efficiency:

Kg Potential Pounds Potential Points
Ale Maris Otter 2.40 1.038 5.28 41.8
Barley Roasted 0.24 1.025 0.528 2.7
Barley Flaked 0.16 1.032 0.352 2.3
CaraPils 0.16 1.033 0.352 2.4
Acidulated Malt 0.16 1.038 0.352 2.8
Oats Flaked 0.16 1.037 0.352 2.7
Potential 54.82
Actual 41.00
Efficiency 74.8%

Brew Day 13 Reddit Collaboration APA Batch 2

Last brew day I made a short boil no chill version of a collaboration brew that was suggested on the /r/homebrewing on Reddit. You can read the full report of that day here. It turned out beautifully and for the first time I felt like my usual 12.5L brew size was too small as I drank through most of the delicious hoppy APA far too quickly. Planning was put inplace to brew another batch but and my lovely partner splashed out on a fantastic 33L stainless steel boil kettle for me so I seized the opportunity to make a bigger batch of 20 liters. I cracked out my handy brew in a bag spreadsheet, scaled the recipe up and arrived at the following:

Ale Barret Burston 2 Row 3.26kg
Ale Maris Otter 0.93kg
CaraPils 0.22g
Caramalt Malt 0.22kg
Oats, Flaked 0.22kg

Magnum 14g (12.7%AA) @ 30 minutes
Amarillo 8g (9.5% AA) @ 5 minutes
Citra 8g (13.2% AA) @ 5 minutes
Amarillo 15g @ Flameout
Citra 15g @ Flameout
Amarillo 40g Dry Hop 3 days
Citra 35g Dry Hop3 days

British S04 Ale Yeast

Brew Type : 20L All Grain (BIAB)

OG: 1.054
FG: 1.015
ABV: 5.6%
IBU: 23.2
EBC: 11.4

As this is a no-chill brew again I’m treating the flameout additions as 10 minute additions meaning that the 23.2IBU is low and it’s likely that this beer will be 40-45IBUs. Other changes include using harvested S04 yeast instead if US05, and toning down the dry hopping somewhat because, well, hops are expensive.

Mashing In

Mashing In

Post Mash Gravity

Post Mash Gravity

S04 British Ale Yeast Starter

S04 British Ale Yeast Starter

As usual I shot for a 60 minute mash, I chose 20L of strike water heated to 72C to which I added my grain. Rather than use a brew bag I used 4 square meters of white Swiss Voile fabric. I hit the strike temperature exactly in my shiny new 33L pot, added the grains, stirred for a few minutes before putting the lid on and wrapping up the pot in an insulating doona. There it sat for an hour varying very little from the initial mash temperature of 69.6C, dropping just 1.6C to 68.0C. It’s at this point where I started to mess things up. The first mistake (I think) had already happened as I hadn’t mixed the mash at all during the hour of rest and my mash efficiency was crap. Second, I chose to sparge with too much water (10L) for two reasons. Firstly I’d done my calculations assuming there was a 60 minute boil, but of course there was only a 30 minute boil, and I’d assumed a too high evaporation rate during the boil. As a result I ended up with 26.5L of pre-boil wort with an SG of 1.025 at 64C (corrected to 1.040).

The boil itself went fine, I made my hop additions and at flameout allowed the wort to stand for 10 minutes. I did make use of some new stainless steel hop balls to try to improve wort clarity. At the end of this process I still had 24L of wort left in the pot. The pot, wort and all went into my refrigerator and was brought down to my final pitching temperature of 26C nearly 24 hours later. At that point I took a gravity reading (1.036???) and pitched the S04 yeast that I’d put into a 600mL starter the day before. It all went back into my temperature controlled fridge where fermentation started within 12 hours.

Hop Balls!

Hop Balls!

Pitching the Yeast

Pitching the Yeast

Initial Gravity

Initial Gravity

What Went Wrong

So much went wrong with this it’s embarrassing. Firstly my mash efficiency was up the shit, secondly my pre-boil volume was way two high, third I think I got my 10 minute hop additions wrong (they should have been 5 minute additions), and finally there’s something screwy with my SG readings. A corrected pre-boil SG of 1.040 cannot become a gravity of 1.036 post boil. Not actually possible, SG has to go up if you’ve removed water. My post boil volume of 24L is too high, which means the ABV is going to be down, given my usual mash efficiency the final gravity should be about 1.043. The final thing that went wrong was the sheer size of the batch. Everything was too heavy. I did manage but I was nervous handling 30 kilograms of stainless steel and near boiling wort as I lifted it from the ground to my stovetop. And speaking of the stovetop, it struggled to maintain a good rolling boil.

So what will I do different next time? Not sure yet, let’s see how this mid-strength hoppy ale turns out. If it’s crap I will re-evaluate my whole process. If it’s good I might see if I can repeat my mistakes on a smaller 15L batch.

Bulk Priming and Bottling

One of my daughters helped me bottle this brew. We ended up almost exactly 30 full 740mL PET bottles (22L of beer) and batch primed with 184g of white sugar dissolved in about 200mL of boiling water. Final gravity (prior to bulk priming) was 1.008 (see below), quite a bit drier than I would have expected.

Final Gravity Prior to Bottling

Final Gravity Prior to Bottling

Dual SHA256 / SHA1 Windows App Code Signing

I wrote about digitally signing programs for Windows a few years ago. Microsoft announced last year that windows would no longer trust files signed with the SHA-1 algorithm after 1 January 2017. This causes some problems with older operating systems (like XP SP2 and Vista) as they do not support the SHA256 algorithm for certificates used to sign programs/apps. To maintain compatibility with ealier versions Microsoft suggests dual signing with both the SHA1 and SHA256 certificates. It turns out my certificate (from Comodo and issued in mid-2015) supports both the SHA1 and SHA256 algorithm so it’s not a big hassle for me. However, some older certificates (that have not expired) may need to be re-issued by the issuing authority, some certificate issuers such as K-Software are issuing replacements for free.

Here’s what I had to do to sign my EXE files with both SHA1 and SHA256 versions of my certificate.

1. Download an up-to-date version of the signtool.exe file from Microsoft. Such as this one from the Windows 8.1 SDK.
2. My certificate was installed automatically by Comodo when I purchased it so it needed to be exported to a PFX file. You’ll need to know what the password for your certificate was when you purchased it. There’s a decent tutorial covering this process here.
3. Work out the new commands to dual sign your EXE files. In my case they look something like this.

//Code sign with SHA1
signtool.exe sign /f "c:\path\to\pfx-file\my-pfx-file.pfx" /p mypfxpassword /t http://timestamp.comodoca.com /v c:\Path\To\File\somefile.exe

//Code sign with SHA256
signtool.exe sign /f "c:\path\to\pfx-file\my-pfx-file.pfx" /p mypfxpassword /fd sha256 /tr http://timestamp.comodoca.com/?td=sha256 /td sha256 /as /v c:\Path\To\File\somefile.exe

It’s important to use the /fd and /td switches on the second call to ensure both the file and date/time stamp are SHA256 signed. I actually wrote a little batch file to automate the dual signing of files. I call the file from my various build scripts to sign both my program executables and installers. Here’s that file:

@echo off
echo ************************************************ 
echo Running %0
IF %1=="" GOTO InvalidParameter
IF not exist %1 goto InvalidFile  
echo Signing %1
echo Signing with sha1

"d:\code signing 256\signtool.exe" sign /f "c:\path\to\pfx-file\my-pfx-file.pfx" /p mypfxpassword /t http://timestamp.comodoca.com /v %1

echo Signing with sha256
"d:\code signing 256\signtool.exe" sign /f "c:\path\to\pfx-file\my-pfx-file.pfx" /p mypfxpassword /fd sha256 /tr http://timestamp.comodoca.com/?td=sha256 /td sha256 /as /v %1
echo Signing completed Successfully
goto eof

:InvalidParameter
echo You must pass this script a file to sign
goto eof

:InvalidFile
echo %1 does not exist
goto eof

:eof
echo ************************************************ 

You can easily check if you’ve dual signed correctly from within Windows 10 by right clicking on your signed EXE file, selecting Properties and then clicking the Digital Signatures tab. If it’s done right it should look something like the screen below. Note that both the SHA1 and SHA256 certificates are present.

Dual Code Signed EXE File

Dual Code Signed EXE File

Copy Element to Clipboard Using Javascript

Over the years I’ve built a web based system that controls most of the sales and support aspects for my software. This includes tracking sales, editing sales, supplying customers with registration keys, prompting them to renew support, and so on. There’s also a search interface that allows me to find customer sales details, registration keys, and to check if they have current support. I use this search interface multiple times a day and when I need to find a registration key or need to remind a customer that their support has expired the system outputs the email text I need to send to the customer to the browser window. Then I select it, and paste it into my emails.

This morning I thought it would be really neat if I could cut out the select and copy steps and have JavaScript copy it into the clipboard for me. Last time I checked this (5 years ago) it wasn’t possible without Flash. Now it turns out you can use the Web API that most modern browsers support to do it.

I wrote this little JavaScript function that I can pass a HTML element ID to and it copies the contents to the clipboard.

function copyToClipboard(elem)
{
	//create a new range to hold the DIV to copy
	var range = document.createRange();
	//select the not containing the element to copy
	range.selectNode(elem);
	//clear the current selection
	window.getSelection().removeAllRanges();
	//add the selected range to the current selection
	window.getSelection().addRange(range);
	//run exeCommand to copy 
	document.execCommand('copy');
	//clear the selection
	window.getSelection().removeAllRanges();
}

The key here is the document.execCommand(‘copy’) call which sends the contents of the element to the clipboard so I can paste it into my email tool. Triggering the function is pretty simple with something like this:

document.getElementById('copy-link').addEventListener('mousedown',copyToClipboard("element-id"));

I found a couple of other solutions that copied to the clipboard by copying the element contents to temporarily created <textarea> but the issue with this was that the HTML formatting was not copied. I needed this so that my support emails maintained my standard CSS styling.

Pirate Life Brewing Pale Ale Review

pirate-life-pale-ale

Pirate Life Brewing are a craft brewer with their facilities in my home town of Adelaide, South Australia. They have a small range of beers available at a limited number of retail outlets. My partner went out of her way to find one of those outlets and bought me a can of each of their three products. The first of these that I’ve tried is their Pale Ale which uses ale malt, caramalt, pale crystal, cascade and mosaic hops. Poured into the glass the beer is a little darker than you’d expect a pale ale to be, being a dark amber, it’s not crystal clear (I am not a clear beer nazi) and it very attractive in the glass. The head was nice and white and fluffy but dissipated fairly quickly. The aroma of the beer was muted with passionfruit the strongest character and some pine in there too. The beer itself had an upfront breadiness and a good level of lingering bitterness, on the back of my palate I got some lemon in the aftertaste. The mouthfeel was nice and sharp and crisp, the sort of mouthfeel I’d like to achieve in my own brewing but haven’t managed yet. Overall, a nice beer but perhaps a little too bitter for it to be quaffable in larger quantities. Recommended.

PERL Search and Replace in Multiple Files – Easy as PIE

I help to administer a blog with about 2000 entries.  Previously the site was managed in MovableType but earlier this year we moved it over to WordPress.  At the time we migrated about 30% of the posts to WordPress (the top trafficked 30%).  It was a slow process and as time has gone by we’ve migrated more and more posts  but it’s a time consuming process.  We need to create the new WordPress post, put a 301 redirect in place and then manually delete the old MovableType post.  And by manual deletion I mean deleting the actual HTML file that MoveableType created for that post.  You see, MovableType produces static files for each and every post, archive page, and index page.  This is a blessing and a curse, it means that the load on the web server isn’t large on heavily trafficked sites, but it also means maintaining a legacy site is a PAIN IN THE A**.  It’s actually such a pain that I have given up with MT itself and now I am working with the static HTML files directly.

This week I needed an easy way of doing a search and replace in all the legacy HTML files, all 2000 or so of them.  It needed to be recursive and ideally it needed to happen without me needing to FTP all the files to a local computer and then FTP them back.  I have command line access to the server the blog is on so I checked to see if PERL offered a way to do what I wanted working on the files in situ.  As it turns out it’s pretty simple.  I wanted to find and replace all internal links that used the old domain name (did I mention this site just changed domain names) with the new domain name.  The PERL command to do this with all the files in a single folder is like this:

perl -p -i -e 's/oldstring/newstring/g;' *.html

The -p means the script we’re running will be put through the C pre-processor before PERL compilation. The -i option means that PERL will edit the files in place. The -e option allows the running of PERL commands from the command line (it doesn’t look for a script file). The actual PERL operator s is the substitution operator while the he oldstring and newstring are regular expressions so special characters need to be escaped appropriately. And finally the operator /g means the command will do a global match. So to replace my URLs I needed something like this:

perl -p -i -e 's/www\.old\-domain\.com/www\.new\-domain\.com/g' *.html

The issue with that is that I needed the script to process sub-directories recursively to search and replace in all the HTML files. That could be done in a few different ways, the immediately obvious were chaining with FIND or GREP. I chose FIND and ended up with a command that looks like this:

perl -p -i -e 's/www\.old\-domain\.com/www\.new\-domain\.com/g' ' `find ./ -name "*.html"`

Ran that from the ubuntu commmand line and thousand or more files were processed in under a second. Very cool.

Brew Day 12 – Reddit /r/HomeBrew Collaboration APA

I often frequent the /r/HomeBrewing sub-reddit and over the last few weeks a member has been developing an APA recipe based on feedback from the sub-reddit subscribers. You can view the recipe here, it’s a pale ale using 2-row, Maris Otter, some oats, and hopped with Warrior, Amarillo, and Citra. As I mostly brew in isolation (apart from my lovely partner who is amusingly tolerant of my brewing fascination) I thought it would be fun to take part in the group-think and have a go at the recipe myself. However, I wanted to try a no-chill (which seemed to work really well last time) and a shorter boil. Aim was to be done with brew day in about 2 hours.

I had to scale down the recipe for my usual 12.5L size (the recipe calls for 5.5 gallons) and adjust the hop schedule to account for the no-chill approach. I’ve done quite a bit of reading in the last few weeks and the rule of thumb suggested is that flame-out additions for no chill should be counted as 10-15 minute additions. The recipe was constructed in the very handy BIAB Beer Designer spreadsheet.

Ale Barret Burston 2 Row 2.04kg
Ale Maris Otter 0.58kg
CaraPils 0.14kg
Caramalt Malt (50EBC) 0.14kg
Oats Flaked 0.14kg

Magnum 9g (12.7%AA) @ 30 minutes
Amarillo 5g (9.5% AA) @ 5 minutes
Citra 5g (13.2% AA) @ 5 minutes
Amarillo 13g @ Flameout
Citra 13g @ Flameout
Amarillo 35g Dry Hop 3 days
Citra 44g Dry Hop3 days

SAFALE US05 Yeast

Ingredients

Ingredients

Brew Type : 12.5L All Grain (BIAB)

OG: 1.052
FG: 1.014
ABV: 5.0%
IBU: 19.9
EBC: 11.4

You’ll note that the IBU’s are just under 20, but if you dial in the 5 minute and flameout additions as 10 minute additions you arrive at 42IBU which is right on what the original recipe calls for. The logic for this may be a little flawed as I suspect the 5 minute additions should really be considered as 15 minute additions but the proof will be in the tasting.

Brew Day (21 November 2015)

The evening before I filled my brew pot with 10L of water and my sparge pot with 7L of water and left them sitting to allow for any volatiles to evaporate overnight.

Heating Strike Water

Heating Strike Water

1. Brew day started at 6:40AM when I brought 10L of water to strike temperature of 71C with grain bag lining pot.

2. Added grain bill, stir to ensure no dough balls.

Mashing In!

Mashing In!

3. Took temperature of mash (69.0C) replaced lid on pot, and wrapped pot in doona/blanket for 60 minutes to mash.

There's Wort in There

There’s Wort in There

4. Bring 7L of water to 75C in another pot.

5. At the end of 60 minutes unwrap pot, take temperature again (68.0C). I drained the bag on a wire rack suspended over the brew pot for several minutes.

Draining the Bag

Draining the Bag

6. Sparged the bag with the 75C water until there was a litre or two left and put the bag in the sparge pot and let it rinse out the last of the wort.

Bringing Wort to the Boil

Bringing Wort to the Boil

7. At this stage I had 13L of wort in the brew pot. I took a gravity reading (1.037 @ 61.5C), added a few drops of FERMCAPs to stop boil-overs and brought it all to the boil.

Hop Additions

Hop Additions

8. Hop additions were made when the boil started (Warrior), 25 minutes (5g of Citra and Amarillo) and at the end of the 30 minute boil (13g each of Citra and Amarillo). At this point I whirlpooled the wort for 10 minutes.

Whirlpooling at Flameout

Whirlpooling at Flameout

9. Once that time was up I put the pot into my pre-chilled fridge to bring the temperature down to pitching temp (19C). I expected that to take about 12 hours and aimed to pitch my yeast the next morning. At this point it was 9.20AM, 2 hours and 40 minutes since I’d started. In that time I’d brewed the beer, showered and breakfasted, and answered my morning work emails. Generally I was pretty happy with how short the whole exercise was.

Hot Wort Cooling in Fridge

Hot Wort Cooling in Fridge

10. (Morning of 22 November 2015). I drained the wort into my sterilised fermentation vessel trying to leave as much hop residue as possible in the brew pot. I had to top it off with about 2 liters of cooled boiled water to get my 12.5L volume. I took a gravity reading (1.053) and temperature reading (19C). Aerated thoroughly with a large (sterilised) plastic spoon and pitched my yeast. Filled the airlock with steriliser, put the lit on the FV and put it in my fridge with a set temperature of 19C.

Yeast is Pitched

Yeast is Pitched

Generally I was happy with the day, my mashing temperature was a little high but it doesn’t seem to have effected anything as I achieved my usual efficiency and just missed the target OG by one lousy point. The wort was a very pale green/gold, without doubt the palest wort I have made to date. Not sure if this was a product of the grain bill or the shorter boil. I certainly liked the shorter boil time, however the longest periods of inactivity (other than the mash) was spent waiting for the strike water to heat up and bringing the wort to the boil. That idle time is only going to be solved by getting a bigger gas burner which isn’t on the cards any time soon.

Mash Efficiency

I did my mash efficency calculations in Excel, and got my usual efficency of 70%.

Kg Potential Pounds Potential Points
Ale Barret Burston 2 Row 2.04 1.038 4.49 49.59
Ale Maris Otter 0.58 1.038 1.28 14.10
CaraPils 0.14 1.033 0.31 2.96
Caramalt Malt 0.14 1.034 0.31 3.04
Oats Flaked 0.14 1.037 0.31 3.31
Potential 73.00
      Actual 51.00
      Efficency 69.9%