Skip to content

Instantly share code, notes, and snippets.

View kent's full-sized avatar
👋

Kent Fenwick kent

👋
View GitHub Profile
@kent
kent / recursively.rb
Created June 24, 2010 12:57
Find all Twitter Friends using recursion
# Here is a little recursive method that pulls in all Twitter friends using recursion
require 'rubygems'
require 'twitter'
def get_twitter_friends_with_cursor(cursor, list, client)
# Base case
if cursor == 0
return list
else
hashie = client.friends(:cursor => cursor)
class Friend < ActiveRecord::Base
belongs_to :user
belongs_to :contact, :class_name => "User", :foreign_key => "contact_id"
# user befriends contact
def self.befriend(user,contact)
relationship = find_by_user_id_and_contact_id(user.id,friend.id)
if relationship.nil?
transaction do
SET = Redis.new
SET.set_add key, value
class Friend < ActiveRecord::Base
belongs_to :user
belongs_to :contact, :class_name => "User", :foreign_key => "contact_id"
# user befriends contact
def self.befriend(user,contact)
begin
HELPERS.set_add contact.id, user.id
HELPING.set_add user.id, contact.id
class Friend < ActiveRecord::Base
belongs_to :user
belongs_to :contact, :class_name => "User", :foreign_key => "contact_id"
# user befriends contact
def self.befriend(user,contact)
relationship = find_by_user_id_and_contact_id(user.id,friend.id)
if relationship.nil?
transaction do
@kent
kent / email_sieve.rb
Created November 15, 2011 02:35
Email Sieve
f = File.open("")
content = f.read
r = Regexp.new(/\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b/)
emails = content.scan(r).uniq
puts emails
@kent
kent / git_branch_show
Created September 25, 2012 16:17
Show Git Branch for a given project
# Add this to your ~/.bash_profile to see which local git branch you are on.
function parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[1;34m\]"
GREEN="\[\033[0;32m\]"
NO_COLOUR="\[\033[0m\]"
<script>__FILE__="(none)";page_load_globals.times.code_load_completed = new Date().getTime();host.profiler.stopSummary("~ 0 loading framework js");</script>
<!-- DEBUG-TAG: app -->
<script>__FILE__="(none)";host.profiler.startSummary("~ 1 creating server globals");
server_globals=(function() {return Deserializer.create().thaw({"S":"C","C":"Map","D":[["current_version",{"S":"C","C":"VersionInfo","D":{"build_time_ms":1360630883000,"build_date_str":"Tue Feb 12 01:01:23 2013 +0000","commit_id":"712592c0708daab876ef4b893da1dd7b5622f983","commit_date_str":"Mon Feb 11 22:07:28 2013 +0000","release_revision":"20130212_010123_712592c0708daab876ef4b893da1dd7b5622f983","session_version":58}}],["session_id",4047635787510],["request_dispatch_time",1360706683095],["enabled_features",{"S":"C","C":"Array","D":["enable_only_propagate_unknown_loading_values_to_loading_boundaries","enable_memcache","enable_search_indexing","enable_action_coalescing","enable_list_caching","enable_fail_on_reentrant_handlers","enable_mobile_task_r
from pymongo import MongoClient
connection = MongoClient('173.255.248.42', 27017)
db = connection.eventish
@kent
kent / the_new_hello_world.c
Created February 27, 2013 02:49
Let's change the "Hello World" to "Change the World" because let's face it, that's what we are doing.
#include<stdio.h>
main()
{
printf("Change the World");
}