Macbook Data Recovery

Last summer the hard drive on my Macbook suddenly stopped booting. After panicking, I took it into work and was able to figure out a way of recovering my data, formatting the hard drive, and restoring Mac OSX without too much trouble.

Guess what happened again last night.

Stuff needed

  • USB storage (hard-drive, thumbstick, whatever)
  • A target computer (optional)

Step one: Boot into recovery mode. This is done by holding down the “Command” and “R” keys while booting. You should get a window titled “OS X Utilities”, with four options: “Restore From Time Machine Backup”, “Reinstall OS X”, “Get Help Online”, and “Disk Utility”.

Step two: Attempt to recover the drive. Click “Macintosh HD” in left pane. The right pane should give you a button to “Verify Disk”. Follow the suggestions to repair your disk. In my experience, these steps fail, but if they work for you, then you’re probably golden.

Assuming repairing the disk fails…

Step three: Mount your drives. You should see both the Macintosh HD and your USB drive in the left pane. Mount both. If necessary, you can format your USB drive to HFS first. This will probably be required.

Step four: Open the terminal. If you go back to the main window (in other words, close the Disk Utility programme), the menubar will have a “Utilities” drop down. Choose “Terminal”.

Step five: Copy over the files. Everything you care about should be under /Volumes/Macintosh HD/User/. Your USB drive should be mounted to something like /Volumes/Untitled (or a different path, if you gave it a proper name).

Step six: Verify recovered data. On another PC, mount your USB drive and make sure the data was successfully copied over. If you’re in Windows, you can use HFSExplorer to read the HFS filesystem. Note: If you can’t find the USB drive under “File” -> “Load filesystem from device”, open the programme again in administrator mode.

Step seven: Reformat and reinstall. Go nuts. You can do this stuff through the “OS X Utilities” window. I did this, and it worked for about a year. This time I think I’ll throw Linux on instead.

Posted in General | Tagged | Comments Off on Macbook Data Recovery

Multiplication Workshop

I’ve been playing Human Resource Machine. It’s awesome! It’s a little silly that I’ve been relaxing after a long day of coding by… doing assembly programming, but it’s a fun game.

Anyway, I’ve been hung up at the optimization challenges for Year 20: Multiplication Workshop.

The challenge: For each two things in INBOX, multiply them and OUTPUT the result. Don’t worry about negative numbers for now.

Optimization challenges:

  1. Use 15 or fewer commands
  2. Complete in 109 or fewer steps.

The first challenge was easy. The second was not. But I’m finally there, so… here’s my solution!


  • Register 0 is my counter
  • Register 9 is initialized to “0”.
  • Register 1 is a copy of the number to add in the multiplication loop
  • Register 2 is the final result.

There’s a little bit of trickery. If either input number is a zero, it jumps to an early exit. If the operand being used as a counter is larger than the other operand, we swap them. And to speed up the mulitiplication loop, I negate counter to take advantage of the “jumpn” command, or “jump if the current value in the accumulator is negative”. So the “BUMPUP” instruction increments the counter and copies the new value to the accumulator, and if it’s zero we exit.



    INBOX         ; read first input
    JUMPZ    f    ; jump to label f if zero
    COPYTO   2
    INBOX         ; read second input
    JUMPZ    g    ; jump to label g if zero
    COPYTO   0
    SUB      2    ; this bit compares the two numbers...
    JUMPN    h
    ; in this branch, the current value of the counter is bigger than the
    ; other operand. Let's switch!
    COPYFROM 0    
    COPYTO   1
    COPYTO   0
    COPYTO   2
    ; because register 2 already equals register 1 (instead of "0"),
    ; reduce the counter by one.
    BUMPDN   0
    JUMPZ    e ; jump for an early exit if the counter is zero
    SUB      0 ; make the counter negative for a faster loop
    SUB      0
    COPYTO   0
    COPYFROM 1 ; the main addition loop
    ADD      2
    COPYTO   2
    BUMPUP   0
    JUMPN    d ; we keep looping until the counter is zero
    COPYFROM 2 ; output the value in register two
    JUMP     a ; go back for new input

; This label is if the first value is zero
    INBOX      ; dump
    COPYFROM 9 ; copy zero from register

; This label is used if the second value is zero
    JUMP     b

; This is a shortcut to copy the second operand to the result,
; then jump back to the bit where we negate the counter.
    COPYTO   1
    JUMP     c
Posted in Code | Comments Off on Multiplication Workshop


I wrote this the day after the “The Imitation Game” meetup (November 22nd, 2014). The fellow who usually wrote the post-mortems wasn’t there, and I had to record an excellent evening. And thus I reproduce it here for safe-keeping:

OK, I’ll try my hand at a post-mortem.

The three of us got together for the movie, which was very well crafted and Cumberbatch-y and not that good, in my opinion. The others disagree. Subsequently we had drinks at The Church, where we diligently protected the reservation for the 8:45 TK Max Christmas Party (our coworkers didn’t appear ’til much later), debated dystopias, complained about a fictional coworker, taught me how to pass as Irish, and subjected ourselves to increasing amounts of bass and songs about asses ’til we called it a night.


Posted in Ireland | Comments Off on TK MAX MEETUP GROUP 4 LYFE

I contributed to CPAN!

I spend a lot of time dealing with Perl at $WORK (as you can tell by the word “$WORK”). One of my projects is updating our legacy code, which mostly runs on Perl 5.8. When I tried running things under Perl 5.20, some unit tests broke because as of Perl 5.18, the return order of keys and values from hashes are randomized. The code was generating links, such as

Thanks to the randomization, the order of “foo” and “bar” is unknown. Which is good! But rather than rewriting all the unit tests, I decided to write a Test::Deep helper to handle unordered parameters for me. Thus Test::Deep::URI! Now that test can be written like

And just because, I added support for partial URI matching, so it’d also match uri(“/?foo=1&bar=2”) or uri(“//”).

It’s nothing major, but it feels good to give something back. Plus now I can use it at work, and that problem is solved. 😀

Posted in Code, General, Work | Comments Off on I contributed to CPAN!