Skip to content

Instantly share code, notes, and snippets.

View iantruslove's full-sized avatar

Ian Truslove iantruslove

View GitHub Profile
@iantruslove
iantruslove / gist:9478996
Last active August 29, 2015 13:57
Convert one of @Raynes' #clojure log files to a multiline JSON file ready for ElasticSearch's _bulk import API
curl -s http://www.raynes.me/logs/irc.freenode.net/clojure/2011-07-04.txt \
| sed -r 's/\\/\\\\/g' | sed -r 's/"/\\"/g' \
| sed -r 's/^\[([^\]+)\] ([^:]+): (.*)$/{ "index" : { "_index" : "irc.freenode.clojure", "_type" : "message" } }\n{ "datestamp": "2011-07-04T\1", "author": "\2", "message": "\3" }/'
@iantruslove
iantruslove / 2011-07-04.json
Last active August 29, 2015 13:57
The result of converting one of @Raynes #clojure logs into an ES _bulk import ready JSON file
{ "index" : { "_index" : "irc.freenode.clojure", "_type" : "message" } }
{ "datestamp": "2011-07-04T04:03:35", "author": "lnostdal-laptop", "message": "ring seems to mess around with stdout (*out* ?) or something .. debug output using println doesn't show up in slime here" }
{ "index" : { "_index" : "irc.freenode.clojure", "_type" : "message" } }
{ "datestamp": "2011-07-04T04:04:03", "author": "lnostdal-laptop", "message": "..and exceptions end up in the terminal; where i started `lein swank'" }
{ "index" : { "_index" : "irc.freenode.clojure", "_type" : "message" } }
{ "datestamp": "2011-07-04T04:04:20", "author": "lnostdal-laptop", "message": "..is there some way of fixing this? .. i.e. println output should end up in slime, and exceptions also" }
{ "index" : { "_index" : "irc.freenode.clojure", "_type" : "message" } }
{ "datestamp": "2011-07-04T04:05:56", "author": "hoeck", "message": "lnostdal-laptop: the server code runs in a different thread than the slime repl, and slime only redirects stdout of its
@iantruslove
iantruslove / docker-fu.md
Last active August 29, 2015 13:57
Some docker command line magic to keep track of...

Remove all unlabelled images:

docker rmi $(docker images | grep "^<none>" | awk "{print $3}")

Remove all old containers:

docker rm `docker ps -notrunc -a -q`

Disable caching of build steps with docker build -no-cache ...

;; Option 1: Return the response
(with-authentication state-with-auth-creds
clj-http.client/post
"http://some.url/api"
{:accept :json :headers {"X-foo" "bar"}})
;-> {:status 200 :body "looks good"}
;; Option 2: Return a wrapped request method
(def authenticating-post
(with-authentication state-with-auth-creds clj-http.client/post))
@iantruslove
iantruslove / gist:9688036
Created March 21, 2014 14:56
scrypt password hashing
(ns foo.user
(:require [clojurewerkz.scrypt.core :as sc]))
(defn calculate-hash [password salt]
(sc/encrypt (str password salt) 16384 8 1))
(defn verify-hash [hash password salt]
(sc/verify (str password salt) hash))
(defn verify-user-password [user password]
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{:uri "/foo"
:http-method :post
:headers {"content-type": "application/json"
"accept": "*/*"}
:body <InputStream ...>}
@iantruslove
iantruslove / general-case-middleware.clj
Last active August 29, 2015 14:05
Ring: from the ground up
(defn wrap-generic-middleware-example [handler & [other-args]]
(fn [request]
;; Early side-effects:
(log/info "Wrapping incoming request...")
(let [;; Modify request here:
req (assoc request :new-req-key "some value for handlers")
;; Run the handlers:
resp (handler req)]
;; Late side-effects:
(log/info "My middleware is almost done.")