Skip to content

Instantly share code, notes, and snippets.

from hado.models import *
import datetime
f = open("prepayments.csv", "w+")
import csv
ppcsv = csv.DictWriter(f, ["user", "email", "balance"])
ppcsv.writeheader()
total = 0
users = User.objects.all().order_by('first_name')
for u in users:
for c in u.contracts.exclude(start__gte=datetime.date(2010, 10, 1)):
@ruiwen
ruiwen / fb-angular.js
Last active July 5, 2017 10:40
Wrapping and initialising the Facebook SDK with Angular JS
// Facebook SDK
angular.module('facebook', [])
.directive('fb', ['$FB', function($FB) {
return {
restrict: "E",
replace: true,
template: "<div id='fb-root'></div>",
compile: function(tElem, tAttrs) {
return {
post: function(scope, iElem, iAttrs, controller) {
// ActivityTypes
Transaction.I_OWE = 0;
Transaction.OWES_ME = 1;
Transaction.I_PAID = 2;
Transaction.PAID_ME = 3;
Transaction.VOID = 4;
Transaction.WELCOME = 5;
// Transaction types as strings
Transaction.types = ["I owe", "owes me", "I paid", "paid me"];
@ruiwen
ruiwen / .gitconfig
Last active December 18, 2015 16:29
Recommended git configs
# Stick this in your repo's .git/config
# OR ~/.gitconfig
#
# Also,
# $ sudo apt-get install bash-completion
# for autocompletion goodness
[color]
ui = always
[alias]
# Borrowed from http://stackoverflow.com/a/2527623/149468
class objectJSONEncoder(json.JSONEncoder):
"""A specialized JSON encoder that can handle simple lxml objectify types
>>> from lxml import objectify
>>> obj = objectify.fromstring("<Book><price>1.50</price><author>W. Shakespeare</author></Book>")
>>> objectJSONEncoder().encode(obj)
'{"price": 1.5, "author": "W. Shakespeare"}'
"""
def default(self,o):
@ruiwen
ruiwen / whatshappening.py
Created July 2, 2013 11:24
A scraper for WhatsHappening.sg
# -*- coding: utf-8 -*-
#!/bin/python
# RSS feed parser/scraper for WhatsHappening.sg
import urllib2
import csv
import re
import cStringIO
import codecs
@ruiwen
ruiwen / gist:5908551
Created July 2, 2013 11:29
Unicode DictWriter
# Unicode DictWriter object
# http://stackoverflow.com/a/5838817
class DictUnicodeWriter(object):
def __init__(self, f, fieldnames, dialect=csv.excel, encoding="utf-8", **kwds):
# Redirect output to a queue
self.queue = cStringIO.StringIO()
self.writer = csv.DictWriter(self.queue, fieldnames, dialect=dialect, **kwds)
self.stream = f
self.encoder = codecs.getincrementalencoder(encoding)()
@ruiwen
ruiwen / s3selfsigned.py
Last active December 19, 2015 14:59
Self Signed S3 REST API Request
import boto
import os
import base64
import hashlib
import requests
import datetime
import hmac
@ruiwen
ruiwen / s3selfsignedPOST.py
Last active December 19, 2015 14:59
Self Signed S3 REST API Using POST
import boto
import os
import json
import base64
import hashlib
import requests
import datetime
import hmac
import pytz
import boto
import os
import json
import base64
import hashlib
import requests
import datetime
import hmac
import pytz