TDD vs. Design

Published by Michael de Silva on Friday, 02 May 2014


It's quite likely that you've read David's recent write up 'TDD is dead. Long live testing.' (with its follow up, Test-induced design damage and Slow database test fallacy) and the ensuing debate on Twitter.

TDD is quite certainly not dead, and while those were words David chose at the time, I can understand why it's 'irked' as many in the community as it has. There are many, who've made TDD their 'mantra' to the point a large part of their business — such as training in TDD in a professional capacity not to mention followers of Pivotal labs.

David's main point was that following TDD, as it is mean't to be followed, leads to tests driving design. Going against this, would technically not be TDD — hence ...(continued)

Just Tweeted by @bsodmike!

Code & Tech

Reclaim Disk Space with hdiutil & Sparse Bundle Disk Images for Mac OS X

First blog post for 2014 and guess what? I managed to reclaim over 50gig of disk space in under 20 seconds by shrinking a ~96 gig sparse bundle disk image down to arou ...(continued)

Getting to Grips with Chef via Knife-solo, Berkshelf, and Vagrant ~ Part One

To get started, I've put together an example chef-repo (a.k.a 'kitchen') chef-server-with-vagrant, which was set ...(continued)

The Ruby Class Diagram ~ Eigenclasses Demystified

Thanks to some inspiration from Andrea (@madebydna)'s article 'Ruby's Eigenclasses Demystified

 

Ruby

The Ruby Class Diagram ~ Eigenclasses Demystified

Thanks to some inspiration from Andrea (@madebydna)'s article 'Ruby's Eigenclasses Demystified

Simple Ruby DSL Mixin

Whilst perusing through the code for Berkshelf I came across this piece of absolute gold, since I've been looking at various approaches to implementing clean DSLs in ...(continued)

Monsieur Eigenclass to the Rescue!

Today, Monseuir Eigenclass saved the day for me. I had an interesting gist sent to me from a colleague where he was leveraging const_missing; he had a passing spec b ...(continued)


Reclaim Disk Space with hdiutil & Sparse Bundle Disk Images for Mac OS X

Published by Michael de Silva on Friday, 17 January 2014


First blog post for 2014 and guess what? I managed to reclaim over 50gig of disk space in under 20 seconds by shrinking a ~96 gig sparse bundle disk image down to around 40 gigs.

-> % hdiutil compact Cohiba_secure.sparsebundle 
Enter password to access "Cohiba_secure.sparsebundle": 
Starting to compact
Reclaiming free space
...............................................................................
Finishing compaction
Reclaimed 52.4 GB out of 251.5 GB possible.

It's that easy...

Getting to Grips with Chef via Knife-solo, Berkshelf, and Vagrant ~ Part One

Published by Michael de Silva on Thursday, 19 December 2013


To get started, I've put together an example chef-repo (a.k.a 'kitchen') chef-server-with-vagrant, which was setup with knife-solo, Berkshelf, and Vagrant.

This kitchen was created by performing knife solo init . to turn the current directory into a new chef-repo. Here are the contents of this kitchen

.
├── Berksfile
├── Berksfile.lock
├── Gemfile
├── Gemfile.lock
├── MIT-LICENSE
├── README.md
├── Vagrantfile
├── chefserver
├── cookbooks
├── data_bags
├── environments
├── nodes
│   ├── chefserver.json
│   ├── vagrant.json
│   └── web.node.json
├── roles
│   ├── base.json
│   ├── chefserver.json
│   ├── node_base.json
│   └── vagrant_chefserver.json
└── site-cookbooks
    ├── apt
    │   ├── CHANGELOG.md
    │   ├── README.md
    │   ├── attributes
    │   │   └── default.rb
    │   ├── files
    │   │   └── default
    │   │       └── apt-proxy-v2.conf
    │   ├── li ...(continued)

The Ruby Class Diagram ~ Eigenclasses Demystified

Published by Michael de Silva on Sunday, 06 October 2013


Thanks to some inspiration from Andrea (@madebydna)'s article 'Ruby's Eigenclasses Demystified' and 'A Complete Ruby Class Diagram' by @banisterfiend — here's my take on the class diagram, in which I wanted to elucidate a bit more by making Class.new the starting point.

Download high-res PNG: http://d.pr/i/4HVg+
Long live pry!

Enjoy!

Simple Ruby DSL Mixin

Published by Michael de Silva on Sunday, 06 October 2013


Whilst perusing through the code for Berkshelf I came across this piece of absolute gold, since I've been looking at various approaches to implementing clean DSLs in Ruby. I particular prefer an isolated mixin based approach, and this example does so rather gracefully via an 'annonymous class' upon which the DSL is based on.

Should you have a need to process a file via your DSL, checkout its original implementation for dsl_eval_file — let's get cracking!

I've taken the liberty of stripping this down in to a single file for prying into with... uh, pry!

To start off, CleanRoom is defined within the DSLEval namespace

    class CleanRoom
      attr_reader :instance

      def initialize(instance)
        @instance = instance
      end
    end

The actual dsl_eval meth ...(continued)

Monsieur Eigenclass to the Rescue!

Published by Michael de Silva on Wednesday, 25 September 2013


Today, Monseuir Eigenclass saved the day for me. I had an interesting gist sent to me from a colleague where he was leveraging const_missing; he had a passing spec but noticed some strange behaviour on production where his call to super in const_missing was returning nil.

Eventually this snippet was used to see what the stack trace was like between both scenarios, a case of spotting the 'ugly duckling' as it were.

