Skip to content

Instantly share code, notes, and snippets.

View joshsusser's full-sized avatar

Josh Susser joshsusser

View GitHub Profile
@joshsusser
joshsusser / gist:1375148
Created November 18, 2011 00:51
reset pk sequence for model tables before seeding postgresql db
models = ActiveRecord::Base.connection.tables
models.delete(ActiveRecord::Migrator.schema_migrations_table_name)
models.each do |table|
ActiveRecord::Base.connection.reset_pk_sequence!(table)
end
@joshsusser
joshsusser / gist:998055
Created May 29, 2011 19:20
turn off 255 limit for string fields in postgresql
# in rails application.rb
initializer "postgresql.no_default_string_limit" do
ActiveSupport.on_load(:active_record) do
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:string].delete(:limit)
end
end
@joshsusser
joshsusser / gist:929622
Created April 19, 2011 20:50
git status to mate
#open all new and modified files in textmate tabs for open project:
git status -s -uall | cut -b 4- | xargs -n 1 mate
@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
@joshsusser
joshsusser / Tenderlove Theme Song
Created March 25, 2011 16:14
Tenderlove Theme Song
( roughly to the tune of the Ultraman theme song:
http://www.televisiontunes.com/Ultraman.html )
Tenderlove, Tenderlove
Ruby programming guy
Tenderlove, Tenderlove
he's as awesome as _why
Seattle is his home
he's a Ruby brigadier
@joshsusser
joshsusser / example_devise_controller_spec.rb
Created March 15, 2011 17:08
How to test a devise controller in rspec
require 'spec_helper'
describe Example::RegistrationsController do
before(:each) do
setup_controller_for_warden
request.env["devise.mapping"] = Devise.mappings[:example]
end
describe "sign up" do
it "does something"
@joshsusser
joshsusser / seed.rb
Created March 1, 2011 23:13
reset all db tables before re-seeding
# reset tables
tables = ActiveRecord::Base.connection.tables
tables.delete("schema_migrations")
tables.each do |table|
ActiveRecord::Base.connection.execute("TRUNCATE TABLE #{table}")
ActiveRecord::Base.connection.reset_pk_sequence!(table)
end
# seed data
#
@joshsusser
joshsusser / gist:672940
Created November 11, 2010 18:26
always do bundle open using TextMate
alias bo="env EDITOR=mate bundle open $*"
@joshsusser
joshsusser / example.html
Created October 18, 2010 07:47
I like this approach to putting mustache/handlebars templates in script tag sections. Reads much easier than assembling them from strings in JavaScript.
<!DOCTYPE HTML>
<html>
<head>
<script src="javascripts/jquery.js" type="text/javascript"></script>
<script src="javascripts/handlebars.js" type="text/javascript"></script>
<script id="main" type="text/html">
<ul>
{{#people}}
<li>{{> link}}</li>
gem list | cut -f 1 -d " " | xargs -E gem gem dep -R $gem | grep -v "^ \w" | grep -P "^[^\s][^\n]+\n[^ ]" -o | grep -v "^$" | sort | cut -f 2 -d " "