Skip to content

Instantly share code, notes, and snippets.

View ollieglass's full-sized avatar

Ollie Glass ollieglass

View GitHub Profile
@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 / CSV export function.py
Last active December 11, 2015 23:39
CSV export function from my personal finance mini-hackathon http://ollieglass.com/2013/01/30/personal-finance-mini-hackathon
def weeks(self):
final_date = Transaction.objects.all().order_by('-transaction_date')[0].transaction_date
start_date = Transaction.objects.all().order_by('transaction_date')[0].transaction_date
end_date = start_date + datetime.timedelta(weeks=1)
while end_date <= final_date:
yield start_date, end_date
start_date += datetime.timedelta(weeks=1)
@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()
@ollieglass
ollieglass / topsy_tabs.py
Created February 2, 2013 13:22
Open Topsy reports for your last ten Wordpress blog posts. Details at http://ollieglass.com/2013/02/01/topsy-tracker-whos-tweeting-about-your-blog-posts/
import webbrowser
import xmlrpclib
# get posts from wordpress
server = xmlrpclib.ServerProxy('http://ollieglass.com/xmlrpc.php')
result = server.metaWeblog.getRecentPosts('WORDPRESS_BLOG_NAME', 'WORDPRESS_USERNAME', 'WORDPRESS_PASSWORD', 10)
urls = [post['link'] for post in result]
# change into topsy searches
urls = [url.replace('http://', 'http://topsy.com/') for url in urls]
@ollieglass
ollieglass / macros.py
Created April 10, 2013 16:46
Macros for Django - this snippet, with unused imports removed http://djangosnippets.org/snippets/363/
#
# templatetags/macros.py - Support for macros in Django templates
#
# Author: Michal Ludvig <michal@logix.cz>
# http://www.logix.cz/michal
#
"""
Tag library that provides support for "macros" in
Django templates.
@ollieglass
ollieglass / jsbin.EguNoVI.html
Created October 17, 2013 22:20
Bulk find or create with ember.js This would be simple to do synchronously (foreach... continue if exists). But working with the asynchronous store creates lots of overhead.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<script src="http://code.jquery.com/jquery-2.0.2.js"></script>
<script src="http://builds.emberjs.com/handlebars-1.0.0.js"></script>
<script src="http://builds.emberjs.com/ember-latest.js"></script>
<script src="http://builds.emberjs.com/beta/ember-data.js"></script>
<script src="https://rawgithub.com/rpflorence/ember-localstorage-adapter/master/localstorage_adapter.js"></script>
@ollieglass
ollieglass / twitter_search_summary.js
Created December 10, 2013 11:14
Twitter search summary. 1. search Twitter for something 2. dismiss the promoted Tweet 3. scroll down, and keep scrolling until you've loaded all the tweets 4. open your JavaScript console (alt + cmd + I in Chrome) 5. paste the code below into the console, press enter to run 6. voila. A summary appears at the top of the search results
$(".header-inner").append(
"<h2>Who's shared your links?</h2>"
+ $.map($(".details"), function (x) { return('<a href="' + $(x).attr('href') + '>@' + $(x).attr('href').split("/")[1] + '</a>') } ).join("<br>")
)
@ollieglass
ollieglass / python
Created November 8, 2016 23:51
Increase open file limit
import platform
if platform.system() == 'Windows':
import win32file
win32file._setmaxstdio(2048)
@ollieglass
ollieglass / artsy.css
Created January 21, 2021 15:56
Custom stylesheet for artsy.net
[class^="Lightbox__DeepZoomContainer"] > [class^="Box-sc"] {
display:none;
}
header {
display:none;
}
@ollieglass
ollieglass / gist:d1f5a6766544e9d3f42dc44c8c331aef
Created August 15, 2018 21:22
Sainsbury's Bank Credit Card transaction view to CSV (almost)
$('tr.no-transaction-details.card').each(function(i, e) {
var $e = $(e);
var s = [$e.find("td[data-coltype='date']").text(),
$.trim( $e.find("td[data-coltype='description']").text() ),
$.trim( $e.find("td[data-coltype='amount']").text() )
];
s = s.join(',');
console.log(s);
})