Skip to content

Instantly share code, notes, and snippets.

View r-moeritz's full-sized avatar

Ralph r-moeritz

  • Adelaide SA
View GitHub Profile
@r-moeritz
r-moeritz / set-umlaut-keys.lisp
Created July 25, 2012 06:19
Umlaut keybindings
;; -*- mode: Lisp; lexical-binding: t; -*-
(defun global-set-umlaut-keys ()
(let ((gen-insert-key
(lambda (key)
(lambda ()
(interactive)
(ucs-insert key)))))
(global-set-key (kbd "\C-co") (funcall gen-insert-key #xf6))
(global-set-key (kbd "\C-cu") (funcall gen-insert-key #xfc))
@r-moeritz
r-moeritz / gist:2761273
Created May 21, 2012 08:54
nif clojure
(defmacro nif [expr pos zero neg]
`(let [~res# ~expr]
(cond (> ~res# 0) ~pos
(= ~res# 0) ~zero
:else ~neg)))
@r-moeritz
r-moeritz / gist:2761193
Created May 21, 2012 08:35
nif macroexpand
(macroexpand
'(nif (random 100) 'positive 'zero 'negative))
;; Expands to:
(LET ((#:RESULT3117 (RANDOM 100))) (COND ((PLUSP #:RESULT3117) 'LET-OVER-LAMBDA.G!.EXAMPLES::POSITIVE) ((ZEROP #:RESULT3117) 'LET-OVER-LAMBDA.G!.EXAMPLES::ZERO) (T 'LET-OVER-LAMBDA.G!.EXAMPLES::NEGATIVE)))
@r-moeritz
r-moeritz / gist:2761145
Created May 21, 2012 08:21
defmacro/g! nif
(defmacro/g! nif (expr pos zero neg)
`(let ((,g!result ,expr))
(cond ((plusp ,g!result) ,pos)
((zerop ,g!result) ,zero)
(t ,neg))))
@r-moeritz
r-moeritz / gist:1974044
Created March 4, 2012 17:40
ClojureCLR LoadEmbeddedAssembly
public static void load(String relativePath)
{
bool loadAsResource = EmbeddedAssembly(relativePath);
load(relativePath, true, loadAsResource);
}
private static bool EmbeddedAssembly(String relativePath)
{
return (ResourceData(ResourceName(relativePath)) != null);
}
@r-moeritz
r-moeritz / gist:1973703
Created March 4, 2012 16:11
ClojureCLR AssemblyResolve
static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
{
var name = args.Name.Split(',').FirstOrDefault();
if (String.IsNullOrEmpty(name) || name.EndsWith(".resources")) return null;
name = name.Replace('.', '_');
var data = (byte[])Properties.Resources.ResourceManager.GetObject(name);
return (data == null) ? null : Assembly.Load(data);
}
@r-moeritz
r-moeritz / init.el
Created June 28, 2011 21:28
My init.el
;; -*- mode: Lisp; lexical-binding: t; -*-
;; ----------------------------------------------------------------------
;; HELPER FUNCTIONS
;; ----------------------------------------------------------------------
(defvar electrify-return-match
"[\]}\)\"]"
"If this regexp matches the text after the cursor, do an \"electric\"
return.")
@r-moeritz
r-moeritz / pretty-literals.lisp
Created June 24, 2011 10:30
pretty hash table & vector literal syntax for common lisp
;;;; pretty-literals.lisp - pretty hash table & vector literal syntax
;;;; inspired by and uses code from http://frank.kank.net/essays/hash.html
(in-package #:pretty-literals)
;; vector literal syntax using brackets
(set-macro-character #\[
(lambda (str char)
(declare (ignore char))
(let ((*readtable* (copy-readtable *readtable* nil))
@r-moeritz
r-moeritz / core.clj
Created June 16, 2011 21:29
cljdoc - a repl helper to quickly browse Clojure docs
;; Copyright (c) Ralph Moritz. All rights reserved.
;; The use and distribution terms for this software are covered by the Eclipse
;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which
;; can be found in the file epl-v10.html at the root of this distribution. By
;; using this software in any fashion, you are agreeing to be bound by the
;; terms of this license. You must not remove this notice, or any other, from
;; this software.
(ns
^{:author "Ralph Moritz"
@r-moeritz
r-moeritz / project.clj
Created June 16, 2011 19:24
hello jwt in clojure : project.clj
(defproject jwt-examples "0.1.0"
:description "Clojure versions of JWT example programs"
:dependencies [[org.clojure/clojure "1.2.1"]
[jetty-wrapper "0.1.1"]])