Skip to content

Instantly share code, notes, and snippets.

# In-memory Cassandra-ish thingy... useful for unit tests. Maybe useful for other
# stuff too? No support for SuperColumns, but that should be easy enough to add.
import bisect
import copy
from cassandra.ttypes import NotFoundException, Column, ColumnPath, ColumnOrSuperColumn
class SSTable(object):
@jhrr
jhrr / Functional Core, Imperative Shell
Last active January 8, 2018 16:11
Notes and links for ideas about Gary Bernhardt's "functional core, imperative shell"
http://www.infoq.com/presentations/Simple-Made-Easy
http://www.infoq.com/presentations/integration-tests-scam
http://blog.thecodewhisperer.com/2010/09/14/when-is-it-safe-to-introduce-test-doubles
http://youtu.be/yTkzNHF6rMs
http://pyvideo.org/video/1670/boundaries
http://skillsmatter.com/podcast/ajax-ria/enumerators
http://alistair.cockburn.us/Hexagonal+architecture
http://c2.com/cgi/wiki?PortsAndAdaptersArchitecture
http://www.confreaks.com/videos/977-goruco2012-hexagonal-rails
http://www.confreaks.com/videos/1255-rockymtnruby2012-to-mock-or-not-to-mock
@jhrr
jhrr / map-filter-fold.rkt
Last active December 27, 2015 18:19
A bunch of implementations for map, filter and fold in Racket
;; map
;; simple definition
(define (map/simple f lst)
(if (empty? lst) empty
(cons (f (first lst))
(map/simple f (rest lst)))))
(map/simple (λ (x) (* 2 x)) '(1 2 3 4))
(* map *)
fun map(_, nil) = nil
| map(f, (head::tail)) = f(head) :: map(f, tail)
(* filter *)
fun filter(_, nil) = nil
| filter(p, (head::tail)) = if p(head)
then (head :: filter(p, tail))
#lang racket
(require (for-syntax racket/syntax))
(require rackunit)
;; Macro for auto-writing tests with defines.
;; Syntax:
;; (define+test (function-name parameters ...)
;; ((test-input desired-result)
;; ...)
#!/bin/bash
#
# DESCRIPTION:
#
# Set the bash prompt according to:
# * the branch/status of the current git repository
# * the branch of the current subversion repository
# * the return value of the previous command
#
# USAGE:
@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 / OSX-fixes.el
Last active January 6, 2024 07:25
Make sure emacsen in a graphical frame running on OSX have the correct path and that the hash key (alt-3) is working.
;; Detect OS
(defvar macosx-p (string-match "darwin" (symbol-name system-type)))
;; osx fixes
(defun insert-hash ()
(interactive)
(insert "#"))
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell
@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