Skip to content

Instantly share code, notes, and snippets.

View natbat's full-sized avatar

Natalie Downe natbat

View GitHub Profile
@natbat
natbat / gist:4109493
Created November 19, 2012 07:51
18th November 2012 hamster.log
Revolutions: 1 (time = 1353270795.1)
Revolutions: 2 (time = 1353270820.32)
Revolutions: 3 (time = 1353275042.99)
Revolutions: 4 (time = 1353275045.56)
Revolutions: 5 (time = 1353275051.18)
Revolutions: 6 (time = 1353275057.6)
Revolutions: 7 (time = 1353275063.12)
Revolutions: 1 (time = 1353275203.54)
Revolutions: 2 (time = 1353275959.26)
Revolutions: 3 (time = 1353275962.48)
@natbat
natbat / Django nice times
Created April 10, 2012 13:45
9am to 9:30am in django templating
{{ session.start_time|date:"g" }}{% with session.start_time|date:"i" as mm %}{% if mm != "00" %}{{ session.start_time|date:":i" }}{% endif %}{% endwith %}{{ session.start_time|date:"A"|lower }}
@natbat
natbat / Mailto
Created January 18, 2012 15:29
Mailto formatting
mailto:jsmith@example.com?subject=A%20Test&body=My%20idea%20is%3A%20%0A
@natbat
natbat / Pluralize
Created January 18, 2012 15:12
pluralize in django to be two words
{{ group.adverts|length|pluralize:"this,these" }}
@natbat
natbat / TimeSince.php
Created November 10, 2011 10:39
Works out the time since, takes a an argument in unix time (seconds)
function time_since($original) {
// array of time period chunks
$chunks = array(
array(60 * 60 * 24 * 365 , 'year'),
array(60 * 60 * 24 * 30 , 'month'),
array(60 * 60 * 24 * 7, 'week'),
array(60 * 60 * 24 , 'day'),
array(60 * 60 , 'hour'),
array(60 , 'minute'),
);
warning = false;
window.onbeforeunload = function() {
if (warning) {
return 'You have made changes on this page that you have not yet confirmed. If you navigate away from this page you will loose your unsaved changes';
}
}
if ((location.href.split('?')[1] || '').indexOf('print') > -1) {
/* assuming all other stylesheets are on media all, this means you can use the ?print query string to preview print styles */
$('link[media=print]').attr('media', '');
}
<!--[if lte IE 6]><![if gte IE 7]><![endif]-->
<!-- This is a bit mad, but code inside here is served to everything except browsers less than IE7 -->
<!--[if lte IE 6]><![endif]><![endif]-->
function wait(millis) {
var date = new Date();
var curDate = null;
do {
curDate = new Date();
} while(curDate-date < millis);
var date = null;
var curDate = null;