Skip to content

Instantly share code, notes, and snippets.

View kitsunde's full-sized avatar
💭
Poisoning pigeons in the park

Kit Sunde kitsunde

💭
Poisoning pigeons in the park
View GitHub Profile
@kitsunde
kitsunde / gist:3699827
Created September 11, 2012 16:59
FacebookApplication lookup
class FacebookApplication(object):
def process_request(self, request):
current_url = request.get_absolute_path()
match_url = "^" + current_url.replace('http://', 'https://')
# This is admittedly a rather strange looking.. lookup.
# What we need to do is find out if the applications canvas_url is the
# start of the URL we are currently on. Once that has been established
# we also need to find out which canvas_url is longer to find out
# which is the closer match.
@kitsunde
kitsunde / gist:3665628
Created September 7, 2012 12:05
pytz working for Singapore
>>> import pytz
>>> from datetime import datetime
>>> time_zone = pytz.timezone('Asia/Singapore')
>>> my_time = datetime.utcnow()
>>> my_time
datetime.datetime(2012, 9, 7, 12, 6, 15, 56631)
>>> my_time.replace(tzinfo=pytz.utc)
datetime.datetime(2012, 9, 7, 12, 6, 15, 56631, tzinfo=<UTC>)
>>> my_time = my_time.replace(tzinfo=pytz.utc)
>>> my_time.astimezone(time_zone)
@kitsunde
kitsunde / gist:2901831
Created June 9, 2012 17:09
Getting all addresses for EC2's registered to an ELB
import boto
from boto import regioninfo
from boto import ec2
ACCESS_KEY_ID = '##'
SECRET_ACCESS_KEY = '##'
elb_region = boto.regioninfo.RegionInfo(
name='ap-southeast-1',
endpoint='elasticloadbalancing.ap-southeast-1.amazonaws.com')
@kitsunde
kitsunde / gist:2302593
Created April 4, 2012 15:19
Facbeook snippet
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/static/styles/reset.css">
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function () {
FB.init({
@kitsunde
kitsunde / gist:1862669
Created February 19, 2012 08:57
Singapore time on Facebook

There are [2 589 420 Facebook users in the Singapore][1]. They each spend 38 mins and 46 secs on Facebook per day making Singapore #1 in terms of time spent per user (Can't reference this off-hand).

United States has [155 701 780 users][2]. All the Facebook users from the US spend a total of [100,000 years on Facebook each month][3]. American users spend an average of 6 hours and 33 minutes on the social network each month.

Normalize:

38 mins and 46 secs user/day = 2326 seconds on Facebook user/day

Total for singapore:

@kitsunde
kitsunde / tabmigration.js
Created July 10, 2011 15:40
If we fail to change the dimensions of a chrome window we create a new one with the desired dimensions and migrate the tabs.
// Workaround for http://code.google.com/p/chromium/issues/detail?id=50138
chrome.windows.getCurrent(function(win){
var update = {height: 480, width: 320};
chrome.windows.update(win.id, update, function(win){
// If the window isn't the dimensions we set to it
// it means it's maximized and we'll create a new window.
if( win.height !== update.height && win.width !== update.width ){
chrome.tabs.getAllInWindow(win.id, function(tabs){
mysql -uroot -p -e"create database wp_dropbox"
ps -Af | grep apache2
convert source.png -resize 128x128 target.png
convert source.png -resize 400x275 -background "#ABCABC" -extent 400x275 target.png