Skip to content

Instantly share code, notes, and snippets.

@domwom
domwom / gist:90676
Created April 6, 2009 08:58
Facebook-ish "people you may know" thingie
class User < ActiveRecord::Base
has_many :friends, :through => :friendships
has_many :friendships, :dependent => :destroy
def getMutualFriendsWith user
intersection = friends() & user.friends()
end
def getNumberOfMutualFriendsWith user
getMutualFriendsWith(user).length()
@domwom
domwom / .gitconfig
Created April 6, 2009 21:37
gitconfig
[color]
diff = auto
status = auto
branch = auto
interactive = auto
ui = true
pager = true
[color "branch"]
current = yellow reverse
@domwom
domwom / collect_iteratable.php
Created April 29, 2009 12:45
map iteratables in php
public function collect($function)
{
$result = array();
foreach ($this as $key => $value) {
array_push($result,call_user_func(array($value,$function),$value));
}
return $result;
}
@domwom
domwom / gist:109371
Created May 9, 2009 18:48
bash profile
export TERM=xterm-color
export LSCOLORS=dxfxcxdxbxegedabagacad
alias ls='ls -G'
alias ll='ls -l'
alias l='ls -la'
alias la='ls -a'
alias gs='git status'
# tweak bash tab completion
@domwom
domwom / base_template.rb
Created May 9, 2009 21:54
rails_templates
# Delete unnecessary files
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/robots.txt"
run "rm -f public/javascripts/*"
gitignoreItems = %w(
.DS_Store
log/*.log
# SUPER DARING APP TEMPLATE 1.0
# By Peter Cooper
# Link to local copy of edge rails
inside('vendor') { run 'ln -s ~/dev/rails/rails rails' }
# Delete unnecessary files
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
/*
* Twita@talinkahashifyer
* http://www.dustindiaz.com
* http://www.dustindiaz.com/basement/ify.html
*
* Copyright (c) 2009 Dustin Diaz
* licensed under public BSD
*/
var ify = function() {
return {
@domwom
domwom / no_follow_back.rb
Created August 16, 2009 15:27 — forked from jerodsanto/no_follow_back.rb
no_follow_back.rb
require 'rubygems'
require 'twitter'
auth = Twitter::HTTPAuth.new('username', 'password')
base = Twitter::Base.new(auth)
guilty = base.friend_ids - base.follower_ids
puts "There are #{guilty.size} People you follow who do not follow you"
guilty.each do |user_id|
## some dummy data
x <- seq(as.Date("2008-01-01"), as.Date("2009-10-31"), by = "day")
set.seed(1234)
y <- cumsum(rnorm(length(x)))
## plot, but suppress axes
plot(y ~ x, type = "l", axes = FALSE)
## add in axis on side 2
axis(2)
@domwom
domwom / gist:213542
Created October 19, 2009 17:45
php bitly api
function make_bitly_url($url, $login, $appkey, $format='xml', $history=1, $version='2.0.1')
{
//create the URL
$bitly = 'http://api.bit.ly/shorten';
$param = 'version='.$version.'&longUrl='.urlencode($url).'&login='
.$login.'&apiKey='.$appkey.'&format='.$format.'&history='.$history;
//get the url
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $bitly . "?" . $param);