This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Utility classes | |
class UtilMixIn(): | |
def __json_render_field(self, f, only_fields=[], mapped_fields={}): | |
field = self._meta.get_field_by_name(f)[0] | |
if isinstance(field, models.fields.DateTimeField): | |
return time.mktime(getattr(self, f).timetuple()) | |
elif isinstance(field, models.fields.related.ForeignKey): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Various utility functions | |
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden | |
from django.template import RequestContext, Context, loader | |
from django.conf import settings | |
from django.contrib.auth.forms import AuthenticationForm | |
from django.contrib.auth import authenticate, login as django_login | |
from django.db import models | |
import json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* Neuters console.log, and makes its output dependent on the global boolean DEBUG | |
* | |
**/ | |
window.DEBUG = false; | |
window.console._log = window.console.log; // Make sure we have a pointer to the original function | |
window.console.log = function(str) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if we're root | |
if [ 0 -ne `id -u` ]; then | |
id -u | |
echo "This script needs to be run as root. Exiting." | |
exit 1 | |
fi | |
# Add uwsgi and nginx repositories |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flatten_dict(self, dct): | |
out = {} | |
for field in dct.keys(): | |
fk = self.model._meta.get_field(field) | |
if isinstance(fk, ForeignKey): | |
# Determine the target model of the ForeignKey | |
Klass = fk.rel.to().__class__ | |
d = { Klass._meta.pk.name : dct[field] } | |
# Grab the instance | |
i = Klass.objects.get(**d) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
File: KeychainItemWrapper.h | |
Abstract: | |
Objective-C wrapper for accessing a single keychain item. | |
Version: 1.2 - ARCified | |
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple | |
Inc. ("Apple") in consideration of your agreement to the following | |
terms, and your use, installation, modification or redistribution of |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// RCDirectionalPanRecognizer.h | |
// | |
// Created by Ruiwen Chua on 6/23/12. | |
// Copyright (c) 2012 thoughtmonkeys. | |
// | |
// Reference taken from http://stackoverflow.com/a/7149691 | |
#import <UIKit/UIKit.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From http://stackoverflow.com/a/1685337 | |
from __future__ import with_statement | |
import time | |
class Timer(object): | |
def __init__(self, autoprint=False): | |
self.autoprint = autoprint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Sample object: | |
{ | |
"url": "/1/functions/Klass3", | |
"_id": { | |
"$oid": "506c082701d5410ec7000002" | |
}, | |
"log": [ | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function recordTransaction(txn) { | |
// NON FUNCTIONING CODE | |
// Let 'friend' be the User's friend, the 'other' party in this Activity/Transaction | |
// Record the origin | |
var origin = friend.balance; | |
// Calculate friend balance | |
if(role == Activity.CREDITOR) { |
OlderNewer