Skip to content

Instantly share code, notes, and snippets.

;;; Problem solved, by subterfuge.
(defadvice rgrep (around rgrep-rename-previous-buffer activate compile)
"If a previous *grep* buffer exists, offer to rename it before
running the new process."
(interactive
(let ((old-grep-buf (get-buffer "*grep*")))
(if (and old-grep-buf
(y-or-n-p "Grep results buffer already exists; rename it first? "))
(let ((new-buf-name (read-string "New name: ")))
(with-current-buffer old-grep-buf
(defvar *mh/lisp-base* (file-name-directory (file-truename user-init-file))
"Base code directory; contains free-standing code and
subdirectories of other projects. Defaults to the directory
containing the user's initialisation file (including following
symlinks).")
(add-to-list 'load-path *mh/lisp-base*)
;;; site-specific customisations; for now, assume that this can be
;;; done by platform, since it's linux at work, OSX at home. Just
;;; name the file the same as is reported by system-type (#'load will
from django.conf import settings
from django.contrib.auth.models import User
import cx_Oracle
class OracleBackend(object):
"""Authenticate by attempting to establish an oracle connection.
Uses the database from the settings. The django user module is
still used for management, just not authentication."""
def authenticate(self, username=None, password=None):
try:
(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))))
// ==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,
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();
jQuery.fn.log = function (msg) {
console.log("%s: %o", msg, this);
return this;
};
// $('selector').log('BEGIN')
// .css('color', 'red')
// .log('new value')
// // etc
// 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');
// 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]);
}
}
@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();