Skip to content

Instantly share code, notes, and snippets.

View codification's full-sized avatar

Ville Svärd codification

  • Stockholm, SE
View GitHub Profile
@codification
codification / proc.clj
Created March 6, 2012 08:10
Clojure asynchronous process
(ns proc
(:import [java.lang ProcessBuilder])
(:use [clojure.java.io :only [reader writer]]))
(defn spawn [& args]
(let [process (-> (ProcessBuilder. args)
(.start))]
{:out (-> process
(.getInputStream)
(reader))
@codification
codification / clojure.lang
Created February 6, 2012 22:04
Clojure Syntax highlighting in shjs (for showoff)
# Clojure syntax highlighting for GNU source-highlight
# rocks with SHJS
comment start ";"
include "number.lang"
vardef SPECIALCHAR = '\\.'
environment string delim "\"" "\"" begin
@codification
codification / graphite-client.py
Last active April 29, 2019 17:21
Graphite client in python
import time
import socket
def collect_metric(name, value, timestamp):
sock = socket.socket()
sock.connect( ("localhost", 2003) )
sock.send("%s %d %d\n" % (name, value, timestamp))
sock.close()
def now():
return int(time.time())
@codification
codification / graphite-client.clj
Created December 30, 2011 08:55
Graphite client in clojure
(ns clj-client.core
(import [java.net Socket]
[java.io PrintWriter]))
(defn now []
(int (/ (System/currentTimeMillis) 1000)))
(defn write-metric [name value timestamp]
(with-open [socket (Socket. "localhost" 2003)
os (.getOutputStream socket)]
@codification
codification / server.py
Created November 25, 2011 10:16
Python HTTP PUT test server
import sys
import signal
from threading import Thread
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
class PUTHandler(BaseHTTPRequestHandler):
def do_PUT(self):
print "----- SOMETHING WAS PUT!! ------"
print self.headers
length = int(self.headers['Content-Length'])
@codification
codification / bogus.core.clj
Created September 21, 2011 13:32
Feeding graphite with metrics
(ns bogus.core
(import java.util.Date)
(import java.net.Socket)
(import java.io.PrintWriter))
(def metric "bogus.metric")
(defonce power (atom 0))
(defn pow! []
(swap! power inc))
@codification
codification / Midje test
Created February 16, 2011 22:56
(solve the-challange the-words)
(ns challange.test.core
(:use [challange.core] :reload)
(:use [midje.sweet]))
(fact
(solve "AA" ["A"]) => ""
(solve "ABA" ["A" "B"]) => ""
(solve "AB" ["A" "X"]) => "B")
(fact