Skip to content

Instantly share code, notes, and snippets.

@jhrr
jhrr / preLoadImages.js
Last active August 29, 2015 13:56
JQuery image preloader that should work correctly with the hashing mechanism from django-compressor.
function preLoadImages () {
$.get($('link[rel="stylesheet"]')[0].href, function(data){
r = /url\(['|"]?(\S+\.(gif|jpg|jpeg|png)[^'(]*)['|"]?\)/ig;
while (match = r.exec(data)){
var cacheImage = document.createElement('img');
cacheImage.src = match[1];
}
});
}
preLoadImages();
@jhrr
jhrr / Non-$HOME .emacs.d
Created February 14, 2014 14:38
Locating your .emacs.d somewhere other than ~/
(setq user-emacs-directory (expand-file-name "~/Dropbox/path/to/.emacs.d/"))
(load (locate-user-emacs-file "init.el"))
@jhrr
jhrr / json_functions.py
Created February 14, 2014 18:10
JSON utilities for django
from django.db import models
from django.utils.functional import Promise
from django.utils.encoding import force_unicode
from django.utils import simplejson as json
from decimal import Decimal
from django.core import serializers
from django.conf import settings
from django.http import HttpResponse, HttpResponseForbidden, Http404
from django.core.mail import mail_admins
from django.db.models.query import QuerySet
@jhrr
jhrr / Backbone.sync_csrftoken.js
Created February 16, 2014 13:05
Embed the CSRF token in a meta tag in the HTML header, and to modify Sync to take the token from the DOM and add it to the AJAX request's HTTP headers. From: http://ozkatz.github.io/backbonejs-with-django-15.html
var oldSync = Backbone.sync;
Backbone.sync = function(method, model, options){
options.beforeSend = function(xhr){
xhr.setRequestHeader('X-CSRFToken', CSRF_TOKEN);
};
return oldSync(method, model, options);
};
function doPopups() {
if (document.getElementsByTagName) {
var links = document.getElementsByTagName("a");
for (var i=0; i < links.length; i++) {
if (links[i].className.match("help")) {
links[i].onclick = function() {
window.open(this.getAttribute("href"));
return false;
};
}
@jhrr
jhrr / setup-slime-js.el
Last active August 29, 2015 13:56
Configuration for slime/swank.js
;;; slime-js.el -- Set up slime-js
;;
;;; Commentary:
;;
;; To install, see https://github.com/swank-js/swank-js/wiki/Installation
;;
;; This is what I did:
;;
;; npm install swank-js -g
;; M-x package-install slime-js
;; emacsd-tile.el -- tiling windows for emacs
(defun swap-with (dir)
(interactive)
(let ((other-window (windmove-find-other-window dir)))
(when other-window
(let* ((this-window (selected-window))
(this-buffer (window-buffer this-window))
(other-buffer (window-buffer other-window))
(this-start (window-start this-window))
@jhrr
jhrr / make-cstack.lisp
Created March 4, 2014 18:48
SBCL exports a symbol sb-ext:compare-and-swap, which can be used to do small-scale transactional tricks, and is often an order of magnitude faster than the equivalent locking solution. Here is a very simple concurrency-safe stack. The macro is a convenient wrapper that helps use compare-and-swap in a 'transactional' way. http://marijnhaverbeke.n…
(defmacro concurrent-update (place var &body body)
`(flet ((action (,var) ,@body))
(let ((prev ,place))
(loop :until (eq (sb-ext:compare-and-swap ,place prev (action prev)) prev)
:do (setf prev ,place))
prev)))
(defun make-cstack (&rest elements)
(cons :stack elements))
(defun push-cstack (element stack)
@jhrr
jhrr / ers.sh
Created March 27, 2014 15:11
some functions for safely killing and restarting the emacs daemon
server_ok() {
emacsclient -a "false" -e "(boundp 'server-process)"
}
function ek {
if [ "t" == "$(server_ok)" ]; then
echo "Shutting down Emacs server"
emacsclient -e '(kill-emacs)'
else
echo "Emacs server not running"

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results