Skip to content

Instantly share code, notes, and snippets.

@jasoncodes
jasoncodes / README
Created February 10, 2011 00:02
IPv6 router announcement with DNS
iOS 4.2.1 detects shows the announced DNS settings in Settings, Wi-Fi Networks within a second of starting `radvd`. The search domain does not appear to be supported.
@jasoncodes
jasoncodes / go.rb
Created March 12, 2011 03:16
API Terms of Service
#!/usr/bin/env ruby -w
require 'shellwords'
require 'fileutils'
# generate plain text versions
Dir['*.html'].each do |html_filename|
open("|elinks -dump -dump-width 9000 -no-numbering -no-references #{Shellwords.escape(html_filename)}") do |io|
@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>
@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 / 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 / _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 / 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 / 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 / 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 / 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"