Skip to content

Instantly share code, notes, and snippets.

View danlentz's full-sized avatar

Dan Lentz danlentz

View GitHub Profile
(defmacro extend-fn [name args & body]
`(let [old-fn# (var-get (var ~name))
new-fn# (fn [& p#]
(let [~args p#]
(do ~@body)))
wrapper# (fn [& params#]
(if (= ~(count args) (count params#))
(apply new-fn# params#)
(apply old-fn# params#)))]
(alter-var-root (var ~name) (constantly wrapper#))))
(defprotocol Hexl
(hexl-hex [val])
(hexl-char [char]))
(extend-type Number
Hexl
(hexl-hex [i]
(let [rtnval (Integer/toHexString (if (< i 0) (+ 256 i) i)) ]
(if (< (count rtnval) 2) (str "0" rtnval) rtnval)))
(hexl-char [b]
(defprotocol Hexl
(hexl-hex [val])
(hexl-char [char]))
(extend-type Number
Hexl
(hexl-hex [i]
(let [rtnval (Integer/toHexString (if (< i 0) (+ 256 i) i)) ]
(if (< (count rtnval) 2) (str "0" rtnval) rtnval)))
(hexl-char [b]
@danlentz
danlentz / make-org-file.sh
Created September 16, 2013 18:47
tpapp SBCL script example
#!/usr/local/bin/sbcl --script
(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp"
(user-homedir-pathname))))
(when (probe-file quicklisp-init)
(load quicklisp-init)))
(ql:quickload "cl-fad" :verbose nil :explain nil :prompt nil)
(destructuring-bind (header footer &rest files)
(loop for arg in (cdr sb-ext:*posix-argv*)
@danlentz
danlentz / prefix.txt
Created September 14, 2013 23:39
Dydra standard prefixes
The following prefixes are automatically included for all repositories. Any values you specify above will overwrite these defaults.
PREFIX cc: <http://creativecommons.org/ns#>
PREFIX cert: <http://www.w3.org/ns/auth/cert#>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dc: <http://purl.org/dc/terms/>
PREFIX dc11: <http://purl.org/dc/elements/1.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX doap: <http://usefulinc.com/ns/doap#>
PREFIX exif: <http://www.w3.org/2003/12/exif/ns#>
@danlentz
danlentz / trig-bnf.md
Last active December 23, 2015 01:59
BNF specification for ttl grammar

TriG EBNF

[1] TriGDoc	::=	ws* (statement ws*)*
[2] statement	::=	directive ws* '.' | graph
[3] graph	        ::=	graphName? ws* '='? ws* '{' ws* (triples ws* ('.' ws* triples ws*)* '.'? ws*)? '}' ws* '.'?
[4] graphName	::=	resource

All other grammar terms are defined by the Turtle grammar as of 2006/12/04.

@danlentz
danlentz / global_catch_exception.clj
Created September 12, 2013 19:06 — forked from ifesdjeen/global_catch_exception.clj
clojure uncaught exception handler
;; That will actually catch exception within inner thread, too. And within inner thread of inner thread. Etc.
(Thread/setDefaultUncaughtExceptionHandler (proxy [Thread$UncaughtExceptionHandler] []
(uncaughtException [t e]
;;
;; Your fancy Exception logging here
;;
(println "Throwable: " + (.getMessage e))
(println (.toString t)))))
(.start (Thread. (cast Runnable
(fn []
@danlentz
danlentz / d3.css
Created September 12, 2013 19:03 — forked from bobmonteverde/d3.css
/********************
* TOOLTIP CSS
*/
.nvtooltip {
position: absolute;
background-color: rgba(255,255,255,1);
padding: 10px;
border: 1px solid #ddd;
@danlentz
danlentz / 1a.md
Created September 12, 2013 18:51
clojure enlive content layout

You can use snippet markers within your HTML template code in order to generate *-prefixed selectors that you can later use within Enlive template.

For example, if you say:

<div snippet="content-main"></div>

You can later reference it with *content-main selector, which will be automatically generated for you.

Finding Paths

Our example graph consists of movies with title and year and actors with a name. Actors have ACTS_IN relationships to movies, which represents the role they played. This relationship also has a role attribute.

We queried and updated the data so far, now let’s find interesting constellations, a.k.a. paths.