Saturday, January 16, 2016

Handy Skills: Basic Butchery

Although it makes a lot of sense now that I think about it, I never thought I'd find butchery all that interesting, but, a little over a year ago, after watching a video about a chef in Scotland who hunts and gathers his own food for his restaurant, I watched a ton of videos on butchery and it turns out a little bit of butchery is a handy skill to have and it's awesome.

Why is a little basic butchery a handy skill to have?

  1. Cutting up a couple of whole chickens is cheaper than buying the breasts and thighs separately, and the entire carcass can be used for a variety of things
  2. Ever go fishing and not know how to scale, gut and prepare the fish you just caught?
  3. It's good to know where the various cuts of meat come from
  4. It's a little bit therapeutic
  5. You develop an appreciation for the entire animal

So here's some videos:

Wednesday, January 6, 2016

2016

Happy New Year!

Last year was a fantastic year in all facets of my life. I got engaged to my lovely girlfriend, Cherie, I competed in a bunch of strongman competitions, I learned a ton of stuff about low-level systems programming and also about massively scaling systems, I learned (and blogged) about a few handy skills to make me a generally more useful person, and I had a heap of good times with my friends and family.

This year I've got a bunch of exciting stuff to look forward to; turning 30, engagement party, competing at the Australian Arnold (pending qualifiers this month), more food, more handy skills, more blogging, more fun!

Time to get on with it!

Friday, December 11, 2015

5/3/1 Retrospective

Back in 2011, I ran 5/3/1 for a few cycles, shortly after finishing up a linear periodisation program back when I first started strength training. I made great progress for a year on the original 5/3/1 template, and then, for some reason (fun, mostly), I swapped to other programs (mostly my own, because I knew everything apparently) where I made mediocre progress for a couple of years. The only decent progress I made in this period was actually a program somebody else gave me.

And then, at the end of 2014, I realised that I didn't, in fact, know everything, and wound up back on 5/3/1, using Chase Karnes' 5/3/1 for Strongman template, and lo and behold, after a couple of cycles I got stronger again, built a little more muscle and felt much better for it. So for the past year, I've been training on some kind of 5/3/1 template.

5/3/1 for Strongman

Chase Karnes' 5/3/1 template was fantastic for a few reasons:

  1. It's an upper/lower split, which was how I was training at the time.
  2. Doing two main upper-body lifts on the upper-body day and two main lower-body lifts on the lower-body day gave me a really nice volume boost, which translated into some quick, early strength and mass gains since most weeks I can only train twice a week and only doing one main upper/lower lift per week wasn't enough volume for that.
  3. Events are trained on their own day, rather than amongst regular training days. I know the norm is to have a separate events training day, but I had been training with an event tacked onto the end of my regular training days for a while up to this point, which had the downside of training days taking at least 2 hours.

Eight weeks of this template saw me through to my first competition of the year, which went pretty well.

Joker Sets, First-Set-Last Volume and Deadlifting Again

After getting my hands on Beyond 5/3/1, I experimented with joker sets and first-set-last volume work.

One of the reasons I'd previously moved on from the original 5/3/1 template was because I hated never really getting to test out where I was at with heavier weights, and I absolutely despised the Boring But Big volume work. So these two additions seemed perfect.

Having previously had success with paused overhead presses and with the general recommendation in my strength trainee circles that paused variations were awesome, I added in paused first-set-last volume work first; 5 sets of 5 after the regular 5/3/1 sets.

After a cycle of paused volume work, I added in the joker sets, after the regular 5/3/1 sets but before the volume work. I cut the volume work down to 3 sets and really pushed the joker sets. A cycle of this saw me through to my second competition of the year.

At this point, my pressing strength had never felt stronger; it was around this time of the year that I strict pressed 100kg for a solid double for an all-time PR, and was regularly strict pressing 100kg for a single most weeks.

During this training block, I started training my deadlift again, since I'd had some lower-back issues from a leftover injury that put my deadlift out of action for a while, but I didn't want to program the deadlift with 5/3/1 and really hammer it just yet, so I kept it to sets of no more than 3 reps at no heavier than 80% and followed it up with a lot of prehab work (hyperextensions mostly). Partial pulls from the knees felt fine though, for those days when I had to scratch a really heavy itch.

