Skip to content

Instantly share code, notes, and snippets.

View ollieglass's full-sized avatar

Ollie Glass ollieglass

View GitHub Profile
@ollieglass
ollieglass / jqm_example.html
Created April 9, 2012 16:30
Pages and links with jQuery Mobile
<div data-role="page" id="first">
<div data-role="header">
<h1>Page Title1</h1>
</div><!-- /header -->
<div data-role="content">
<p>Page content goes here.</p>
<a href="#second">Go to second page</a>
</div><!-- /content -->
</div><!-- /page -->
@ollieglass
ollieglass / condiments.dot
Created April 9, 2012 16:39
Condiment graph
graph condiments {
ketchup -- mayonnaise -- tartar -- lemon
ketchup -- bbq
}
@ollieglass
ollieglass / imgur.py
Created May 19, 2012 21:15
oauth_hook, imgur and requests error
import requests
import urlparse
from oauth_hook import OAuthHook
# consumer key + secret
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
# get access token, create client
client = requests.session(
@ollieglass
ollieglass / vis.py
Created October 21, 2012 20:03
Simple network visualisation
import MySQLdb
db = MySQLdb.connect(host="localhost", port=3306, user="user", passwd="passwd", db="db")
cursor = db.cursor()
cursor.execute("SELECT id, referrer_id FROM users")
print "graph referrers {"
for row in cursor.fetchall():
print "%s -- %s" % (row[0], row[1])
@ollieglass
ollieglass / FizzBuzz.java
Created December 2, 2012 14:26
Pythonic Java FizzBuzz
/* Write a program that prints the numbers from 1 to 100.
But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”.
For numbers which are multiples of both three and five print “FizzBuzz”.
Pythonic Java - https://gist.github.com/1725650
*/
public class FizzBuzz {
public static void main(String[] args) {
@ollieglass
ollieglass / Object model.py
Last active December 11, 2015 23:38
Transaction, Merchant and Category object model from my personal finance mini-hackathon http://ollieglass.com/2013/01/30/personal-finance-mini-hackathon
class Category(models.Model):
name = models.CharField(max_length=255)
class Merchant(models.Model):
name = models.CharField(max_length=255)
category = models.ForeignKey(Category, blank=True, null=True, db_index=True)
class Transaction(models.Model):
@ollieglass
ollieglass / Capital One credit card CSV importer.py
Last active December 11, 2015 23:38
Capital One credit card CSV importer from my personal finance mini-hackathon http://ollieglass.com/2013/01/30/personal-finance-mini-hackathon
for filename in os.listdir(path):
reader = csv.reader(open(path + filename), dialect=csv.excel)
headers = reader.next()
for row in reader:
m, created = Merchant.objects.get_or_create(name=row[3])
# lose the £ symbol and minus sign, cast to float
@ollieglass
ollieglass / Django view for categorising credit card transactions
Created January 30, 2013 22:56
Django view for categorising credit card transactions, from my personal finance mini-hackathon http://ollieglass.com/2013/01/30/personal-finance-mini-hackathon
{% loop through transactions... %}
<td>
{% if not transaction.merchant.category %}
<select data-value="{{ transaction.id }}">
<option value="-1">Not set</option>
{% for category in categories %}
<option value="{{ category.id }}">{{ category.name }}</option>
{% endfor %}
</select>
@ollieglass
ollieglass / AJAX helper for categorising credit card transactions.js
Last active December 11, 2015 23:38
AJAX helper for categorising credit card transactions, from my personal finance mini-hackathon http://ollieglass.com/2013/01/30/personal-finance-mini-hackathon
var setCategory = function(transactionId, categoryId) {
$.ajax({
type: "GET",
url: "/transaction/",
data: {
transactionId: transactionId,
categoryId: categoryId
}
}).done(function( msg ) {
console.log(msg);
@ollieglass
ollieglass / AJAX helper function for storing credit card transaction categories.py
Last active December 11, 2015 23:39
AJAX helper function for storing credit card transaction categories, from my personal finance mini-hackathon http://ollieglass.com/2013/01/30/personal-finance-mini-hackathon
def transaction(request):
transaction_id = request.REQUEST.get('transactionId')
category_id = request.REQUEST.get('categoryId')
t = Transaction.objects.get(pk=transaction_id)
m = t.merchant
c = Category.objects.get(pk=category_id)
m.category = c
m.save()