Skip to content

Instantly share code, notes, and snippets.

@honza
honza / update-keys.clj
Created February 4, 2014 10:32
Update keys
(defn update-keys [m ks f]
(let [g (fn [c k]
(update-in c [k] f))]
(reduce g m ks)))
(update-keys {:a 1 :b 2} [:a :b] inc)
;; => {:a 2 :b 3}
@honza
honza / Rocket.hs
Last active August 29, 2015 13:56
BSD/MIT licensed
-- This is a Haskell implementation of aphyr's
-- "Clojure from the ground up - modeling"
--
-- http://aphyr.com/posts/312-clojure-from-the-ground-up-modeling
--
-- Compile this with:
--
-- $ ghc -O Rocket.hs
import GHC.Exts
@honza
honza / fff.hs
Created March 17, 2014 16:04
Typeclasses
class Functor f where
fmap :: (a -> b) -> f a -> f b
class (Functor f) => Applicative f where
pure :: a -> f a
(<*>) :: f (a -> b) -> f a -> f b
(<$>) :: (Functor f) => (a -> b) -> f a -> f b
class Monad m where

Keybase proof

I hereby claim:

  • I am honza on github.
  • I am honza (https://keybase.io/honza) on keybase.
  • I have a public key whose fingerprint is 70E0 3E0A A2E5 40EA A2FB 4422 67C0 AD96 97D5 AB41

To claim this, I am signing this object:

@honza
honza / config.fish
Created April 24, 2014 18:17
Cabal Sandbox Fish Shell
function cabal_prompt
if [ -e "cabal.sandbox.config" ]
printf '(cabal sandbox)'
end
end
@honza
honza / pure.clj
Created May 7, 2014 17:06
Impure function detectio
;; If you name your impure functions with a name ending in "!",
;; you can use this handy macro to check if a form uses any impure functions.
(declare find-impure)
(defn ends-in-bang? [s]
(= \! (last (str s))))
(defn impure? [e]
(cond
@honza
honza / angular.cljs
Created August 26, 2014 07:54
Quick wisp macro example - Angular controller
(def app {})
(defmacro fnj [args & body]
(if (empty? args)
`(fn [] ~@body)
`[~@(map name args) (fn ~args ~@body)]))
(defmacro def-controller [module n args & body]
`(.controller ~module ~(name n) (fnj ~args ~@body)))
dactyl/pentadactyl/../common/make_jar.sh: line 47: unexpected EOF while looking for matching `''
make: *** [chrome/] Error 2
// Given
var content = {
id: 1,
name: 'Honza'
};
function renderTemplate(content) {
return 'Hello, ' + content.name;
}
@honza
honza / clojure.md
Last active September 24, 2015 17:32
Clojure and memory usage in development

Developing in Clojure seems to require tons of RAM. I'm currently working on a small HTTP service: 200 LOC, minimal dependencies. I'm using lein ring server-headless to run a development server, and I'm using Emacs and the CIDER repl. This spins up 4 java processes on my machine, 2 for the server and 2 for CIDER.

That's almost 3GB of RAM. If you're also running a VM in virtualbox or VMware, your computer is gonna have a bad time.

VMware Fusion is using only 200MB of RAM. No idea how that's possible.