More Volume Variations

At this point I was totally sold on joker sets and first-set-last volume; it kept training interesting and I walked out of the gym feeling like I'd done some good work.

For this training block I alternated the movements that I used for the volume work each 5/3/1 cycle, e.g. after my strict press 5/3/1 and joker sets, I did my volume work with either paused strict presses, or I incline benched, since incline benching had translated pretty well to my overhead strength before.

Bodybuilding work also got a massive push after the volume work. There's never enough muscle and I'm way behind the strongmen that I compete against on this front.

My lower-back felt good at this point and my deadlift was feeling solid, so I ran a Mag/Ort peaking cycle. I stopped squatting so that my legs were always ready for the Mag/Ort onslaught. In hindsight, I wish I'd kept squatting, but the 8-week Mag/Ort cycle went well and I finished up with an all-time 2RM of 235kg.

The end of that 8-week block saw me through to my third and final strongman competition for the year.

Full Body, Full 5/3/1

After the last competition, I wasn't too happy with my performance and I'd stopped feeling athletic. I was stronger though, so at least I had that going for me. But I looked fat and I felt slow. My food intake had been pretty terrible (high calorie, low quality). So the first step was to clean up my diet and then sort out my training.

When this article (sort by "oldest first") popped up on T-Nation a few years ago, a full-body 5/3/1 template where I squatted every gym day was something I wanted to try, because squatting is awesome, but for one reason or another, I never did it. Wendler modified the full-body template and added a couple of variations to the Beyond 5/3/1 book and that's where my current training template has come from and I'm just finishing up my second cycle now.

I'm squatting again, I'm benching again, my deadlift is programmed with 5/3/1 again and my strict overhead press just keeps on truckin'. I'm enjoying squatting every time I walk into the gym.

I'm still using joker sets, and I'm still doing first-set-last volume, although a little different to earlier in the year:

  • The squat and deadlift get one first-set-last rep-out
  • The bench press and overhead press get a rest-pause first-set-last set

Programming the drop sets with these parameters has the added benefit of some conditioning upkeep and a huge pump.

Going into the new year, as I prep to qualify for, and compete in, the Australian Arnold Amateur Strongman competition, I'll tweak this template a little bit, but maintain the full-body principles.

I'm happy to be back on 5/3/1. Training hasn't felt this good in a while.

Friday, December 4, 2015

A Night for Mates

This past Sunday night, a few of my mates organised to catch up for the first time in what felt like months. I mean, we've all seen each other for various reasons recently (playing basketball on Tuesday nights, birthday's, engagement parties, weddings, etc...), but we rarely see each other just for the hell of it. There's usually some pre-planned event going on and as such, our attention is spread a little thin on those occasions.

