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 / 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);
@spacebat
spacebat / scope-guard.el
Created November 23, 2012 12:37
Emacs lisp scope guard
(eval-when-compile
(require 'cl))
(defmacro* scope (&rest args)
"Partial implementation of scope the statement from D2.
A series of :key val arguments are accepted after which there is
a body of forms. The body is executed within an unwind-protect,
with the :exit form being unconditionally executed, and :success
and :failure conditionalised. A :failure-return argument will be
evaluated and its value returned in place of any condition raised.
@spacebat
spacebat / gist:4442501
Created January 3, 2013 10:34
emacs: eval-expression-to-kill-ring
(defun eval-expression-to-kill-ring ()
"Evaluate an expression interactively and place its result in the kill ring"
(interactive)
(kill-new (call-interactively 'eval-expression)))
@spacebat
spacebat / html-entities.el
Created January 4, 2013 00:52
Emacs HTML entities un/escaping
(defvar user/html-entity-to-unicode-alist
'(("Aacute" . "Á") ("aacute" . "á") ("Acirc" . "Â") ("acirc" . "â") ("acute" . "´") ("AElig" . "Æ") ("aelig" . "æ") ("Agrave" . "À") ("agrave" . "à") ("alefsym" . "ℵ") ("Alpha" . "Α") ("alpha" . "α") ("amp" . "&") ("and" . "∧") ("ang" . "∠") ("apos" . "'") ("aring" . "å") ("Aring" . "Å") ("asymp" . "≈") ("atilde" . "ã") ("Atilde" . "Ã") ("auml" . "ä") ("Auml" . "Ä") ("bdquo" . "„") ("Beta" . "Β") ("beta" . "β") ("brvbar" . "¦") ("bull" . "•") ("cap" . "∩") ("ccedil" . "ç") ("Ccedil" . "Ç") ("cedil" . "¸") ("cent" . "¢") ("Chi" . "Χ") ("chi" . "χ") ("circ" . "ˆ") ("clubs" . "♣") ("cong" . "≅") ("copy" . "©") ("crarr" . "↵") ("cup" . "∪") ("curren" . "¤") ("Dagger" . "‡") ("dagger" . "†") ("darr" . "↓") ("dArr" . "⇓") ("deg" . "°") ("Delta" . "Δ") ("delta" . "δ") ("diams" . "♦") ("divide" . "÷") ("eacute" . "é") ("Eacute" . "É") ("ecirc" . "ê") ("Ecirc" . "Ê") ("egrave" . "è") ("Egrave" . "È") ("empty" . "∅") ("emsp" . " ") ("ensp" . " ") ("Epsilon" . "Ε") ("epsilon"
@spacebat
spacebat / hide-by-regexp.el
Created January 21, 2013 08:13
Playing around with the invisible text property in emacs
(defun hide-by-regexp (regexp &optional buffer start finish)
"First stab at hiding from START (default: (point-min)) to the end of the first match of REGEXP in BUFFER."
(save-excursion
(with-current-buffer (or buffer (current-buffer))
(unless start (setq start (point-min)))
(goto-char start)
(when (search-forward-regexp regexp finish t)
(add-text-properties start (point) '(invisible t))))))
@spacebat
spacebat / kvplist-merge
Created January 22, 2013 14:29
A naive implementation of property list merge
(defun* kvplist-merge (&rest plists)
"Merge the 2nd and subsequent plists into the first, clobbering values set by lists to the left."
(let ((result (car plists))
(plists (cdr plists)))
(loop for plist in plists do
(loop for (key val) on plist by 'cddr do
(setq result (plist-put result key val))))
result))
@spacebat
spacebat / package-dirs
Created January 27, 2013 01:30
Ignore version numbers in ELPA package directories. Also gists are not displaying as the language that I indicate :(
(defun package-dirs (package-name)
"Ignore version numbers in ELPA package directories"
(let ((regex (concat "^" package-name "-.*")))
(mapcar (lambda (x) (concat package-user-dir "/" x))
(remove-if-not (lambda (x) (string-match regex x))
(directory-files package-user-dir)))))
@spacebat
spacebat / create-scratch.el
Created February 3, 2013 13:31
Create a scratch buffer, with a mode and some locals for take off no zigs there
(defvar scratch-buffer-locals '(lexical-binding t)
"A plist of variables and bindings to apply in a new scratch buffer")
(defvar scratch-buffer-mode-locals '(cperl-mode (cperl-indent-level 4))
"A plist of modes and the buffer locals to set in a new scratch buffer according to mode")
(defun create-scratch-buffer (&optional mode)
"Create a new scratch buffer to work in. (could be *scratch* - *scratchX*)"
(interactive "aMode: ")
(let ((n 0)
(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 / *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")