Skip to content

Instantly share code, notes, and snippets.

@gtrak
gtrak / gist:1928815
Created February 28, 2012 02:41
static hiccup generation
(defmacro defpartial
"Create a function that returns html using hiccup. The function is
callable with the given name."
[fname params & body]
`(defn ~fname ~params
(h.core/html
~@body)))
(defmacro fn-partial
"Create a function that returns html using hiccup."
running:
(clojure.java.shell/sh "sh" (str "-c " "\"ls -l\""))
returns:
{:exit 2, :out "", :err "sh: - : invalid option\nUsage:\tsh [GNU long option] [option] ...\n\tsh [GNU long option] [option] script-file ...\nGNU long options:\n\t--debug\n\t--debugger\n\t--dump-po-strings\n\t--dump-strings\n\t--help\n\t--init-file\n\t--login\n\t--noediting\n\t--noprofile\n\t--norc\n\t--posix\n\t--protected\n\t--rcfile\n\t--restricted\n\t--verbose\n\t--version\nShell options:\n\t-irsD or -c command or -O shopt_option\t\t(invocation only)\n\t-abefhkmnptuvxBCHP or -o option\n"}
readably:
{:exit 2, :out , :err sh: - : invalid option
Usage: sh [GNU long option] [option] ...
<Location /svn>
DAV svn
SVNParentPath /var/www/svn
SSLRequireSSL
AuthType Basic
AuthName "Restricted Files"
AuthUserFile "/etc/bugzilla/passwords"
AuthGroupFile "/etc/bugzilla/groups"
# Require group Bugzilla
(defmacro to-map []
(let [keys# (keys &env)
keywords# (map keyword keys#)]
`(zipmap [~@keywords#] [~@keys#])))
;-> (let [c 1] (let [a 1 b (inc a)] (to-map)))
;{:c 1, :a 1, :b 2}
@gtrak
gtrak / gist:2891175
Created June 7, 2012 19:54
Does this exist?
(defn diff-vals
[old new]
(let [new-minus-old (difference (into #{} (vals new))
(into #{} (vals old)))]
(map-invert (select-keys (map-invert new) new-minus-old))))
(defmacro let-map
"Avoids having to build maps from let bindings manually"
[bindings]
(let [names (->> (tree-seq #(or (vector? %) (map? %)) identity bindings)
(filter symbol?))
bindings (destructure bindings)]
`(let [~@bindings]
(zipmap [~@(map (comp keyword name) names)]
[~@names]))))
(ns pomoclojo.core
(:import [org.apache.commons.exec
PumpStreamHandler
DefaultExecutor
ExecuteWatchdog
CommandLine]
[java.io ByteArrayOutputStream])
(:use [clj-time.core :only [in-secs in-minutes now interval plus minus within? minutes secs]]))
(defn execute
@gtrak
gtrak / gist:3057775
Created July 6, 2012 02:49
Gary's 5-Year Course in Programming
Books I've read that I recommend, pretty much in the order that I read them, I'm not listing books that I
considered to be too specific, without any generic and fundamental knowledge, or that could easily be replaced by other, similar books:
Code Complete 2
Programming Pearls (didn't finish it yet)
The Pragmatic Programmer
Mythical Man Month
Effective C++ Scott Meyers
Design Patterns (Gang of Four) (good reference, but pretty dry)
Pattern Hatching (explains how they came up with them)
Refactoring (Martin Fowler, (google for the pdf, read the first few
@gtrak
gtrak / gist:3122677
Created July 16, 2012 13:20
Swank in web app
(ns swanker.core
(:require [swank.swank :as swank]))
(gen-class
:name swanker.core.ServletFilter
:prefix servlet-
:implements [javax.servlet.ServletContextListener])
(comment
java.lang.AbstractMethodError: null
at clojure.core.protocols/fn (protocols.clj:73)
clojure.core.protocols$fn__5828$G__5823__5841.invoke (protocols.clj:13)
clojure.core$reduce.invoke (core.clj:6030)