It wasn't anything big; just a couple of beers to try out a new pub in the area and some souvlaki's for dinner. It was just a lot of fun to sit around for a few hours and chat about what's going on with each other, and even what's going on in the world around us (terrorism, season 6 of Game of Thrones and $5 Raspberry Pi's).

Having just read the latest Art of Manliness post, How and Why to Throw a Gentleman’s Dinner, it got me thinking about why I enjoyed that night so damn much, and I think the article hit the nail on the head: these nights are a kind of therapy.

From the article:

The truth of the matter is that you have to constantly make friendship a priority. Surrounding yourself alongside men who challenge, support, mentor, and call you out on occasion is all part of our never-ending journey of manhood. If you don’t seek such counsel, don’t expect to grow.

And now a few of us have already planned to get together again after the Christmas period.

Friday, November 20, 2015

Avoiding Data Retention in Australia

On Tuesday, October 13, 2015, Australia officially started retaining metadata. The legislation mandates that the metadata be kept for at least two years and be made available to a handful of agencies (of which the scope has changed multiple times).

Because I'm a pro-privacy kinda guy, below are a few links that hopefully makes privacy a bit more accessible, especially for the less tech-savvy people.

Take privacy seriously. Once it's gone, it'll be even harder to get it back.

Friday, October 30, 2015

Perl Hack: Modifying a List

One of my favorite Perl hacks, shown to me by a work colleague a few years ago, is for modifying a list. The hack is actually fairly pretty:

s/^ +//g, s/ +$//g for @list;

For very simple substitutions, I think this is more expressive and easier to understand than the usual foreach loop, or a map.

Friday, October 16, 2015

A Little Assembly for the Infosec Guy

If you who grew up in the 90s with some kind of interest in computer security, there's a decent change you probably only ever attempted to learn how to program in assembly for one reason: writing shellcode.

I didn't grow up in the golden era when most programmers programmed in assembly and I only did one computer systems subject at university which had us learning assembly for the Motorola 68000 microprocessor. And these days, due to the ridiculous amounts of memory machines have, in only a few extreme circumstances, the lowest-level programming language I'll ever have to program with will be C, and it'll only be as an extension to my main programming language (Perl). Unless I end up working with embedded systems, or if I get into something like malware analysis/reverse engineering as a career, dealing directly with assembly is something I'm probably not going to do as part of my job, so it has to be pursued on the side.

Slowly over the past year or so, I've been spending a couple of hours here and there playing with some very small programs, solving reverse engineering problems for wargames and writing my own shellcode from scratch rather than stealing them from shell-storm all the time.

It's been long and challenging, and I wanted to share a few rewarding experiences.

Writing shellcode that doesn't just spawn a shell

Since shellcode was what originally exposed me to assembly all those years ago, why not further that skill?

execve(/bin/sh) shellcode is what's used in pretty much every tutorial on buffer overflows and shellcode ever (I mean, I assume that's where the name shell code came from, right?). But there are other useful kinds of shellcode to write.

An easily modifiable and totally unoriginal shellcode that I wrote to read a file and write it to stdout has come in super handy when playing online wargames, since many of these games require reading a file - that you usually know, or can guess the name of, ahead of time - to get the password to the next level. I also had to write a less easily modified version of the same read/write shellcode without using the jmp-call-pop technique.

I like writing shellcode because I'm writing a small program from scratch that does a very specific thing and isn't overly complicated. It requires reading a little documentation to figure out what syscall(s) I need and how they are called and it's often written quick enough that the pay-off is immediate and there's a practical purpose to the program, as opposed to writing a program that uppercases whatever's in argv[0].

A lot of reverse engineering is patterns

While reversing a program for a more difficult level in Blackbox, I came across some code that was indexing into an array of chars a lot, and I picked up a reoccurring pattern:

  0x804859a:    lea    0xfffffbe9(%ebp),%eax
  0x80485a0:    mov    %eax,%ecx
  0x80485a2:    add    0xfffffbe4(%ebp),%ecx

At offset 0xfffffbe8(%ebp), I knew there was a char array stored on the stack, let's call it buf, so 0xfffffbe9(%ebp) is buf + 1. At offset 0xfffffbe4(%ebp) was an int that was being used to index into the array, so because we add that value, what we essentially end up with in ecx is the address of buf[index + 1].

  0x80485a8:    lea    0xfffffbe9(%ebp),%eax
  0x80485ae:    mov    %eax,%edx
  0x80485b0:    add    0xfffffbe4(%ebp),%edx

This is the same thing, just placed into the edx register.

  0x80485b6:    lea    0xfffffbe8(%ebp),%eax
  0x80485bc:    add    0xfffffbe4(%ebp),%eax

This is almost the same thing, except it's the address of buf[index] that's placed into the eax register and the compiler used one less instruction to do it.

  0x80485c2:    movzbl (%eax),%eax
  0x80485c5:    xor    (%edx),%al
  0x80485c7:    mov    %al,(%ecx)

So if eax is the address to buf[index], ecx is the address to buf[index + 1] and edx is also the address to buf[index + 1], the first instruction puts the value at the address of buf[index] into eax, xor's it with the value at the address of buf[index + 1] and moves that value into the value at the address of buf[index + 1]. So all of this translates to the following bit of C code:

  buf[index + 1] = buf[index] ^ buf[index + 1];

There were about 30-40 instructions that all did similar things all in a row - which is intimidating until you break it down into chunks of 2 or 3 instructions - and recognising the pattern and relating it to a higher-level concept made reversing the rest of the program much easier.

The more of these patterns you find, the more you understand how compilers break down higher-level ideas.

"Indexing into an array... how exciting..."

