Skip to content

Instantly share code, notes, and snippets.

View ubermajestix's full-sized avatar

Tyler Montgomery ubermajestix

View GitHub Profile
"
" :help add-plugin
" :help add-global-plugin
" :help runtimepath
"
:help add-plugin
" :help add-global-plugin
" :help runtimepath
@ubermajestix
ubermajestix / .gvimrc
Created April 25, 2012 19:53
My vim settings
if filereadable(expand("~/.gvimrc.before"))
source ~/.gvimrc.before
endif
" CtrlP OS-X Menu remapping
if janus#is_plugin_enabled('ctrlp') && has("gui_macvim")
macmenu &File.New\ Tab key=<D-S-t>
endif
if filereadable(expand("~/.gvimrc.after"))
@ubermajestix
ubermajestix / inspector.rb
Created December 12, 2011 18:08
Override inspect on objects so RSpec failures aren't as frightening.
# When an RSpec test like this fails,
#
# @my_array.should == [@some_model, @some_model2]
#
# RSpec will call inspect on each of the objects to "help" you figure out
# what went wrong. Well, inspect will usually dump a TON OF SHIT and make trying
# to figure out why `@my_array` is not made up of `@some_model` and `@some_model2`
# really really painful.
#
# This little module and technique helps get around that. It will redefine `inspect`
namespace :db do
namespace :migrate do
desc "stucture"
task :structure => [:environment, :load_config] do
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
ActiveRecord::Migrator.migrate(['db/migrate/structure'], ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
Rake::Task["db:schema:dump"].invoke
end
# This will run the migrations in db/migrate/data.
class Presenter
class Base
def routes
Rails.application.routes.url_helpers
end
alias :r :routes
# Wholesale stole helpers and self.helpers from Draper
def helpers
@ubermajestix
ubermajestix / handlebars_helpers.coffee
Created November 8, 2011 22:18
Rails routes in ur javascriptz! Rails like link_to in Handlebarz! Mustaches and stuff!
# Builds a link using the route helper below
# text - String
# route_name - String used to lookup route in the routes global object
Handlebars.registerHelper 'link_to', (text, route_name) ->
href = Handlebars.helpers['route'](route_name, @)
template = _.template("<a href='{{href}}'>{{text}}</a>")
template(text: text, href: href)
# Returns what it returns.
# Grab a named route from the global routes object
if Module.const_defined?('ActionView')
include ::ActionView::Helpers::NumberHelper
namespace :db do
namespace :tables do
desc "how big is each table?"
task :size => :environment do
sql = "SELECT tablename FROM pg_tables WHERE schemaname = 'public' ORDER BY tablename;"
tables = ActiveRecord::Base.connection.execute(sql)
sizes = []
@ubermajestix
ubermajestix / Rakefile
Created September 22, 2011 19:00
Rake tasks for managing your spork server. Check the Rakefile to bypass loading Rails to run these rake tasks super fast.
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
# If certain tasks are called, don't load Rails!
if %w(spork:start spork:restart spork:stop).include?(Rake.application.top_level_tasks.first)
# Load the rake tasks
Dir.glob("#{File.expand_path("../lib/tasks", __FILE__)}/*.rake").each { |r| import r }
else
require File.expand_path('../config/application', __FILE__)
@ubermajestix
ubermajestix / 1. Write the tame.tjs code .js
Created July 18, 2011 18:22
A basic tame.js example from http://tamejs.org/ with the compiled javascript
// This file will be compiled into native Javascript.
// You can't just use twait natively!
// It writes out nasty js, but hey, you didn't have to write the nasty js right?
require('tamejs').register();
var dns = require("dns");
function do_one (ev, host) {
twait {
dns.resolve (host, "A", mkevent (var err, ip));