Skip to content

Instantly share code, notes, and snippets.

@emyl
emyl / assets_helper.rb
Created March 6, 2012 17:03
Determine if asset pipeline is enabled, exiting gracefully if on Rails < 3.1
def assets?
begin
Rails.application.config.assets.enabled || false
rescue NoMethodError
false
end
end
@emyl
emyl / i18n.rake
Created March 13, 2012 21:37
Copy translations from simple backend (YAML) to Active Record
namespace :i18n do
desc "Copy translations from simple backend (YAML) to Active Record"
task :copy2ar => :environment do
unless I18n.backend.instance_of?(I18n::Backend::Simple)
I18n.backend = I18n::Backend::Simple.new
I18n.backend.load_translations
end
Translation.delete_all
I18n.available_locales.each do |loc|
@emyl
emyl / enumerable.rb
Created April 6, 2012 15:21
Iterate and returns the couple [previous || nil, current]
module Enumerable
def each_with_previous
self.inject(nil) { |pre, cur| yield pre, cur; cur }
self
end
end
@emyl
emyl / spec_helper.rb
Created November 21, 2012 10:26
Rspec matcher for equality without considering newlines
RSpec::Matchers.define :eq_in_one_line do |target|
match do |source|
source.gsub(/\n/, '').should eq target.gsub(/\n/, '')
end
end
@emyl
emyl / softlayer_destroy.rb
Created October 28, 2013 10:42
SoftLayer CCI destroy test
require "softlayer_api"
id = 2841947
sl = SoftLayer::Service.new('SoftLayer_Virtual_Guest',
:api_key => "<my_api_key>",
:username => "<my_username>"
)
sl.object_with_id(id).deleteObject
@emyl
emyl / xs_raid_step1.sh
Last active December 27, 2015 18:49
RAID setup for Citrix Xenserver 6.x
#!/bin/bash
echo "o
Y
n
1
2048
8388641
FD00
n
@emyl
emyl / Vagrantfile
Created December 14, 2013 10:14
Vagrant + Docker = Wordpress
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.network :forwarded_port, :guest => 8080, :host => 8080
config.vm.provision "docker" do |d|
d.pull_images "jbfink/docker-wordpress"
d.run "jbfink/docker-wordpress", :args => "-d -p 8080:80"
end
end
@emyl
emyl / foundation_template.rb
Last active January 2, 2016 08:59
Padrino template for Zurb Foundation. Works with: Stylesheet engine: Compass/Scss/None Template engine: Erb/Haml/Slim
# Template for a Zurb Foundation app. It uses Bower to manage frontend resources.
opts = options.dup
opts.delete("template")
# Check for valid template engine.
until ["erb", "haml", "slim"].include?(opts["renderer"])
opts["renderer"] = ask(
"Foundation is not compatible with #{opts["renderer"]} template engine. Choose another one [erb|haml]",
"slim"
)
@emyl
emyl / Vagrantfile
Created February 14, 2014 16:29
djenkins Vagrantfile
require "json"
Vagrant.configure("2") do |config|
config.vm.define "djenkins" do |djenkins|
djenkins.vm.box = "raring64_chef11"
djenkins.vm.box_url = "http://goo.gl/Y4aRr"
# Configuration for vagrant-omnibus plugin
djenkins.omnibus.chef_version = :latest
@emyl
emyl / install.cmd
Created February 18, 2014 11:09
Install vagrant-librarian-chef on Windows
REM Ensure that vagrant-berkshelf is not installed (it conflicts with vagrant-librarian-chef)
vagrant plugin uninstall vagrant-berkshelf
REM Install the plugin
vagrant plugin install vagrant-librarian-chef
REM Remove conflicting versions of the ffi gem from .vagrant.d
set GEM_HOME=%USERPROFILE%\.vagrant.d\gems
C:\HashiCorp\Vagrant\embedded\bin\gem uninstall ffi --ignore-dependencies --version ">1.5.0"