Skip to content

Instantly share code, notes, and snippets.

@markhepburn
markhepburn / picasa-uploader.py
Created June 23, 2012 14:00
Script to automate uploading image directories to picasa albums
#!/usr/bin/env python
import ConfigParser
import os
import os.path as op
import gdata.photos.service
import gdata.media
import gdata.geo
@markhepburn
markhepburn / links.hs
Created May 22, 2012 12:34
Basic yesod app from the first few chapters, just for including in a post.
@markhepburn
markhepburn / mv-submodule.sh
Created January 14, 2012 13:26
Shell script to automate moving a git submodule
#!/bin/bash
# See for eg
# http://stackoverflow.com/questions/4526910/rename-a-git-submodule;
# an important point seems to be to avoiding the trailing '/' when
# calling 'add' in the new location.
# Also, note that the name ([submodule = "name"]) in the .gitmodules
# file can be anything; it's just used to map to the corresponding
# .git/config entry.
@markhepburn
markhepburn / lazy-loader.js
Created November 2, 2011 22:44
Yet another lazy script-loader, with callbacks managed using jQuery Deferred objects.
var $LL = (function($) {
var deferreds = {};
return function(s, c) {
if (s in deferreds) {
deferreds[s].done(function(){
c();
});
return;
}
deferreds[s] = $.Deferred();
// Clean up all those invasive and ugly utm_ parameters, so you can paste a url.
// (will reload the page, be warned)
(function(){
var qs = window.location.search.slice(1).split('&'),
newqs = [];
for (var i = 0; i < qs.length; i++) {
if (qs[i].slice(0,4)!='utm_') {
newqs.push(qs[i]);
}
}
// From here, with a few improvements (options classes argument, ability to pass plain text in):
// http://stackoverflow.com/questions/118241/calculate-text-width-with-javascript
(function($) {
$.textMetrics = function(el, classes) {
var h = 0, w = 0;
var div = document.createElement('div');
jQuery.fn.log = function (msg) {
console.log("%s: %o", msg, this);
return this;
};
// $('selector').log('BEGIN')
// .css('color', 'red')
// .log('new value')
// // etc
var re = /\d{6}/,
dt = re.exec(document.location.href)[0];
var m = dt.slice(0,2),
d = dt.slice(2,4),
y = dt.slice(4);
y = y.charAt(0)==='0' ? '20'+y : '19'+y;
dt = newDate(y, parseInt(m,10)-1, d);
dt.setDate(dt.getDay()===5 ? dt.getDate()+3 : dt.getDate()+2);
y = dt.getFullYear().toString().slice(2);
m = dt.getMonth(); m++; m = m.toString();
// ==UserScript==
// @name PhD Comics Keyboard Navigation
// @namespace http://www.everythingtastesbetterwithchilli.com
// @description Use arrow keys to navigate through the phdcomics archive.
// @include http://*phdcomics.com/comics/*
// ==/UserScript==
function findHrefForParentOf(xpth) {
var imgIterator = document.evaluate(
xpth,
(defadvice rec-fib (around rec-fib-memoize compile activate)
(let* ((memo-table (memo-table-for-symbol 'rec-fib))
(arg (ad-get-arg 0))
(result (gethash arg memo-table)))
(if result
(setq ad-return-value result)
ad-do-it
(puthash arg ad-return-value memo-table))))