Finding gold along the way

The first real assembly nugget that I came across earlier this year was while playing Blackbox. While checking the disassembly of a program in gdb, I came across this sequence of instructions:

  0x08048519 :    lea    0xfffffc10(%ebp),%eax
  0x0804851f :    mov    $0xffffffff,%ecx
  0x08048524 :    mov    %eax,0xfffffc00(%ebp)
  0x0804852a :    mov    $0x0,%al
  0x0804852c :    cld
  0x0804852d :    mov    0xfffffc00(%ebp),%edi
  0x08048533 :    repnz scas %es:(%edi),%al
  0x08048535 :    mov    %ecx,%eax
  0x08048537 :    not    %eax
  0x08048539 :    dec    %eax

My reaction: what the fuck was that? What the hell is repnz? And scas? Is that two opcodes in one? What's that funky addressing syntax? And cld... an opcode with no operands? What is this?!

I won't go through and explain each instruction, since - as I discovered soon after figuring out what this little nugget was doing - there are already plenty of sites that have explained it before, but it was pretty cool to step through the code while reading reference documentation to figure out what those unfamiliar instructions were doing.

The short of it is, as explained by this StackOverflow answer, it's an implementation of strlen, and sometimes gcc will inline it as a little optimisation.

Moving forward

I'll keep reverse engineer programs and write shellcode for wargames. It's just a lot of fun once you get into the swing of it.

Lately something else that's become a lot of fun is learning how some low-level parts of systems work. An article about building a Tetris clone in x86 assembly does a great job at introducing some parts of systems that are much lower-level than I'd usually deal with (VRAM) and some more advanced topics (bootloaders).

2015-11-04 edit: I rewrote a few paragraphs, because I hated how they read.

Saturday, September 19, 2015

Handy Skills: Shining Shoes and Tying a Tie

Two simple skills for formal occasions. Or for work. Or for fun. Whatever it may be.

Shining shoes was something my dad taught me back when I was in high-school; the only formal-looking shoes I had were the shoes I wore to school, and because of the amount of dirt and scuff marks a typical high-school kid acquires in a short period of time, and the lack of responsibility I felt to keep the shoes clean, my shoes were always in pretty terrible shape, so my dad quickly showed me how to clean them up before whatever formal occasion we were getting ready for. Anyway, I hadn't done it for years after that, so I needed to remind myself how to do it.

Last year, when I was a groomsman, we ran into a little trouble getting our ties on because only Julian (the groom) and my other cousin, Adam, sorta knew how to tie a full windsor but couldn't quite remember, so we spent a good 30 minutes sorting out each others' ties. Turns out it's actually not as hard to do as everyone makes it out to be.

Friday, August 28, 2015

Shell Productivity Hack

I got really sick of iTerm2 (and other terminals) not giving me an easy key-combo to move forward or backward a word at a time; having to hold down the left- or right-arrow key, for what feels like forever, to fix a typo in the middle of a really long one-liner (or a MySQL query, as was often the case) was becoming way too annoying, especially when I do it multiple times a day. So a few months ago I added this little nugget to my ~/.inputrc:

"\e[1;9C": forward-word
"\e[1;9D": backward-word

This lets me press alt-left or alt-right to move word-by-word rather than character-by-character. And now I can't live without it.

Saturday, July 25, 2015

Handy Skills: (Very) Basic Car Maintenance

I'm that guy who didn't get his license until his mid-20s and thus, never owned a car before, so I didn't really learn any of this stuff when everyone else did.

sigh

By basic car maintenance, I mean checking for blown fuses, replacing light bulbs, replacing batteries, checking the oil, checking tire pressure, etc... Things that are easy to do yourself without the need for overly-specialist tools and without having to fork out extra money at the mechanic.

A lot of this came in handy when, in the space of a few days, both low-beam headlights blew, the front left tire went flat and the battery (on the car we were using until we replaced the headlights on our primary car) went flat.

When it rains, it pours...

Saturday, June 27, 2015

Early Mornings Again

About six years ago, when I started working full-time, I got into the habit of waking up at around 5am (along with the habit of going to sleep early), but slowly, over time, that creeped up and up until I was finally getting out of bed at 7am, which left me with just enough time to quickly put some clothes on and run out to the bus stop by 7:15am so I can go to work and still get there just barely on time at 8:30am.

