Skip to content

Instantly share code, notes, and snippets.

@joho
joho / vegan-with-an-iphone.md
Created October 27, 2010 06:52
Some questions for vegans.

Moral questions for veganism

Hypothetically, you are a vegan with an iPhone.

Your choice to become a vegan was because you determined it to be morally correct.

Your moral evaluation is based primarily on two considerations

  • That factory farming is harming the environment
  • That treating animals inhumanely is, well, inhumane
@adamhunter
adamhunter / unicorn.sh
Created December 28, 2010 14:29
init.d file for unicorn with rails 3
#!/bin/sh
set -e
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/deploy/taxscribe/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="/usr/local/bin/unicorn --config-file $APP_ROOT/config/unicorn.server.rb --env production --daemonize $APP_ROOT/config.ru"
action="$1"
@brianmario
brianmario / config.ru.rb
Created April 21, 2011 06:11
minimal rails3 app
# minimal rails3 app
require 'action_controller'
Router = ActionDispatch::Routing::RouteSet.new
Router.draw do
root :to => 'site#index'
end
class SiteController < ActionController::Metal
@xaviershay
xaviershay / application_controller.rb
Created May 19, 2011 21:43
Access helper methods outside controllers and views
class ApplicationController < ActionController::Base
# Provide access to helper methods from outside controllers and views,
# such as in Presenter objects. Rails provides ActionController::Base.helpers,
# but this does not include any of our application helpers.
def self.all_helpers
@all_helpers_proxy ||= begin
# Start with just the rails helpers. This is the same method used
# by ActionController::Base.helpers
proxy = ActionView::Base.new.extend(_helpers)

See all your work in a given repo over the last couple of weeks, collated by day. Makes filling out timesheets much easier.

To run the script, pass it a git repo as the first argument.

ruby timesheeting_like_a_boss.rb ~/projects/babushka

Here's what I see in babushka:

# 2011-05-25 (Wed)

c1dea1b: Return strings from #which and #cmd_dir.

@taf2
taf2 / load.patch
Created June 5, 2011 13:05
Ruby 1.9.2-p180 require performance patch
--- a/load.c 2010-10-23 05:36:38.000000000 -0400
+++ b/patchload.c 2011-06-05 08:58:00.000000000 -0400
@@ -40,14 +40,6 @@
VALUE ary;
long i;
- for (i = 0; i < RARRAY_LEN(load_path); ++i) {
- VALUE str = rb_check_string_type(RARRAY_PTR(load_path)[i]);
- if (NIL_P(str) || !rb_is_absolute_path(RSTRING_PTR(str)))
- goto relative_path_found;
@evolve2k
evolve2k / gist:1077086
Created July 12, 2011 00:05
What makes a good README
Notes from 'Xavier Shay's talk' - What makes a good README file (RORO 2010 Melbourne)
Use Symantic versioning (Major.Minor.Patch)
What
----
What prob u solving
How
---
@pat
pat / gist:1096339
Created July 21, 2011 01:43
Check definition pair in a definition list
Then /^"([^"]*)" should be set as "([^"]*)"$/ do |term, definition|
first(:xpath, "//dd[preceding-sibling::dt[.='#{term}']]").text.
should == definition
end
@mdub
mdub / postgresql_full_text_search.rb
Created August 3, 2011 07:05
PostgreSQL full-text search support for ActiveRecord
module PostgresqlFullTextSearch
extend ActiveSupport::Concern
module ClassMethods
def tsearch(column_names, terms)
raise(ArgumentError) if terms.nil?
return self.scoped if terms == ""
vectors = Array(column_names).map do |column_name|
@wtaysom
wtaysom / where_is.rb
Created September 23, 2011 08:57
A little Ruby module for finding the source location where class and methods are defined.
module Where
class <<self
attr_accessor :editor
def is_proc(proc)
source_location(proc)
end
def is_method(klass, method_name)
source_location(klass.method(method_name))