Thursday, March 24, 2016

Go

In the very small amount of spare time that I have at the moment, I'm learning to program in Go, with a short-term goal to write some performance testing utilities for work and a long-term goal to make it my second go-to language after Perl.

The reasons I've chosen Go are pretty simple:

  1. Healthy ecosystem. There are tons of libraries, lots of articles, plenty of discussion and frequent updates to the compiler.
  2. Simple concurrency primitives. A lot of the problems I'm dealing with at the moment need to be approached with concurrency in mind. Goroutines and channels fit a lot of these problems really well.
  3. Statically linked executables. This is really nice to have. It means when I write performance testing utilities for work, they are easily deployed and run on all kinds of machines, whether they're for one product or another or whether it's a production or development environment. It means I can avoid any runtime dependency hell if there are subtle environment differences between machines and it means I don't have to change the state of the machine just to run my code.
  4. Composition over inheritance. It's a personal preference, but I hate inheritance once it grows beyond a couple of layers.

Now, just wait a few months and I'll write a blog post titled "what I hate about Go" :)

Friday, February 26, 2016

Handy Skills: More Useful Knots

Last year I briefly wrote about knot tying and that I was learning to be a little less useless when helping people move house by having a few knots up my sleeve. Back then I only learned a couple of really simple knots, like the bowline, the clove hitch and the square knot. I've picked up a few other useful knots for a couple of semi-common situations since then.

  1. Threaded Figure 8. When erecting a tent or a marquee, a threaded figure 8 is useful for attaching your guy ropes to the actual tent or marquee, if they didn't come already-attached. A bowline can be used aswell, but with all of the different variations, I think a figure 8 is more versatile, even if it's a little slower to tie than a bowline.
  2. Trucker's Hitch. Following on from the figure 8, after the guy rope has been attached to the tent, the other end of the rope needs to be attached to the peg in the ground (or a nearby tree), and the trucker's hitch is an awesome way to tension and secure the rope. I like the trucker's hitch more than the taut line hitch for this purpose because I've found that the taut line hitch doesn't work well with every kind of cordage, whereas the trucker's hitch does. It's also great for tying down cargo in the tray of a ute, or in the back of a moving truck. It looks difficult to tie, but it's worth spending time on for how versatile it is. It's one of those knots I watched my dad tie a million times as a kid but was never able to remember how he did it.
  3. Slipped Sheet Bend. Great for joining two bits of rope together. It's a lot stronger than a square knot and is quicker to tie and easier to undo than a figure 8 bend.
  4. Timber/Killick Hitch. For hauling anything and everything. I haven't actually used this in any real situation yet, but I like it.

Friday, January 29, 2016

Australia Day Weekend Camping

Last weekend, for Australia Day, Cherie and I went camping up in Thornton. We weren't completely roughing it (showers/toilets/BBQ were on-site), but it was a great few days next to the Goulburn River and just reminded me how awesome camping is.

Cherie and I have camped together a few times now, so we get our camp setup pretty quickly; we both get the tent out, I peg the thing down, we both get the poles setup and erect the tent, and I finish pegging it down and setting the guy ropes while she unpacks the gear from the car. Smooth and efficient!

All our tents were setup around the camp fire. Being able to have a camp fire was great since many other places we've camped won't let you have fires anymore, especially during summer. We cooked everything from chicken wings, sausages and steaks to bacon and eggs. A whole chicken was even roasted in a pot.

Jeremy with his awesome contraption to cook food over a fire

She just wanted to roast them, not eat them

Even though there was a pool on the grounds, swimming in the river was the real treat. Even though the weather was hot, the river was ridiculously cold, but after you got over the initial shock, diving under was invigorating (and good for you). It was a lot of fun. We even taught our friends' kids how to skip a few stones, or in some cases, how to throw the biggest and heaviest stones in the water for the biggest splash.

Skipping stones

It was a great weekend! I love camping, I love summer, I love swimming and I love spending quality time with friends.

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.