Skip to content

Instantly share code, notes, and snippets.

View takinbo's full-sized avatar

Tim Akinbo takinbo

View GitHub Profile
@takinbo
takinbo / shorty.py
Created February 19, 2012 17:57
url shortening snippet
import string
import sys
# list of valid characters to use in the shortener slug
CHARSET = string.digits + string.lowercase + string.uppercase
# convert a numeric id to a url-shortener-type slug
def shorty(id):
slug = ""
while id > 0:
@takinbo
takinbo / network_operator_function.sql
Created February 17, 2012 09:57
PostgreSQL function to determine network prefix from a phone number
CREATE OR REPLACE FUNCTION network_operator(msisdn text)
RETURNS text AS
$$
DECLARE
operator TEXT;
BEGIN
IF msisdn ~ '^(0|234)(703|706|803|806|810|813|816)\\d+$' THEN
operator := 'MTN';
ELSEIF msisdn ~ '^(0|234)(705|805|807|815)\\d+$' THEN
operator := 'GLO';
@takinbo
takinbo / paginated_collection.js
Created July 25, 2011 21:57 — forked from io41/paginated_collection.js
Pagination with Backbone.js & django-tastypie
// includes bindings for fetching/fetched
var PaginatedCollection = Backbone.Collection.extend({
initialize: function() {
_.bindAll(this, 'parse', 'url', 'pageInfo', 'nextPage', 'previousPage', 'filtrate', 'sort_by');
typeof(options) != 'undefined' || (options = {});
typeof(this.limit) != 'undefined' || (this.limit = 20);
typeof(this.offset) != 'undefined' || (this.offset = 0);
typeof(this.filter_options) != 'undefined' || (this.filter_options = {});
typeof(this.sort_field) != 'undefined' || (this.sort_field = '');
@takinbo
takinbo / gist:669561
Created November 9, 2010 18:42
generic wsgi file for wsgi-based django app deployments
import os, sys
import django.core.handlers.wsgi
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
application = django.core.handlers.wsgi.WSGIHandler()
# FizzBuzz
# ----------------------------------------------------------------------------
# in response to Pascal Ehigie Aito's blog post
# http://aitoehigie.wordpress.com/2010/10/24/most-programmers-cant-solve-this/
# here's an attempt to solve it
for i in range(1, 101):
if not (i % 3 or i % 5):
print "FizzBuzz"
elif not i % 3:
print "Fizz"
from boss import BossFactory
from sys import argv
import yaml
config = yaml.load(file('config.yml', 'rb').read())
boss = BossFactory(appid=config['yahookey'])
offset = 0
done = False
urls = []
#!/bin/sh
# uses Google's Closure Compiler - http://code.google.com/p/closure-compiler/
test -e $1 && java -jar /path/to/compiler.jar --js $1 --js_output_file `basename $1 .js`.min.js
#!/bin/sh
#----------------------------------------------+
# If you happen to do BlackBerry Application |
# development with PhoneGap on Linux, this |
# utility will come in handy. It automates |
# copying the phonegap library files to your |
# BlackBerry project. This should should be |
# copied to your extracted phonegap-blackberry |
# directory. |
@takinbo
takinbo / post.py
Created July 21, 2010 18:05
Scraping script for Nigeriapostcodes.com
#!/usr/bin/env python
import sys
import re
from datetime import datetime
import csv
from BeautifulSoup import BeautifulSoup
import urllib2
from urllib import urlencode
from time import sleep
#! /bin/sh
### BEGIN INIT INFO
# Provides: mongodb
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the mongodb data-store
# Description: starts mongodb using start-stop-daemon