Skip to content

Instantly share code, notes, and snippets.

View mpouleijn's full-sized avatar

Michel Pouleijn mpouleijn

View GitHub Profile
@mpouleijn
mpouleijn / gist:1111490
Created July 28, 2011 12:59
Ruby Style Guide
Original Source: https://github.com/chneukirchen/styleguide
= Christian Neukirchen's Ruby Style Guide
You may not like all rules presented here, but they work very well for
me and have helped producing high quality code. Everyone is free to
code however they want, write and follow their own style guides, but
when you contribute to my code, please follow these rules:
@mpouleijn
mpouleijn / gist:1681816
Created January 26, 2012 08:53
Command line shortcuts

Input

Ctrl + a # Move the cursor to the beginning of the current line.
Ctrl + e # Move the cursor to the end of the current line.
Alt + b # Move the cursor to the beginning of the current or previous word.
Alt + f # Move the cursor to the end of the next word. Again, like with all shortcuts that use Alt as the modifier
Tab # Autocomplete commands and file names.
Ctrl + u # Erase the current line.
Ctrl + k # Delete the line from the position of the cursor to the end of the line.
Ctrl + w # Delete the word before the cursor.

@mpouleijn
mpouleijn / deep_fetch.rb
Created January 31, 2012 10:58 — forked from avdi/deep_fetch.rb
Deep Fetch
module DeepFetch
def deep_fetch(*keys, &fetch_default)
throw_fetch_default = fetch_default && lambda {|key, coll|
args = [key, coll]
# only provide extra block args if requested
args = args.slice(0, fetch_default.arity) if fetch_default.arity >= 0
# If we need the default, we need to stop processing the loop immediately
throw :df_value, fetch_default.call(*args)
}
catch(:df_value){
@mpouleijn
mpouleijn / etc_init.d_unicorn_example.co.uk
Created February 13, 2012 22:07 — forked from scottlowe/etc_init.d_unicorn_example.co.uk
Ruby on Rails server setup on Ubuntu 11.04 with Nginx, Unicorn, Rbenv
#! /bin/bash
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web server
# Description: starts unicorn
@mpouleijn
mpouleijn / slide1.rb
Created February 16, 2012 13:24
Evented Sinatra
## Eventmachine
# Non-blocking I/O event loop in Ruby
# Lots of extensions that support MySQL, AMPQ, Redis, Memcache, etc.
# Suffers from callback hell (like node.js)
# Easy to start with
require 'eventmachine'
require 'em-http-request'
EventMachine.run {
@mpouleijn
mpouleijn / anonymizer_source.rake
Created February 24, 2012 15:08 — forked from adarsh/anonymizer_source.rake
Code from blog post on anonymizing sensitive user data
task :env_checker do
unless Rails.env.development?
puts "Not in development environment, exiting!"
exit 1
end
end
namespace :app_name do
desc 'Anonymize user, company, and location information'
task :anonymize => [:environment, :env_checker] do
@mpouleijn
mpouleijn / datastaxCommunity.bash
Created March 6, 2012 07:57 — forked from cmaxw/datastaxCommunity.bash
DataStax Community install script
#!/bin/bash
# Use Oracle Sun Java
wget http://javadl.sun.com/webapps/download/AutoDL?BundleId=59621
mv AutoDL?BundleId=59621 jre-6u31-linux-i586.bin
sudo mkdir -p /opt/java/32
sudo mv ./jre-6u31-linux-i586.bin /opt/java/32
sudo chmod 755 /opt/java/32/jre-6u31-linux-i586.bin
cd /opt/java/32
sudo ./jre-6u31-linux-i586.bin
@mpouleijn
mpouleijn / minitest_spec_expectations.md
Created March 16, 2012 15:52 — forked from ordinaryzelig/minitest_spec_expectations.md
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations
@mpouleijn
mpouleijn / rvm2rbenv.txt
Created April 16, 2012 09:54 — forked from brentertz/rvm2rbenv.txt
Switch from RVM to RBENV
## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################
@mpouleijn
mpouleijn / deploy.rb
Created April 23, 2012 09:59
Unicorn + Nginx
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
set :rvm_ruby_string, 'ree-1.8.7@bed4you'
set :rvm_type, :user
require 'bundler/capistrano'
require 'capistrano/ext/multistage'
require 'capistrano_colors'
set :application, 'bed4you'
set :rake, 'bundle exec rake'