Skip to content

Instantly share code, notes, and snippets.

@tmoertel
tmoertel / gist:5798134
Last active April 8, 2024 21:34
How to transform the vanilla recursive fib function into the iterative DP version through a series of mechanical steps.
# Transforming the vanilla recursive fib into the iterative DP version
# through a series of mechanical steps.
#
# For more on converting recursive algorithms into iterative ones, see:
# http://blog.moertel.com/posts/2013-05-11-recursive-to-iterative.html
# original function
def fib(n):
@danneu
danneu / golang-vs-clojure-async.md
Last active November 6, 2023 04:09
Google I/O 2012 - Go Concurrency Patterns ported to Clojure Video: http://www.youtube.com/watch?v=f6kdp27TYZs
@cheery
cheery / cek.py
Created May 10, 2015 12:53
CEK abstract machine
# I glanced through the pycket paper, saw few rules there. Ended up to doing this.
class Var(object):
def __init__(self, name):
self.name = name
def __repr__(self):
return self.name
class Lam(object):
@sgnl
sgnl / postgres-brew.md
Last active February 20, 2024 10:40
Installing Postgres via Brew (OSX) (outdated see top most note)

Outdated note: the process is a lot easier now: after you brew install postgresql you can initialize or stop the daemon with these commands: brew services start postgresql or brew services stop postgresql.

new out put may look like

To have launchd start postgresql now and restart at login:
  brew services start postgresql
Or, if you don't want/need a background service you can just run:
  pg_ctl -D /usr/local/var/postgres start
@marick
marick / about_those_lava_lamps.md
Last active June 22, 2022 21:08
About Those Lava Lamps

Around 2006-2007, it was a bit of a fashion to hook lava lamps up to the build server. Normally, the green lava lamp would be on, but if the build failed, it would turn off and the red lava lamp would turn on.

By coincidence, I've actually met, about that time, (probably) the first person to hook up a lava lamp to a build server. It was Alberto Savoia, who'd founded a testing tools company (that did some very interesting things around generative testing that have basically never been noticed). Alberto had noticed that people did not react with any urgency when the build broke. They'd check in broken code and go off to something else, only reacting to the breakage they'd caused when some other programmer pulled the change and had problems.

@aphyr
aphyr / with-retry.clj
Created January 20, 2016 03:14
Recur from within catch block
(defrecord Retry [bindings])
(defmacro with-retry
"It's really fucking inconvenient not being able to recur from within (catch)
expressions. This macro wraps its body in a (loop [bindings] (try ...)).
Provides a (retry & new bindings) form which is usable within (catch) blocks:
when this form is returned by the body, the body will be retried with the new
bindings."
[initial-bindings & body]
(assert (vector? initial-bindings))
@danielrw7
danielrw7 / replify
Last active October 24, 2023 12:03
replify - Create a REPL for any command
#!/bin/sh
command="${*}"
printf "Initialized REPL for `%s`\n" "$command"
printf "%s> " "$command"
read -r input
while [ "$input" != "" ];
do
eval "$command $input"
printf "%s> " "$command"

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

@ibraheem4
ibraheem4 / postgres-brew.md
Last active April 14, 2024 20:30 — forked from sgnl/postgres-brew.md
Installing Postgres via Brew (OSX)

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update

How Clojure's documentation can leapfrog other languages

Summary

I made a documentation generator that cashes in on Clojure's dynamism. See the play-cljs docs (a ClojureScript game library) for an example of its output.

The Problem

Like many of you, I've often wondered what my final regret will be on my deathbed. My best guess came to me in a dream recently. I was walking across the charred earth of an apocalyptic future world, maneuvering around the remains of the less fortunate. I was startled to find a young girl, barely holding onto her life. She murmured something to me. I asked her to repeat it, and she said more loudly: "I...wish your Clojure projects didn't have such crappy documentation."