Skip to content

Instantly share code, notes, and snippets.

@gbp
gbp / spec_helper.rb
Created March 14, 2014 10:43
rspec with zeus and spork
require 'rubygems'
prefork = lambda {
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
}
each_run = lambda {
...
FROM ubuntu:12.04
RUN apt-get update
RUN apt-get install -y --force-yes build-essential curl git
RUN apt-get install -y --force-yes zlib1g-dev libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt-dev
ADD http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.0.tar.gz /tmp/ruby-2.1.0.tar.gz
RUN cd /tmp; \
tar xzf ruby-2.1.0.tar.gz; \
@clemens
clemens / tmpdir.rb
Created November 25, 2010 09:39
Set environment variable so that Dir::tmpdir uses another temp directory
require 'fileutils'
# force the whole app to use its own tmpdir
FileUtils.mkdir_p(Rails.root.join('tmp'))
ENV['TMPDIR'] = Rails.root.join('tmp')
@vicentereig
vicentereig / ruby_csv_simple_object_mapping.rb
Last active October 7, 2015 15:38
Awesome FasterCSV Features. Thanks @JEG2
# http://ruby-doc.org/stdlib-1.9.2/libdoc/csv/rdoc/CSV.html#method-c-load
# http://ruby-doc.org/stdlib-1.9.2/libdoc/csv/rdoc/CSV.html#method-c-dump
# https://github.com/JEG2/faster_csv/blob/master/test/tc_serialization.rb
require 'csv'
class Person
attr_accessor :id, :name, :email
def self.csv_load(meta, headers, row)
person = Person.new
@klj613
klj613 / gittips.md
Created September 4, 2012 16:12
Git Tips

...

  • treeish: anything which references a commit (e.g. branch, HEAD, HEAD10, master15, SHA)

git show <treeish>:<file>

Displays file from a specific commit

git checkout <treeish> -- <file>

Checkout a file from a specific commit

e.g.

@garethrees
garethrees / hash_arguments.rb
Last active October 12, 2015 14:08
Hash arguments, default values and asserting valid keys
def donate_to_charity(args = {})
# Set valid options that can be supplied. All others will be cut.
valid_args = [:user_id, :charity_id, :amount]
# Set default options if none are supplied
defaults = { :user_id => nil,
:charity_id => 1,
:amount => 25 }
# Raise ArgumentError if invalid keys are passed
@garethrees
garethrees / _analytics.html.erb
Created November 24, 2012 22:35
Rails Shared Templates
<%#
# Renders Google Analytics tracking script
#
# Example
#
# <%= render 'shared/analytics', ua_code: 'UA-XXXXXX-X' %>
#
#%>
<% if Rails.env.production? %>
<script type="text/javascript">
@Odaeus
Odaeus / packages.md
Last active December 15, 2015 10:19
Packages for running Ruby on Rails on Ubuntu

Minimal for gem compilation

  • build-essential

Common for gems

  • libxml2
  • libxml2-dev (for nokogiri)

Ruby compilation

  • libreadline6
@maxehmookau
maxehmookau / raspiairplay.md
Created July 2, 2013 19:04
How to turn a Raspberry Pi in to an AirPlay Server

How to turn a Raspberry Pi in to an AirPlay Server

$ ssh pi@192.168.xxx.xxx
Enter Password: raspberry

$ sudo raspi-config
Choose 'Repurpose entire SD card'

Update apt repositories