Skip to content

Instantly share code, notes, and snippets.

View Database Internals
ifesdjeen / wrap_fn.clj
Created May 22, 2012
Wrapping functions in Clojure
View wrap_fn.clj
(defn wrap-fn
"Wrap or replace some function with your own function"
[qualifier wrapper]
(fn [original-fn]
(fn [& caller-arguments]
(wrapper caller-arguments original-fn)))))
;; Replace your function implementation:
ifesdjeen / ring_middleware_order.clj
Created May 1, 2013
Ring middleware execution order
View ring_middleware_order.clj
(defn handler
(println "HANDLER"))
(defn wrap-1
(fn [request]
(println 1)
(handler request)
ifesdjeen / Haskell Simplification 1.hs
Last active Feb 11, 2018
I've got that piece of code that looks extremely overcomplicated to me. Even though every operation by itself is simple, the "sum" of operations is simply insane.
View Haskell Simplification 1.hs
data Query = Query
data SomeObj = SomeObj
data IoOnlyObj = IoOnlyObj
data Err = Err
-- There's a decoder function that makes some object from String
decodeFn :: String -> Either Err SomeObj
decodeFn = undefined
-- There's a query, that runs against DB and returns array of strings
ifesdjeen / deploy_jar.rb
Created Oct 17, 2013
If you're deploying 20 Clojure libs a day (and keep forgetting Clojars deploy syntax), you're going to love that script. Maybe there's a leiningen task for that, never tried.
View deploy_jar.rb
res = `lein do pom, jar`
jar = res.split("\n").last.gsub("Created ", "")
puts "Gonna deploy jar: #{jar}"
exec "scp pom.xml #{jar}"
View my_let.clj
(defmacro my-let
[bindings & body]
(assert (-> bindings count even?) "Bindings count can only be even.")
`((fn [~@(take-nth 2 bindings)]
~@(take-nth 2 (rest bindings))))
ifesdjeen / with-latch.clj
Last active Dec 21, 2015
Testing with countdown latch
View with-latch.clj
(ns my-test-ns
(:require [clojure.test :refer :all])
(:import [java.util.concurrent CountDownLatch TimeUnit])
(defmacro with-latch
[countdown-from & body]
`(let [latch# (CountDownLatch. ~countdown-from)
~'latch latch#]
(.await latch# 5 TimeUnit/SECONDS)
ifesdjeen / new_gist_file.clj
Last active Dec 21, 2015
In Control Structures of Let-over-lambda, they describe an idea of taking bindings and writing a macro that substitutes symbols for values. That's pretty much same thing. quote from the book itself: The expansion uses Labels special form to bind a function around the provided body. The function is named according to the symbol used in the named …
View new_gist_file.clj
;; Writing something remotely reminding nlet
(defmacro body-and-bindings
[bindings & body]
`(let [~(first bindings) 1
~(second bindings) 2]
;; Expands to:
(let* [a 1 b 2] (+ a b))
View tmux-cheatsheet.markdown

tmux shortcuts & cheatsheet

start new:


start new with session name:

tmux new -s myname
ifesdjeen / string_head.clj
Created Jun 24, 2013
Clojure string tail
View string_head.clj
(defn ^String head
"Returns the first n characters of s."
[n ^String s]
(if (> (count s) n)
(.substring s (- 0 n))))