Skip to content

Instantly share code, notes, and snippets.

View nicferrier's full-sized avatar

Nic Ferrier nicferrier

View GitHub Profile
@nicferrier
nicferrier / org-mode table with formula
Created November 29, 2011 11:24
org-mode table with a formula
| Date | Amount | Description |
|------------+------------------------+-------------------|
| 2011-11-15 | 100.00 | Big client dinner |
| 2011-11-18 | 15.00 | Screen cleaner |
| 2011-11-21 | 110 | London ticket |
|------------+------------------------+-------------------|
| | VSUM([100., 15., 110]) | |
#+TBLFM: @5$2=VSUM(@I..@II)
@nicferrier
nicferrier / gist:1411311
Created November 30, 2011 22:14
using a pipe mill just for splitting args
# An example of using a pipemill just to split words
args="~/somedir ssh://host/remote"
echo $args | while read local remote
do
something $local $remote
done
@nicferrier
nicferrier / gist:1423429
Created December 2, 2011 14:32
nginx user directory serving
# If you only need a few users this is ideal, alter the nferrier part to be regex or:
#
# (nferrier|jsmith|dharry)
#
# If you need any user then use ([A-Za-z0-9-]+) in the regex and use an if to check:
#
# if (! -d /home/$1/public_html) {
# return 403;
# }
#
@nicferrier
nicferrier / gist:1446902
Created December 8, 2011 12:49
lexical binding strangeness
;; test
(setq lexical-binding t)
(defun nic-test-1 (alist-symbol)
(symbol-value 'alist-symbol))
(let ((x 10))
(nic-test-1 x))
@nicferrier
nicferrier / gist:1490301
Created December 17, 2011 14:13
decorating dynamically bound functions lexically without advice
(setq lexical-binding t)
(defun nic-test-1 (x)
(message "base nic test %s" x))
(let ((old-nic-test-1 (symbol-function 'nic-test-1))
(z 10))
(flet ((nic-test-1
(y)
(funcall old-nic-test-1 y)
@nicferrier
nicferrier / flatten.xslt
Created January 24, 2012 21:08
flatten
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
xmlns:re="http://exslt.org/regular-expressions"
extension-element-prefixes="str regexp"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output mode="text" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="//table//tr" mode="variables">
@nicferrier
nicferrier / gist:1853796
Created February 17, 2012 14:30
hack vagrant files to use private keys
#!/bin/bash
# Force a vagrant config to use my private key pair
case $1 in
help|-h|--help)
cat <<EOF
vagrant-privatekey [Vagrantfile] [private key file]
changes the Vagrantfile (or ./Vagrantfile) to use the private-key-file (or
@nicferrier
nicferrier / gist:1895385
Created February 23, 2012 22:28
child process lisps for fun and profit
(defun nic-child-lisp-hook (child-lisp)
;; version of a hook function which wraps child-lisp
`((flet ((my-func (x) (message "hello!")))
,@child-lisp)))
(defun nic-child-lisp-hook (child-lisp)
;; version of a hook function which just returns child-lisp for
;; interpolation
child-lisp)
@nicferrier
nicferrier / gist:1900476
Created February 24, 2012 11:48
elnode's mock process macro
(defmacro elnode--mock-process (process-bindings &rest body)
"Allow easier elnode testing by mocking the process functions.
For example:
(elnode--mock-process (:elnode-http-params
(:elnode-http-method \"GET\")
(:elnode-http-query \"a=10\"))
(should (equal 10 (elnode-http-param 't \"a\")))
)
@nicferrier
nicferrier / gist:1900499
Created February 24, 2012 11:49
test exercising mock-process
(ert-deftest elnode--http-parse-body-incomplete ()
"Tests the HTTP parsing of an incomplete body.
An HTTP request with an incomplete body is setup and tested, then
we finish the request (fill out the content to content-length)
and then test again."
(elnode--mock-process
((:buffer
(elnode--http-make-hdr
'get "/"