Skip to content

Instantly share code, notes, and snippets.

View webmat's full-sized avatar

Mathieu Martin webmat

View GitHub Profile

Development box installation guide

This guide will show how to setup a VirtualBox similiar to an Ubuntu 12.04.1 server for use with Amazon EC2.

Covered in this guide:

  • VeeWee: Tool for building base boxes which will be used by vagrant
  • Vagrant: Tool for managing virtual machines with an easy to use CLI
  • Librarian: Bundler for chef cookbooks
  • Chef-solo & Knife solo: Tool for automating installing and management of servers
@webmat
webmat / minitest_unit_decl.rb
Last active December 11, 2015 13:28
Missing Rails-style declarative helpers in your plain minitest/unit test suite? Here's something to get you started.
class MiniTest::Unit::TestCase
class << self # The def self.test way of doing it doesn't override Kernel.test but this does...
def test(name, &block)
method_name = "test_#{ name.gsub(/[\W]/, '_') }"
if block.nil?
define_method(method_name) do
flunk "Missing implementation for test #{name.inspect}"
end
else
define_method(method_name, &block)
@webmat
webmat / benchmark.rb
Created May 10, 2012 12:52 — forked from panthomakos/benchmark.rb
Benchmark Your Bundle
#!/usr/bin/env ruby
# Temporarily add this dir to your path
# export PATH=~/gists/bundle_benchmark:$PATH
# cd to any of your project and run the benchmark
# cd ~/my-project
# benchmark.rb
require 'benchmark'
require 'bundler'
@webmat
webmat / config_initializers_database.rb
Created March 29, 2012 15:21
Tweak Postgresql config to your liking on Rails boot. Works on Heroku.
Rails.configuration.after_initialize do
case ENV['DB_SPEED']
when 'fast'
ActiveRecord::Base.connection.execute "update pg_settings set setting='off' where name = 'synchronous_commit';"
when 'safe'
ActiveRecord::Base.connection.execute "update pg_settings set setting='on' where name = 'synchronous_commit';"
end
end
@webmat
webmat / gist:1978201
Created March 5, 2012 12:51
"e" shortcut for vim lovers
export EDITOR=vim
function e {
if [ -z $1 ] ; then # nothing specified
$EDITOR .
elif [ -d $1 ] ; then # directory specified
cd $1 ; $EDITOR . ; cd -
else # file specified
$EDITOR $1
fi
}
@webmat
webmat / dashboards.rb
Created February 22, 2012 20:46
First draft of an active_admin-based view for Delayed::Job
ActiveAdmin::Dashboards.build do
# Add this section in your dashboard...
section "Background Jobs" do
now = Time.now.getgm
ul do
li do
jobs = Delayed::Job.where('failed_at is not null').count(:id)
link_to "#{jobs} failing jobs", admin_jobs_path(q: {failed_at_is_not_null: true}), style: 'color: red'
end
@webmat
webmat / hash_to_s.rb
Created September 13, 2011 18:49
Better Ruby Hash#to_s
# Let's face it. Ruby's Hash#to_s output isn't very useful.
# Here's a draft for a better version.
class Hash
def to_s
keys.inject([]) do |a, key|
a << "#{key}: #{fetch(key)}"
end.join(', ')
end
end
@webmat
webmat / 0_instructions.txt
Created May 16, 2011 20:33 — forked from eric1234/0_instructions.txt
Using Sprockets 2 in Rails 3.0.x with CoffeeScript & SASS
Some brief instructions on how to use Sprocket 2 in Rails to get CoffeeScript
powered JS and SASS powered CSS with YUI compression all via the magic of rack.
This stuff will be native in Rails 3.1 and the layout of the files on the
filesystem will be different but this guide will get you working with it
while we wait for all that to finalize.
Ignore the number prefixes on each file. This is just to ensure proper order in the Gist.
@webmat
webmat / backbone-monkey-patch.js
Created May 4, 2011 15:30
Getting pagination information from headers with Backbone
// Get the pagination information from the response headers
// Wrap Backbone.sync to save the pagination header on the response object.
Backbone.sync_with_pagination = function(method, model, success, error) {
var success_with_pagination = function(resp, status, xhr) {
resp.next_page = xhr.getResponseHeader('X-Next-Page');
return success(resp);
}
return Backbone.sync_without_pagination(method, model, success_with_pagination, error);
};