Simon Rentzke

Blue Blistering Barnacles

Ruby "&& vs and" , "or vs ||"

tl;dr && and || have higher precendence

Difference between 'and' and '&&'

cat = 'meow'
dog = false


answer = cat && dog
=> 'bark'

answer
=>  false

answer = cat and dog
=> false

answer
=> 'meow'

Similarly with 'or' and '||'

cat = false
dog = 'bark'

answer = cat || dog
 => 'bark'

answer
=>  'bark'

answer = cat or dog
=> 'bark'

answer
=> false

I generally follow this style guide

Beats to think to

Like to concentrate whilst listening to hypnotic deep house tracks?

I've found the playlist for you.

I use it to focus whilst programming, check it out

Timezone value from offset #rails

Some apis just return a timezone offset from UTC. For example Facebook

Need to convert it to a timezone name?

Rails Active Support to the rescue, you just need to do something like this:

utc_offset_in_hours = 10
time_zone = ActiveSupport::TimeZone[utc_offset_in_hours].name
=> "Brisbane"

Most recent git branches

Sometimes I work on a few branches at the same time.

Emergency bug fix branch here, new feature branch there, performance update branch here, update gem branch there, etc...

Within a big project we sometimes have almost 40 branches at any one time.

So, being human I forget the name of the branch that I was working on last week, and also would like to clean up old branches that I no longer need.

So the solution git for-each-ref

Include a sort and formatting that includes last commit date, and author name. This is the command:

git for-each-ref --count=30 --sort=-committerdate refs/heads/ --format='%(refname:short) %(committerdate) %(authorname)'

Home Entertainment

Recently I have been investigating what the cheapest/easiest setup could be for a home entertainment system would be.

I have an old Macbook laptop that doesn't have a working touchpad and keyboard - but everything else works, so am using that as a media server.

So, my favourite combination of Software/Hardware is:

  • Plex Server, easy to setup, works on all operating systems. You can add your own specific custom plugins, for example ABC iview in Australia, just look on GitHub.

alt text

  • Chromecast - best $30 spent ever. Really simple device that works insanely well. Even without a media server, you can get some fantastic apps on your mobile - and cast from there.

alt text

  • Plex mobile app ~$6, enables you to browse your Plex channels, and cast to your TV. Works on iPad, iPhone and Android.

alt text

Now all I need is a decent live sports channel, and I'll be set.

Best Coffee Shops to work from in San Francisco

You'll see the Nodes, Rubies, the GitHubs, and get power points (mostly). Plus great Coffee.

Not too much VC raising - app idea BS either.

Ritual Coffee

1989 - 1996 : The Golden Years

James Blake - Retrograde

First Lesson: Drawing a diamond with Ruby

I was reminiscing recently about what my programming exercises were at high school. I started on Turbo Pascal.

This is was one of the first, simply to draw a diamond shape, that looked like this:

          *
         ***
        *****
       *******
      *********
     ***********
    *************
   ***************
  *****************
 *******************
*********************
 *******************
  *****************
   ***************
    *************
     ***********
      *********
       *******
        *****
         ***
          *

I remember it taking forever, but loving it. So decided to write it out in ruby.

s = 10
(-s..s+1).each do |y|
  (-s..s+1).each do |x|
   print x.abs + y.abs > s ? ' ' : '*'
  end
  puts
end

Alternative solution: s = 10 s.times {|u| puts ' ' * (s - u.to_i) + '*' * (u + u.to_i) } s.downto(0).each {|u| puts ' ' * (s - u.to_i) + '*' * (u + u.to_i) };

Slime Mould Maze

Recently I attended a workshop at the Edge on 3D printing and slime mould.

The event's title was so whack, that I signed up - not knowing what to expect.. This is what we did:

First, an intro to 3D printing. We create a maze in TinkerCad

TinkerCad, was until recently going to shut down, but luckily AutoDesk bought them out.

It's a fantastic way to ease into CAD, and produce 3D printable things. Within 5 minutes I grasped how to use it. Super simple.

tinkercad

Then we made some Agar, chucked the 3D maze in to a petrie dish, and dropped a piece of ravenous slime mould into the middle of it, with some rolled oats.

slime mould

Then I hid my slime mould in a dark box, and 2 days later - my simple maze looked like this - solved!

slime mould solved maze

This is a fascinating timelapse video, of slime mould's ability to actually solve the maze intelligently.