Skip to content

Instantly share code, notes, and snippets.

package main
import (
"net/http"
"database/sql"
"fmt"
"log"
"os"
)

A daily glance at what's happening in a high velocity codebase, thanks to @defunkt:

https://github.com/your/repo/compare/master@{yesterday}...master

Bookmark, share, and enjoy.

@tpope
tpope / gist:2999229
Created June 26, 2012 21:26
Environment variable overrides in Rails
# Add config/overrides/*.yml to .gitignore
# and this near the top of application.rb
%w(defaults overrides).each do |type|
path = File.expand_path("../#{type}/#{Rails.env}.yml", __FILE__)
ENV.update(YAML.load_file(path)) if File.exist?(path)
end
# For things that are sensitive or developer dependent:
# config/overrides/{development,test}.yml
# For everything else:
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
# encoding: UTF-8
def whistle
puts rand > 0.5 ? "♫" : "♪ "
end
def you_work
rand < 0.9
end
whistle while you_work
@simonreed
simonreed / rails.rb
Created May 11, 2011 17:06
.watchr/rails.rb
ENV["WATCHR"] = "1"
system 'clear'
def growl(message)
growlnotify = `which growlnotify`.chomp
title = message.include?('0 failures, 0 errors') ? "AWESOMEO" : random_insult
image = message.include?('0 failures, 0 errors') ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
system %(#{growlnotify} #{options} &)
end
if defined?(RSpec)
namespace :rcov do
RSpec::Core::RakeTask.new(:rspec_aggregate) do |task|
task.pattern = 'spec/**/*_spec.rb'
task.rspec_opts = "--format progress"
task.rcov = true
task.rcov_opts = "--rails --exclude osx\/objc,spec,gems\/ " +
"--aggregate tmp/coverage.data"
end
@igrigorik
igrigorik / when-proc.rb
Created January 9, 2011 23:00
you can call a proc via: f === :arg!
# ruby 1.9 supports 4 ways to call a proc! ex: f =->n {[:hello, n]}; f[:ruby]; f.call(:ruby); f.(:ruby)
#
# turns out, you can also call a proc via proc === :arg -- which means you can use proc's in when clauses!
# ruby doc: http://ruby-doc.org/ruby-1.9/classes/Proc.html#M001165
#
# ... kudos to @chadfowler for the tip!
#
# (note: works on 1.8.7 as well :-))
def should_i_upgrade?
# Add that to your app make, after you define the sinatra env.
Thread.current[:thinking_sphinx_environment] = Sinatra::Application.environment
# When requiring TS add a new task to properly generate the config file
require 'thinking_sphinx'
require 'thinking_sphinx/tasks'
namespace :thinking_sphinx do
namespace :my_app do
# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end