Skip to content

Instantly share code, notes, and snippets.

@mislav
mislav / Gemfile
Last active August 29, 2015 14:18 — forked from janko/benchmark.rb
source "https://rubygems.org"
gem "minitest"
gem "rspec"
@eventualbuddha
eventualbuddha / seed_file.rb
Created July 9, 2010 01:51
SeedFile, a helper for doing database setup in a Rails 3 app
# Helper class for importing files with records to the database.
class SeedFile
def self.import(path)
new(path).import
end
attr_reader :path
def initialize(path)
@path = Pathname(path)
#!/usr/bin/env ruby
def binding_play(&blk)
eval("__LINE__", blk)
end
puts binding_play {
puts "FOO"
}
@indirect
indirect / gist:631628
Created October 18, 2010 02:49
improved git prompt yay
# [andre ~/.bash](master)$ # clean working directory
# [andre ~/.bash](master⚡)$ # dirty working directory
# [andre ~/.bash](master~2)$ # checked out revision not a branch
# [andre ~/.bash](branch)$ # checked out branch with same commits as master
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "⚡"
}
function parse_git_branch {
@joshsusser
joshsusser / gist:900068
Created April 3, 2011 00:52
init postgresql db after brew install
initdb -U postgres --encoding=utf8 --locale=en_US -D /usr/local/var/postgres
@indirect
indirect / better_logger.rb
Created July 19, 2011 07:00
Rails 3 logs with severity and PIDs
# You must require this file in application.rb, above the Application
# definition, for this to work. For example:
#
# # Syslog-like Rails logs
# if Rails.env.production?
# require File.expand_path('../../lib/better_logger', __FILE__)
# end
#
# module MyApp
# class Application < Rails::Application
@JackDanger
JackDanger / descriptive_sql_load_log.rb
Created July 19, 2011 20:24
Let Rails display file names and line numbers for log activity.
module ActiveRecord
module ConnectionAdapters
class AbstractAdapter
protected
# Turn:
# User Load (6.3ms) SELECT * FROM "users"
# Into:
# User Load /app/views/_partial.erb:27 (6.3ms) in `_app_views_partial_erb` SELECT * FROM "users"
@zerowidth
zerowidth / ar_pg_defaults.gemspec
Created October 4, 2011 16:11
Let postgres insert default values for columns with default values that AR 3.1 doesn't understand
Gem::Specification.new do |s|
s.name = "ar_pg_defaults"
s.version = "0.0.1"
s.platform = Gem::Platform::RUBY
s.author = "Nathan Witmer"
s.email = "nwitmer@gmail.com"
s.homepage = "https://gist.github.com/1262051"
s.summary = "Help AR let postgres do its thing"
s.description = "Let postgres insert default values for columns with default values that AR 3.1 doesn't understand"
@chriseppstein
chriseppstein / rbenv-each.sh
Created October 12, 2011 15:49
Execute the same command in each installed ruby via rbenv
#!/bin/bash
verbose=0
function usage() {
echo >&2 "Usage: rbenv each [-v] ..."
echo >&2 " -v Verbose mode. Prints a header for each ruby."
}
while getopts vh option
do case "$option" in
@joshsusser
joshsusser / silence_assets.rb
Created April 17, 2012 22:34
put in config/initializers to silence asset logging in Rails development mode
if Rails.env.development?
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'] =~ %r{^/assets/}
call_without_quiet_assets(env)
ensure