Skip to content

Instantly share code, notes, and snippets.

View iantruslove's full-sized avatar

Ian Truslove iantruslove

View GitHub Profile
@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]
;; 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 / 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 ...

@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 / 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 / README.md
Created February 16, 2014 19:34
Building a simple ClojureScript single page web application [Den of Clojure Feb 2014]

Beyond hello world: building a simple ClojureScript single page web application

Shown at Feb '14 Den of Clojure

Intro

So you've read the blogs and thought how fun it would be to write web front ends with your favorite lisp. Perhaps you've even fired up the repl and done a little playing. But how do you get from there to a

Multi-window, multi-terminal split

Two terminal windows open, one with a bunch of long running watch tasks, the other with an editor. Each of the terminals is a view into one of two windows in a tmux session. Useful for having a vertically split screen with editor on right, and switching between a browser and other command windows on the left.

In first terminal:

  • tmux new-session -s first
  • tmux rename-window editor
  • emacs or whatever

In second terminal:

  • tmux new-session -t first -s second
@iantruslove
iantruslove / vim.markdown
Last active December 16, 2015 01:29
Vim Smackdown! for Den of Clojure

Vim Smackdown

Intro / Ethos

  • Vim vs Emacs: seems like comparing a text editor to the JVM. Apples to oranges?
  • Where Emacs is about providing the user powerful tools, Vim is a powerful text editor focussed on efficiency
  • Emacs has nice tooling for clj dev - can Vim match it?

Keep the mnemonics in mind...