On Holiday...!

Published by Michael de Silva on Thursday, 21 August 2014


I don't always go on holiday, but when I do

class Resource < Struct.new(:employee)
  define_method(:enable_vacation) { "Whoo! Employee '#{employee.handle}' is on holiday!!"}
end

Resource.new(
  Object.new.instance_eval { self.class.send(:define_method, :handle, ->{'@bsodmike'}) }
).enable_vacation

# => "Whoo! Employee '@bsodmike' is on holiday!!"


Code & Tech

'DevOps': Killing the Developer?


Screen%20shot%202014-08-07%20at%2000.39.03

Preamble

I started this week sorting out some widgets for a couple code bases that I am looking after at work. One's a legacy CMS app (Ruby 1.8.7/Rails 2.x) tha ...(continued)

HOWTO: Image upload with Froala editor in Rails 4

All the pertinent info on how Froala makes the AJAX image upload are detailed on the Froala site.

The first challen ...(continued)

TDD vs. Design

It's quite likely that you've read David's recent write up 'TDD is dead. Long live testing.'

Ruby

TDD vs. Design

It's quite likely that you've read David's recent write up 'TDD is dead. Long live testing.'

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)

DevOps

'DevOps': Killing the Developer?


Screen%20shot%202014-08-07%20at%2000.39.03

Preamble

I started this week sorting out some widgets for a couple code bases that I am looking after at work. One's a legacy CMS app (Ruby 1.8.7/Rails 2.x) tha ...(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)


Blog: Upgrading to Ruby 2

Published by Michael de Silva on Saturday, 09 August 2014


Today I decided to upgrade this blog to Ruby 2+ and along the way noticed my VPS was running 1.9.2 and one of the dependencies needed at least 1.9.3.

So I set about removing RMV via rvm implode; then performing a system-wide re-install

curl -sSL https://get.rvm.io | sudo bash -s stable

This was followed by installing the new version of ruby and installing Passenger

gem install passenger
passenger-install-apache2-module

From this point, it was simply a matter of following the instructions for updating Apache's passenger.load and passenger.conf files with the path to the new ruby (installed in /usr/local/bin/rvm), and restarting the Apache service.

'DevOps': Killing the Developer?

Published by Michael de Silva on Wednesday, 06 August 2014


Screen%20shot%202014-08-07%20at%2000.39.03

Preamble

I started this week sorting out some widgets for a couple code bases that I am looking after at work. One's a legacy CMS app (Ruby 1.8.7/Rails 2.x) that's extremely mature and the other is a 'Refinery based CMS' that I put together myself.

"Wait, what?", I hear you ask. Refinery is a CMS. Well, mine's an effort to bake in features that most of our clients expect, and these 'engines' (extensions in Refinery parlance) are aspects I've added. Of course, I digress.

Yes, the start to my week was a whole lot of yak-shaving tedious work. I wasn't creating anything new. There was very little 'architectural' design on my part. The bulk of this widget related work ultimately boiled down to faffling with markup/CSS.

Looking to maintain my sanity, I found myself taking a look at a tool a colleague had pinged me about — Terraform.

At work, provisioning and deployment are, for the most part, han ...(continued)

HOWTO: Image upload with Froala editor in Rails 4

Published by Michael de Silva on Wednesday, 06 August 2014


All the pertinent info on how Froala makes the AJAX image upload are detailed on the Froala site.

The first challenge is to get around Rails' CSRF protection, and you can do this by passing the authenticity_token via the Rails helper form_authenticity_token.

        $el.editable({
          inlineMode: false,
          buttons: ["bold", "italic", "underline", "createLink", "insertImage", "undo", "redo", "html"],
          plainPaste: true,
          imageUploadURL: '<%= refinery.admin_upload_image_path %>',
          imageUploadParams: {
            authenticity_token: '<%= form_authenticity_token %>',
            return_to: window.location.href,
            site: '<%= current_site.id %>'
          },
          imageErrorCallback: function (error) {
            console.log('ERROR: %O', error);

            var scroll_pos=(0);
            var message = error.message + ' (Code: ' + error.code  ...(continued)

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)

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 :)