Skip to content

Instantly share code, notes, and snippets.

View spacebat's full-sized avatar

Andy Kirkpatrick spacebat

  • Adelaide, South Australia
View GitHub Profile
@spacebat
spacebat / uncurry.lisp
Last active September 27, 2016 07:41
Curry with uncurry in common lisp
(defvar *uncurry* nil "When bound and non-nil, curried functions can be uncurried")
(makunbound '*uncurry*)
(defun curry (function &rest args)
(lambda (&rest more-args)
(if (and (boundp '*uncurry*) *uncurry*)
(if more-args
(error "No more args expected")
function)
(apply function (append args more-args)))))
@spacebat
spacebat / system.el
Last active August 29, 2015 14:06 — forked from intinig/system.el
(defun source-env-get (script &rest vars)
"Source script in shell, then look for vars in the resulting subshell environment"
(loop for line in (split-string (shell-command-to-string (concat "source " script " && set")) "[\n]" t)
with result
if (string-match "^\\([[:alpha:]]+\\)=\\(.*\\)$" line)
do (let ((var (match-string 1 line))
(val (match-string 2 line)))
(when (or (not vars) (member var vars))
(push (cons var val) result)))
finally return result))
;;; The macro:
(defmacro add-hook-one-time (hook function)
"Add FUNCTION to HOOK. Remove it after its first execution."
(let ((wrapper-function (make-symbol "wrapper-function-symbol")))
`(progn
(defun ,wrapper-function ()
"Wrapper function that will be executed only once, and then removed from the hook."
(funcall ,function)
(remove-hook ,hook ',wrapper-function))
(add-hook ,hook ',wrapper-function))))
@spacebat
spacebat / *scratch*.el
Last active December 15, 2015 14:19 — forked from nicferrier/*scratch*.el
I think the [^[] was making the start-of-line/string optional
(let ((regex
(rx
(or bol bos)
(? (not (any "[")))
(group
(>= 2 (and (any "A-Z")(one-or-more (any "a-z")))))))
case-fold-search)
(list
(replace-regexp-in-string regex "{\\1}" "[OneWordOrMore]")
(replace-regexp-in-string regex "{\\1}" "Onewordormore")
(let ((regex
(rx
(or bol bos (not (any "[")))
(group
(>= 2 (and (any "A-Z")(one-or-more (any "a-z"))))))))
(list
(replace-regexp-in-string regex "\\1" "[OneWordOrMore]")
(replace-regexp-in-string regex "\\1" "Onewordormore")
(replace-regexp-in-string regex "\\1" "OneWordormore")
(replace-regexp-in-string regex "\\1" "OneWordOrMore")))
@spacebat
spacebat / oo.php
Created September 23, 2010 13:25 — forked from dhotson/oo.php
<?php
// Define the 'class' class
$class = Obj()
->fn('new', function ($class) {
$newClass = Obj($class->methods)
->fn('new', function($class) {
$obj = Obj($class->imethods);
$args = func_get_args();
array_shift($args);