Skip to content

Instantly share code, notes, and snippets.

View mjallday's full-sized avatar
🏠
WFH

Marshall Jones mjallday

🏠
WFH
View GitHub Profile
@mjallday
mjallday / gist:968039
Created May 12, 2011 06:24
Outbound link tracking in Google Analytics
<script type="text/javascript">
var ticketLink = 'http://tickets.kpop.sg';
$( function () {
$('a[href*="' + ticketLink + '"]').click ( function () {
_gat._getTrackerByName()._trackEvent('Outbound links', ticketLink);
setTimeout(function() { document.location = ticketLink; }, 100);
return false;
});
@mjallday
mjallday / digital_signature.py
Created June 10, 2011 04:27
Example of digital signature signing and verification
from M2Crypto import EVP, RSA, X509
import binascii
class C(object):
def __init__(self):
pass
def sign(self, message_to_encrypt):
key = EVP.load_key("mycert-private.pem")
@mjallday
mjallday / currencies.py
Created August 12, 2011 09:09
Tuple of currencies for Python
# -*- coding: utf-8 -*-
"""
list of currencies currently in circulation
taken from http://www.currency-iso.org/iso_index/iso_tables/iso_tables_a1.htm
http://www.iso.org/iso/currency_codes_list-1.html
2011-08-11
"""
for transaction in NewsletterTransaction.objects.filter(sent=None):
...
# to
while NewsletterTransaction.objects.filter(sent=None).count():
for transaction in NewletterTransaction.objects.filter(sent=None).limit(10):
...
# taking 10 at a time and then doing a new query. this way you're
@mjallday
mjallday / add-to-projects.sh
Created December 24, 2011 18:19
git pre-commit
#!/bin/bash
for f in crystal knox pound poundpay-python poundweb precog sterling
do
ln -s ~/code/poundpay/pre-commit $f/.git/hooks/pre-commit
done
@mjallday
mjallday / gist:1781622
Created February 9, 2012 18:01
unique eid across marketplace
@event.listens_for(Debit, 'before_insert')
def increment_balance(mapper, connection, debit):
eid = generate_eid('D')
result = 1
while result:
result = Debit.query.filter(
Debit.marketplace == debit.marketplace,
Debit.eid == eid
@mjallday
mjallday / watcher.py
Created March 8, 2012 17:36
File watcher in Python
#!/bin/python
"""
A simple directory watching script that will compute the checksum for all files
within a path and execute a change when the sum changes.
This will not work well with large files as it reads the entire file into
memory.
"""
import argparse
<html>
<head>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" type="text/css">
<style type="text/css">
code { display: block; }
pre { color: green; }
</style>
</head>
<body>
<h1>Balanced Sample - Collect Bank Account Information</h1>
import balanced
from django.conf import settings
class BalancedMiddleware(object):
def process_request(*_):
balanced.configure(settings.BALANCED['secret'])
@mjallday
mjallday / insufficent-funds.py
Created August 7, 2012 16:53
Insufficient funds
import balanced
api_key = balanced.APIKey().save()
balanced.configure(api_key.secret)
marketplace = balanced.Marketplace().save()
bank_account = balanced.BankAccount(
account_number="1234567890",
bank_code="12",