I was still tired when I woke up. I was getting to sleep later. I was skipping breakfast until I got to work to buy something from a cafe. I was coming home still tired and exhausted. Add basketball and strongman training on top of that and I was a bit of a mess. And the worst part is that I was spending less time with Cherie.

Well, as of about six weeks ago, I've started waking up at 5am again, getting to work by 7:30am and leaving work just after 4pm. From there, I go past Cherie's work and we travel home together.

I go to sleep earlier, I get home earlier (which gives me more time each night to do things), I see Cherie more and, overall, I feel so so so very much better during the day than I did before.

Feels like a win to me.

"If you want to get shit done, wake up before the sun comes up." - Jim Wendler

Friday, May 22, 2015

First Steps with AnyEvent

Nearly 10 years ago, while I was at university, I was first introduced to event-driven programming with Twisted, an event-driven framework for Python. At the time, I was thoroughly confused by the whole thing and didn't really get it (Not allowed to block? But I want my user input now, dammit!). I persisted for a while, but ultimately gave up.

The second time around it made a lot more sense and, since then, I've been exposed to libev (via the EV Perl module) and POE. It's a powerful programming paradigm, and super worthy of being a part of any programmer's toolbox. And this is where AnyEvent can be of service.

AnyEvent isn't exactly an event framework itself, but it can sit on top of other event frameworks; the self-described "DBI of event loop programming". So, because we have a ton of legacy EV code at work, I can write AnyEvent code alongside it, and AnyEvent will integrate with EV's event loop and everything will just work. This a huge benefit and an obvious reason why adopting AnyEvent into an existing system can be a good idea.

Experimenting at Home

I wrote some code to hit my wireless internet router's web server a bunch of times and it wasn't long before I came across my first issue with AnyEvent::HTTP; my router (by Huawei, so take what you will from that) only accepts the content length header in exactly the form 'Content-Length'. However, AnyEvent::HTTP issues 'Content-length' (note lowercased 'L') and my router issues a 404 response for this. Diving into the AnyEvent::HTTP source, I found that there's no way to override this behaviour, as AnyEvent::HTTP lowercases all headers you pass in (plus a couple of default ones) and then ucfirst's them on output.

So what was my workaround for this? To use AnyEvent::Handle and HTTP::Request to talk HTTP. I could have used AnyEvent::Socket alongside AnyEvent::Handle, but AnyEvent::Handle can make TCP connections aswell, which is handy.

That worked! Making many many many HTTP requests? AnyEvent handles it like a champ. That's great!

But the server didn't handle the number of connections very well, so there were lots of failed and closed connections. That's bad.

My first instinct was to write code to retry a connection if it failed for any reason. This worked for a while, but eventually EV (the event backend that AnyEvent had chosen to use, since it was installed) would die with a critical error. That's also bad.

In the end, the solution was to throttle the number of connections I was making, and everything started working again. Great!

How do you throttle? Something like this:


use AnyEvent;
use AnyEvent::HTTP;

my $cv = AE::cv;
my $num_connections = 0;

my $w; $w = AE::io \*DATA, 0, sub {
    return if $num_connections >= 2;

    my $url = <DATA>;

    unless (defined $url) {
        AE::log info => "Finished reading DATA";
        undef $w;
        return;
    }

    chomp $url;
    AE::log info => "Trying $url";

    $num_connections += 1;
    $cv->begin;

    my $hw; $hw = http_head $url, sub {
        my ($data, $headers) = @_;
        AE::log info => "Result from $url: $headers->{Status}";

        $num_connections -= 1;
        $cv->end;
        undef $hw;
    };

};

$cv->recv;

__DATA__
http://google.com
http://reddit.com
http://facebook.com
http://twitter.com
http://gmail.com

Closing Thoughts

I've been wanting to use AnyEvent for something work-related recently, but I want to experiment a little more before I go down that rabbit hole, or perhaps just use it in something non-critical.

Condition variables are great!

I've heard that IO::Async (with futures) is another great way to go as far as Perl asynchronous programming frameworks go, so I might experiment with that some time soon, but for now I'll stick with AnyEvent.