Skip to content

Instantly share code, notes, and snippets.

@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 / init.el
Created March 26, 2014 22:26
c311 .emacs settings -- including miniKanren stuffs
;;; .emacs (full version)
;;; A .emacs file for C311 students. To use this file, rename
;;; it to '.emacs' and place it in your home directory.
;;; [3 November 2004]
;;; Will Byrd created the initial version of this file from the
;;; simple .emacs file posted earlier. Portions of this file were
;;; were taken from Aziz Ghuloum's .emacs file.
@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

@jhrr
jhrr / cabal-sandbox.sh
Created April 20, 2014 13:45
Courtesy of Brian McKenna a zsh script to show the sandbox status of the current directory in our shell -- http://dev.stephendiehl.com/hask/
# a zsh script to show the sandbox status of the current directory in our shell.
function cabal_sandbox_info() {
cabal_files=(*.cabal(N))
if [ $#cabal_files -gt 0 ]; then
if [ -f cabal.sandbox.config ]; then
echo "%{$fg[green]%}sandboxed%{$reset_color%}"
else
echo "%{$fg[red]%}not sandboxed%{$reset_color%}"
fi

This is my recommended path for learning Haskell.

Something to keep in mind: don't sweat the stuff you don't understand immediately. Just keep moving.

Primary course

Installing Haskell

Ubuntu PPA