Skip to content

Instantly share code, notes, and snippets.

module AssociationIds
def ids_for name
name = name.to_s
define_method (name + '_ids=').to_sym do |ids|
values = ids.collect { |id| Kernel.const_get(name.classify).find id }
self.send(name + '=', values)
end
define_method (name + '_ids').to_sym do
self.send(name).collect { |obj| obj.id }
@bensonk
bensonk / location_json.js
Created October 15, 2011 22:24
Location JSON format
{"accuracy":20,"altitude":null,"altitude_accuracy":null,"created_at":"2011-10-06T00:14:33Z","heading":"","id":13053,"latitude":48.0516098,"longitude":-123.6075554,"note_id":null,"recorded_at":"2011-10-14T09:17:13Z","speed":null,"updated_at":"2011-10-14T09:17:13Z","user_id":91,"notes":[{"created_at":"2011-10-06T03:35:39Z","id":94,"latitude":null,"location_id":13053,"longitude":null,"network_id":null,"recorded_at":"2011-10-06T03:35:39Z","subject":"asdfasdf","text":"This is a test.","updated_at":"2011-10-06T03:35:39Z","user_id":91},{"created_at":"2011-10-14T09:19:01Z","id":95,"latitude":null,"location_id":13053,"longitude":null,"network_id":null,"recorded_at":"2011-10-14T09:19:01Z","subject":"blargle","text":"wheeeee","updated_at":"2011-10-14T09:19:01Z","user_id":91}],"tasks":[{"created_at":"2011-10-15T22:17:16Z","date":null,"description":"bar","form_id":null,"groups":null,"id":4,"location_id":13053,"name":"foo","network_id":null,"priority":null,"updated_at":"2011-10-15T22:19:44Z","user_id":91,"users":[]}],"hasN
@bensonk
bensonk / .bash_profile
Created October 17, 2011 01:46
My Bash Prompt
export PS1="\[\033[01;32m\]\u@\h\[\033[01;34m\] \w$(__git_ps1 "\e[1;30m [%s]") \[\033[01;34m\]$ \[\033[00m\]"
module AssociationIds
def ids_for name
name = name.to_s
define_method (name + '_ids=').to_sym do |ids|
values = ids.collect { |id| Kernel.const_get(name.classify).find id }
self.send(name + '=', values)
end
define_method (name + '_ids').to_sym do
self.send(name).collect { |obj| obj.id }
# nvidia-settings: X configuration file generated by nvidia-settings
# nvidia-settings: version 270.29 (buildd@allspice) Fri Feb 25 14:42:07 UTC 2011
# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig: version 270.41.06 ([email protected]) Mon Apr 18 15:14:00 PDT 2011
Section "ServerLayout"
Identifier "Layout0"
Screen 0 "Screen0" 0 0
InputDevice "Keyboard0" "CoreKeyboard"
#!/usr/bin/env ruby
require "base64"
def b(string, context)
string.gsub /\^\{(.*?)\}/ do |s|
val = context.eval(s[2..-2])
"b64d(\"#{Base64.encode64(val).strip}\")"
end
end
@bensonk
bensonk / ps1.sh
Created February 29, 2012 21:53
Python, mercurial, and git friendly prompt script for bash.
#!/bin/bash
# Put this in ~/bin/ps1, and make it executable
# Then add the following line to your .bashrc or .bash_profile:
# PROMPT_COMMAND="source $HOME/bin/ps1"
HG_BRANCH=`hg branch 2>&1`
if [[ $? == 0 ]]
then
VCS_PROMPT="\[\033[00;33m\](\[\033[00;37m\]$HG_BRANCH\[\033[00;33m\]) \[\033[01;34m\]"
else
# Fix the path to search (and prioritize) $HOME/bin and /usr/local/bin
export PATH="$HOME/bin:/usr/local/bin:$PATH"
# Virtual Env Wrapper Prompt Stuff:
source `which virtualenvwrapper.sh`
workon work
export VIRTUAL_ENV_DISABLE_PROMPT=1
export PROMPT_COMMAND='source $HOME/bin/ps1'
# Setup autojump
source :rubygems
gem 'json'
$('tr').map(function(i, it) {
cells = $(it).children('td');
if(cells[0])
return {
time: cells[0].textContent,
eld_fb: cells[1].textContent,
eld_fb2: cells[2].textContent,
eld_ob: cells[3].textContent
}
})