Skip to content

Instantly share code, notes, and snippets.

View bsodmike's full-sized avatar

Michael de Silva bsodmike

View GitHub Profile
@bsodmike
bsodmike / command.rb
Created February 6, 2014 07:24
Rails command to create a mountable plugin (engine)
rails plugin new catscan --skip-bundle -T --dummy-path=spec/dummy --mountable
@bsodmike
bsodmike / bm.rb
Created May 1, 2014 06:02
Performance hit with string interpolation in Ruby
require 'benchmark'
puts Benchmark.measure { 500_000.times { '5' } }
puts Benchmark.measure { 500_000.times { "#{5}" } }
@bsodmike
bsodmike / engine.rb
Last active August 29, 2015 14:01
Initialise Authentication via Rails Engine
require 'initialise_authentication'
module Refinery
module AuthenticateIdentities
class Engine < Rails::Engine
extend Refinery::Engine
isolate_namespace Refinery::AuthenticateIdentities
engine_name :refinery_authenticate_identities
@bsodmike
bsodmike / promotion_decorator.rb
Created July 11, 2014 10:38
Spree - Promotion adjustment action beyond first ignored #3262
=begin
Tested in Spree 1.2.5
Ref: https://github.com/spree/spree/issues/3262
https://github.com/spree/spree/commit/bdd4db95eb2cce3e87f3991dbeca22e275862fc3
=end
::Spree::Order.class_eval do
@bsodmike
bsodmike / howto.md
Created August 6, 2014 06:41
Getting started with Docker, Packer, Terraform for Immutable Infrastructure
  • Build base OS images from source ISOs
  • Develop with Vagrant
  • Build as Docker image
  • Provision AMI instances.

AWS Example

@bsodmike
bsodmike / locales.csv
Created October 14, 2014 16:15
Locales from svenfuchs/rails-i18n
af,ar,az,bg,bn,bs,ca,cs,cy,da,de,de-AT,de-CH,el,en,en-AU,en-CA,en-GB,en-IE,en-IN,en-NZ,en-US,eo,es,es-419,es-AR,es-CL,es-CO,es-CR,es-MX,es-PE,es-VE,et,eu,fa,fi,fr,fr-CA,fr-CH,gl,he,hi,hi-IN,hr,hu,id,is,it,it-CH,ja,jp,kn,ko,lo,lt,lv,mk,mn,nb,ne,nl,nn,or,pl,pt,pt-BR,pt-PT,rm,ro,rs,ru,sk,sl,sr,sv,sw,th,tl,tr,uk,uz,vi,wo,zh-CN,zh-HK,zh-TW
@bsodmike
bsodmike / digitalocean_regions.json
Created November 1, 2014 23:18
Digitalocean Regions (November 2014)
# https://developers.digitalocean.com/#list-all-regions
# Fetch with: curl -X GET "https://api.digitalocean.com/v2/regions" -H "Authorization: Bearer $TOKEN"
# Author: Michael de Silva <michael@mwdesilva.com> / bsodmike
# Updated: 02/11/2014
{
"regions": [
{
"name": "New York 1",
"slug": "nyc1",
"sizes": [
@bsodmike
bsodmike / example.rb
Last active August 29, 2015 14:10
Block helper in Rails 3
# FrontendHelper presentation PORO
def flag_for_country_code(country_code, &block)
country = ::Refinery::Professionals::GeoipCountry.find_by_country_code(country_code)
if country && country.available_locales.any?
flag_locale = country.available_locales.first
flag_url = "/#{flag_locale}"
country_name = country.name
yield(flag_url, country_name)
@bsodmike
bsodmike / decorator.rb
Created February 26, 2015 13:25
Simple Decorator Using Ruby Delegate for Ruby 2.1.5 & Rails 4
module Project
module Decorators
module Draperize
def self.included _klass
_klass.class_eval { extend ClassMethods }
end
module ClassMethods
# Initialize a new decorator instance by passing in
@bsodmike
bsodmike / find_category_and_products.rb
Created March 6, 2015 19:58
Example of recursive tree traversal in Ruby
module NDAClient
module Queries
class FindCategoryAndProduct
def initialize(site, user, request, params)
@current_site = site
@current_user = user
@request = request
@params = params