Graceful locale-based content fallback in RefineryCMS

Published by Michael de Silva on Monday, 13 October 2014


This hack took me through the refinerycms-i18n gem, and I discovered that it does not aid in achieving graceful content fallback, amongst other issues.

It should be noted this bit of work focused on Refinery v2.0.9 and may not be entirely applicable with the current release.

My solution involved adding the following decorator,

puts "Overriding Refinery::Page - #{__FILE__[/(vendor[\/\w\.]+)/]}"

Refinery::Page.class_eval do

  # The `Refinery::Page.find_by_path_or_id` call in
  # `Refinery::PagesController#find_page` calls `Refinery::Page.find_by_path` if
  # `params[:path].friendly_id?` is true.
  #
  #   # With slugs scoped to the parent page we need to find a page by its full path.
  #   # For example with about/example we would need to find 'about' and then its child
  #   # called 'example' otherwise it may clash with another page called /example.
  #   def self.find_by_path(path)
  #     split_path = path.to_s.split('/').reject(&:blan ...(continued)


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)


Inside the Shellshock Vulnerability: The 25-year old Bash bug

Published by Michael de Silva on Saturday, 04 October 2014


You'll find posts such as "Everything You Need To Know About The Shellshock Bug" covering the basics of the bug and how to locally test it out on your, Mac or linux desktop. TL;DR — give this a spin

-> % env X="() { :;} ; echo vulnerable" /bin/sh -c "echo stuff"
vulnerable
stuff

Notice how my Mac is infact vulnerable to this. But how do attackers leverage this against web servers running say, Apache?

Cloudflare have a fantastic write up Inside Shellshock: How hackers are using it to exploit systems providing simple examples that anyone can try via curl.

For example, take this

curl -H "User-Agent: () { :; }; /bin/eject" http://example.com/

Apache internally creates a variable HTTP_USER_AGENT=() { :; }; /bin/eject but this would only work if this variable is passed to bash. This article runs into various int ...(continued)

Better Productivity with Tmux, iTerm2 and Tmuxinator

Published by Michael de Silva on Saturday, 13 September 2014


http://www.railsonmaui.com/blog/2014/03/11/rocking-with-tmux-tmuxinator-and-iterm2-for-rails-development/
https://gist.github.com/MohamedAlaa/2961058
https://gist.github.com/andreyvit/2921703

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!!"

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.

Long live pry!

Enjoy!