Skip to content

Instantly share code, notes, and snippets.

@jasoncodes
jasoncodes / vim_tips.markdown
Last active December 21, 2015 00:08
Vim Tips

Vim Tips

fresh

Build your dotfiles (shell, Vim config) from multiple sources with fresh.

Both of our dotfiles are built using fresh. We source Vim and other config from each other:

@jasoncodes
jasoncodes / README
Last active May 1, 2024 21:29
Remote Chrome browser for Capybara
On the shared machine:
Download http://code.google.com/p/selenium/downloads/detail?name=selenium-server-standalone-2.33.0.jar&can=2&q=
$ brew install chromedriver
$ java -jar selenium-server-standalone-2.33.0.jar
On the local machine:
Set `CHROME_HOSTNAME` in your `.env`, `.rbenv_vars`, or per run.
@jasoncodes
jasoncodes / gist:3065508
Created July 7, 2012 08:36
Named route name from path
path = '/products/42/edit'
params = Rails.application.routes.recognize_path path
route = nil; Rails.application.routes.formatter.send(:match_route, nil, params) { |r| route ||= r }
p route.name # returns "edit_product"
@jasoncodes
jasoncodes / gist:1938675
Created February 29, 2012 06:59
Default `psql` to current Rails application
function __database_yml {
if [[ -f config/database.yml ]]; then
ruby -ryaml -rerb -e "puts YAML::load(ERB.new(IO.read('config/database.yml')).result)['${RAILS_ENV:-development}']['$1']"
fi
}
function psql
{
if [[ "$(__database_yml adapter)" == 'postgresql' ]]; then
PGDATABASE="$(__database_yml database)" "$(/usr/bin/which psql)" "$@"
@jasoncodes
jasoncodes / enum_group_by_many.rb
Created December 12, 2011 23:47
Enumerable#group_by_many
Enumerable.class_eval do
def group_by_many
{}.tap do |groups|
each do |value|
keys = yield value
keys.each do |key|
group = groups[key] ||= []
group << value
end
end
@jasoncodes
jasoncodes / create_item_children_count.rb
Created October 23, 2011 19:04
Create ActiveRecord models for database views
class CreateItemChildrenCountView < ActiveRecord::Migration
def self.up
execute <<-SQL
CREATE VIEW item_children_count AS
SELECT parent_id AS item_id, COUNT(*) as children_count
FROM items GROUP BY parent_id;
SQL
end
def self.down
@jasoncodes
jasoncodes / _form.html.haml
Created October 18, 2011 05:42
Using ActiveRecord optimistic locking with Inherited Resources
/ ...
- f.inputs do
= f.hidden_field :lock_version
/ ...
@jasoncodes
jasoncodes / gist:1223731
Created September 17, 2011 07:45
Installing Ruby 1.9.3 with rbenv on OS X
# The latest version of this script is now available at
# https://github.com/jasoncodes/dotfiles/blob/master/aliases/rbenv.sh
VERSION=1.9.3-p286
brew update
brew install rbenv ruby-build rbenv-vars readline ctags
if [ -n "${ZSH_VERSION:-}" ]; then
echo 'eval "$(rbenv init - --no-rehash)"' >> ~/.zshrc
else
echo 'eval "$(rbenv init - --no-rehash)"' >> ~/.bash_profile
@jasoncodes
jasoncodes / pivotal_tracker-fight_wrinkles.user.js
Created May 15, 2011 23:46
Pivotal Tracker Userscript to Fight UI Wrinkles
// ==UserScript==
// @name Pivotal Tracker: Fight Wrinkles
// @description Fixes a few small UI annoyances with Pivotal Tracker.
// @author Jason Weathered
// @namespace http://jasoncodes.com/
// @match https://www.pivotaltracker.com/*
// @include https://www.pivotaltracker.com/*
// @version 1.0.0
// ==/UserScript==
@jasoncodes
jasoncodes / Apple Terminal.itermcolors
Created May 11, 2011 23:18
iTerm colours that resemble Apple's Terminal.app defaults
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Blue Component</key>
<real>0.0</real>
<key>Green Component</key>
<real>0.0</real>