Skip to content

Instantly share code, notes, and snippets.

View kornysietsma's full-sized avatar

Korny Sietsma kornysietsma

View GitHub Profile
#!/usr/bin/env python
try:
import boto3
except ImportError:
print 'Please install boto3 - either set up a virtualenv, or run: pip install boto3'
exit(1)
import sys
@kornysietsma
kornysietsma / tumlr-schema.clj
Created December 4, 2014 13:54
tumblr schema from clojurex 2014 talk
(def AnyPost
{
:id (s/either s/Str s/Int)
:slug s/Str
:from-feed-id s/Int
:url s/Str
:url-with-slug s/Str
(s/optional-key :tags) [s/Str]
})
@kornysietsma
kornysietsma / loop.clj
Created November 10, 2014 08:09
basic core.async loop with tick, killer channel
(defn irc-loop
"core.async based main loop" [config]
(let [killer (chan)]
(go-loop [data config]
(when data
(println "running")
(alt!
killer ([reason] (println "killed because:" reason))
(timeout 1000) (do (println "tick!")
(recur data)))))
@kornysietsma
kornysietsma / config.clj
Created November 6, 2014 16:28
gitlab stuff
(ns gitlab-utils.config)
(def api-base "http://localhost/api/v3/")
@kornysietsma
kornysietsma / wait-until.clj
Created October 24, 2014 11:41
wait until in clojure test
(def default-wait-death (time/seconds 5))
(def default-wait-delay-ms 10)
(defn wait-until*
"wait until a function has become true"
([name fn] (wait-until* name fn default-wait-death))
([name fn wait-death]
(let [die (time/plus (time/now) wait-death)]
(loop []
(if-let [result (fn)]
@kornysietsma
kornysietsma / fix_xchat.sh
Created October 16, 2014 13:32
irc fiddling
#!/bin/bash -e
set +e
xchat_pid=$(pidof xchat)
set -e
if [[ -z $xchat_pid ]]; then
xchat &
echo "waiting for xchat to calm down"
sleep 3
fi
xchat -e --command "set net_ping_timeout 60"
@kornysietsma
kornysietsma / try-topology.clj
Created October 6, 2014 14:16
rabbitmq / langohr detecting changed topology attempt
(defn try-topology [conn fn]
(let [ch (lch/open conn)]
(try
(fn conn ch)
true
(catch IOException e
(when-not (instance? ShutdownSignalException (.getCause e))
(throw (Exception. "Unexpected exception trying RabbitMQ operation" e)))
(let [reason (-> e .getCause .getReason)]
(when-not (instance? AMQP$Channel$Close reason)
@kornysietsma
kornysietsma / instrument-anything.clj
Last active August 29, 2015 14:06
instrumenting functions via graphite and robert-hooke
(defn graphiteisze-path
"Graphite uses a dot (.) as a separator. Whisper stores metrics on disk by name, so we cannot have slashes in the metric name"
[path]
(clojure.string/replace path #"[/\.]" "_"))
(defn timed-hook-fn
[metric-registry group type name]
(let [timer (timer metric-registry [(graphiteisze-path group) (graphiteisze-path type) (graphiteisze-path name)])]
(fn [f & args]
(time-fn! timer #(apply f args)))))

Keybase proof

I hereby claim:

  • I am kornysietsma on github.
  • I am korny (https://keybase.io/korny) on keybase.
  • I have a public key whose fingerprint is CCA6 2821 5A0F 290B 5040 1F49 1C12 9115 703D B610

To claim this, I am signing this object:

@kornysietsma
kornysietsma / higher_order.clj
Last active August 29, 2015 14:05
basic clojure functional functions
; this page: http://tinyurl.com/ndfzluz
; "higher order functions" basically means using functions as parameters to functions. Lots of languages have this - even C has function pointers
; Structure and Interpretation of Computer Programs, a classic 1993 text from MIT, says:
; "It is better to have 100 functions operate on one data structure than to have 10 functions operate on 10 data structures"
; http://mitpress.mit.edu/sicp/
; simple example - define "is-even":
(def is-even (fn [x] (= (mod x 2) 0)))