The first attempt was a varient on Module.module_eval and I noticed that even the Object.module_eval version failed miserably in IRB. That's to Rails' various bindings however, this does work in a Rails environment

Object.module_eval do
  class << self
    def const_missing _const
      puts "HELL YEAH"
      raise _const
    rescue => ex
      puts ex.message
      puts ex.backtrace
      super
    end
  end
end

module AAAA
end

AAAA::TEST

The trace shed some light on this mystery and it was the in ...(continued)

Saving Music from Soundcloud via cURL

Published by Michael de Silva on Tuesday, 27 August 2013


Today I was looking into saving a clip from Soundcloud and decided to fire up my trusty Chrome inspector and had a look under resources; there wasn't anything listed so I checked to see if anything was being streamed to the client (browser), and surely enough there was!

I chose the Copy as cURL option and ran it in terminal piping the output into an appropriately named file with .mp3 extension... and voila!

Absolutely fantastic! Let me know what you think :)

Dev Productivity: Taming Large MySQL Database Imports with a Bash Script

Published by Michael de Silva on Friday, 26 July 2013


I spent the better part of today attempting to import a 10GB MySQL database that occupies around 17GB if imported correctly.

This dataset was given to me in its current condition and a regular import yields the following as mysql does some sanity checks re. data integrity etc.

[ERROR in query 2150] Cannot add foreign key constraint
[ERROR in query 2152] Table 'foo.keywords_titles' doesn't exist
[ERROR in query 2153] Table 'foo.keywords_titles' doesn't exist
[ERROR in query 2154] Table 'foo.keywords_titles' doesn't exist
[ERROR in query 2155] Table 'foo.keywords_titles' doesn't exist
[ERROR in query 2156] Table 'foo.keywords_titles' doesn't exist
[ERROR in query 2157] Table 'foo.keywords_titles' doesn't exist
[ERROR in query 2158] Table 'foo.keywords_titles' doesn't exist
[ERROR in query 2159] Table 'foo.keywords_titles' doesn't exist
[ERROR in query 2160] Table 'foo.keywords_titles' doesn't exist
[ERROR in query 2161] Table 'foo.keywords_titles' do ...(continued)

HOWTO Grok Regular Expressions

Published by Michael de Silva on Saturday, 15 June 2013


I'm not ashamed to say that I've been more a consumer of publicly-crafted regexes over the years. All the texts on the subject have been cryptic enough, that it's something I never actually bothered looking into seriously enough, and boy-oh-boy I wish I had done this sooner!

Today, I took that step and am already on my way to enlightenment thanks to

  1. #regex on irc.freenode.net and ShiningThrough for his help
  2. http://regex101.com/ which is the best online regex tool I've come across to date (thanks ShiningThrough!)
  3. http://regexone.com/ interactive lessons on groking regexes

I've compiled my solutions as I make my way through these lessons as a Gist for reference and it would be great if you could share your solutions as well. Here's are a couple examples

#### Lesson 9 - http://regex101.com/r/yZ4qG2

Objective:

    match   1.   abc
    match   2.    abc
    match   3.                   abc
 ...(continued)

Installing RMagick & ImageMagick on OS X Mountain Lion

Published by Michael de Silva on Tuesday, 28 May 2013


It's another one of those pesky gem installs.

  gem install rmagick -v '2.13.1'
  Building native extensions.  This could take a while...
  ERROR:  Error installing rmagick:
    ERROR: Failed to build gem native extension.

          /mike/.rbenv/versions/1.9.3-p392/bin/ruby extconf.rb
  checking for Ruby version >= 1.8.5... yes
  extconf.rb:128: Use RbConfig instead of obsolete and deprecated Config.
  checking for gcc... yes
  checking for Magick-config... yes
  checking for ImageMagick version >= 6.4.9... yes
  checking for HDRI disabled version of ImageMagick... yes
  checking for stdint.h... yes
  checking for sys/types.h... yes
  checking for wand/MagickWand.h... yes
  checking for InitializeMagick() in -lMagickCore... no
  checking for InitializeMagick() in -lMagick... no
  checking for InitializeMagick() in -lMagick++... no
  Can't install RMagick 2.13.1. Can't find the ImageMagick library or one of the dependent libraries. Check the ...(continued)

Electric RC Theory 101: Calculating Gear Ratios, Rollout, and Top Speed

Published by Michael de Silva on Thursday, 09 May 2013


For this example I will be taking my Hot Bodies D8T Monster Truggy as an example to base the calculations on. Here are some details

  • Motor: Castle Creations 2,200kV model 1515 1Y
  • Pro-Line 3.8" Badlands with an Outer Diameter (OD) of 148.33mm tyres.

The gear ratio at the centre differential

50T Spur/13T Pinion = 3.85:1 gear ratio

For the front and rear diffs, the axle ratio is

Beveled spur 43T / Spiral pinion 10T = 4.3:1

We can therefore calculate the Final Drive Ratio (FDR)

FDR = (3.85)(4.3) = 16.6:1

Let's now take a look at rollout which is defined as

Rollout is the ratio of how many revolutions of the motor causes the tires to move one inch.

and 1" = 25.4mm

466mm/16.6 = 28mm per motor rev.
28mm/25.4mm = 1.1:1 rollout

I typically run this @ 4S which means 2200kV x 14.8vdc x 0.9 = 29,304 RPM; note that I've compensated for a 10% drop in cell voltage due motor loading, ...(continued)