Skip to content

Instantly share code, notes, and snippets.

View kent's full-sized avatar
👋

Kent Fenwick kent

👋
View GitHub Profile
@kent
kent / jQuery Colourizer.js
Created May 28, 2009 14:45
Add a splash of random colour to elements of your page
// jQuery Colourizer
// Kent Fenwick 2009
// Use it when you want to add a splash of random colour to your page
// Create the colour array
var color_array = ["#ce521d","#ca4b89","#006b89","#3e2d7e","#61902c", "#faa31a", "#6e002a", "#4981b3",
"#980069", "#2dacbf", "#ee1d25", "#9cb46f", "#9a869e", "#ee008c", "#00a895",
"#7b181a", "#ffd63c", "#b46638", "#bcd634", "#f4ea00", "#32b6c0", "#e8ac1c",
"#ea2d50", "#3c7022", "#0085cc", "#97C83B"];
// Pick a random colour of the array
@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)
@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");
}
from pymongo import MongoClient
connection = MongoClient('173.255.248.42', 27017)
db = connection.eventish
<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
<iframe style="height:360px; width:180px; border:0" src="https://www.tilt.com/tilts/phi-delts-fall-festival-long-sleeve-tshirt/iframe_widget"></iframe>
<iframe style="height:360px; width:180px; border:0" src="your_tilt_link_goes_here/iframe_widget"></iframe>
@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\]"
@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
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