Skip to content

Instantly share code, notes, and snippets.

Avatar

Natalie Downe natbat

View GitHub Profile
@natbat
natbat / gist:4109493
Created Nov 19, 2012
18th November 2012 hamster.log
View gist:4109493
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 Apr 10, 2012
9am to 9:30am in django templating
View Django nice times
{{ 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 Jan 18, 2012
Mailto formatting
View Mailto
mailto:jsmith@example.com?subject=A%20Test&body=My%20idea%20is%3A%20%0A
@natbat
natbat / Pluralize
Created Jan 18, 2012
pluralize in django to be two words
View Pluralize
{{ group.adverts|length|pluralize:"this,these" }}
@natbat
natbat / TimeSince.php
Created Nov 10, 2011
Works out the time since, takes a an argument in unix time (seconds)
View TimeSince.php
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'),
);
View On unload notification
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';
}
}
View Print styles preview
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', '');
}
View Print footer
View downlevel reveal conditional comment
<!--[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]-->
View Javascript wait function
function wait(millis) {
var date = new Date();
var curDate = null;
do {
curDate = new Date();
} while(curDate-date < millis);
var date = null;
var curDate = null;