This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'twitter' | |
base = Twitter::Base.new(Twitter::HTTPAuth.new('username', 'password')) | |
my_friends = base.friend_ids | |
candidates = my_friends.inject(Array.new) { |array,id| array += Twitter.friend_ids(id); array } | |
candidates -= my_friends | |
tallied = candidates.inject(Hash.new(0)) { |hash, can| hash[can] += 1; hash } | |
ordered = tallied.sort { |x,y| y[1] <=> x[1] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActionView::Helpers::TextHelper | |
def truncate(text, *args) | |
options = args.extract_options! | |
# support either old or Rails 2.2 calling convention: | |
unless args.empty? | |
options[:length] = args[0] || 30 | |
options[:omission] = args[1] || "..." | |
end | |
options.reverse_merge!(:length => 30, :omission => "...") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
endless.rb is a pre-processor for ruby which allows you to use python-ish | |
indentation to delimit scopes, instead of having to type 'end' every time. | |
Basically, this makes the end keyword optional. If you leave off the | |
end, the preprocessor inserts an end for you at the next line indented | |
at or below the level of indentation of the line which started the scope. | |
End is optional, so you can still write things like this: | |
begin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Provides a function that allows you to choose a JDK. Just set the environment | |
# variable JDKS_ROOT to the directory containing multiple versions of the JDK | |
# and the function will prompt you to select one. JAVA_HOME and PATH will be cleaned | |
# up and set appropriately. | |
# Usage: | |
# Include in .profile or .bashrc or source at login to get 'pickjdk' command. | |
# 'pickjdk' alone to bring up a menu of installed JDKs on OS X. Select one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Generates the migration and opens it in TextMate | |
# | |
# ex.: | |
# mig AddNewColumnToModel new_column:integer | |
# | |
function mig { | |
mate `script/generate migration $@ | tail -n1 | sed 's/.*create //'` | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.bash_profile | |
sg() { | |
local migration=`script/generate $@ | awk ' /db\/migrate\//{print $NF}'` | |
if [ $migration ]; then $EDITOR $migration && rake db:migrate; fi | |
} | |
alias sgmo="sg model $@" | |
alias sgmi="sg migration $@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\[\033[01;34m\]\w\[\033[00m\]\n[${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \A]:$(parse_git_branch)\$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mongomapper' | |
class Media | |
include MongoMapper::EmbeddedDocument | |
key :file, String | |
end | |
class Video < Media | |
key :length, Integer | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Address | |
include MongoMapper::EmbeddedDocument | |
key :address | |
key :city | |
key :country | |
end | |
class Customer | |
include MongoMapper::Document | |
key :name, :required => true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: nginx | |
# Required-Start: $all | |
# Required-Stop: $all | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: starts the nginx web server | |
# Description: starts nginx using start-stop-daemon |