Skip to content

Instantly share code, notes, and snippets.

View d11wtq's full-sized avatar

Chris Corbyn d11wtq

  • Melbourne, Australia
View GitHub Profile
@d11wtq
d11wtq / docker-ssh-forward.bash
Created January 29, 2014 23:32
How to SSH agent forward into a docker container
docker run -rm -t -i -v $(dirname $SSH_AUTH_SOCK) -e SSH_AUTH_SOCK=$SSH_AUTH_SOCK ubuntu /bin/bash
@d11wtq
d11wtq / deliver_email_job.rb
Created August 28, 2011 04:14
Customizing ActionMailer delivery methods
# Resque job to do the true outbound sending
class DeliverEmailJob
include ProjectName::Job::Logging
@queue = :mail_queue
def self.perform(args)
message = QueuedEmail.get!(args["message_id"])
logger.info("Delivering (%s) to %s" % [message.subject, message.formatted_recipient])
@d11wtq
d11wtq / binary_tree.erl
Created March 21, 2013 12:35
Binary tree implementation in Erlang.
%% @doc A binary tree implementation in Erlang.
%% A binary tree stores keys and values.
-module(binary_tree).
-export([init/0, init/1, insert/3, lookup/2]).
-define(EMPTY_NODE, {node, 'empty'}).
%% @doc Initialize an empty binary tree node.
%% This is how the root of the tree should be established.
%%
@d11wtq
d11wtq / enum.sql
Created October 26, 2012 10:07
Renaming an ENUM label in PostgreSQL
/*
Assuming you have an enum type like this.
You want to rename 'pending' to 'lodged'
*/
CREATE TYPE dispute_status AS ENUM('pending', 'resolved', 'open', 'cancelled');
BEGIN;
ALTER TYPE dispute_status ADD VALUE 'lodged';
UPDATE dispute SET status = 'lodged' WHERE status = 'pending';
@d11wtq
d11wtq / let.js
Created August 18, 2012 05:54
RSpec style let() in Jasmine/Mocha
/**
* Get RSpec-style let() in your Mocha/Jasmine specs.
*/
var let = function (callback) {
var value, called = false;
var memoizer = function() {
if (called) {
return value;
} else {
called = true;
@d11wtq
d11wtq / schedule.clj
Last active January 4, 2016 08:19
Seeking DSL style review
(defschedule app-schedule "Application tasks"
[:every "5 seconds" (println "Woohoo!")]
[:at "7am tomorrow" (wake-up!)])
@d11wtq
d11wtq / thread-macro.clj
Created December 13, 2013 10:56
Demonstration implementation of the `->` macro in Clojure.
(defmacro demo-> [val & fns]
(reduce (fn [acc fname] (list fname acc)) val fns))
(macroexpand '(demo-> 42 inc dec inc)) ; (inc (dec (inc 42)))
@d11wtq
d11wtq / inc-number.el
Created June 22, 2013 07:13
Vim-style increment/decrement numbers under the cursor, for Emacs.
;; vim-style increment/decrement numbers
(defun inc-number-at-point (n)
"Increment the number under the point, if present.
Called with a prefix argument, changes the number by N."
(interactive "p")
(let ((amt (or n 1))
(word (thing-at-point 'word))
(bounds (bounds-of-thing-at-point 'word)))
(when (string-match "^[0-9]+$" word)
(replace-string word
(defun colorize-mode-line (&rest args)
(let ((color (cond ((evil-insert-state-p) "#fa4444")
((evil-emacs-state-p) "#fafa00")
((buffer-modified-p) "#22bff0"))))
(set-face-background 'mode-line (or color "#ffffff"))))
(add-to-list 'post-command-hook 'colorize-mode-line)
@d11wtq
d11wtq / queries.md
Last active December 16, 2015 09:29
SQL vs ORM vs QLCs

Comparing the power and expressiveness of various database query systems

Simple select all.

SELECT * FROM users;
User.all