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 / 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
@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 / 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 / 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 / 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 / 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 / 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 / mail.clj
Created April 2, 2012 20:19
ssh key rejected on ec2 eu-west-1
(ns mail
(:use [pallet.utils :only [make-user]]
[pallet.crate.automated-admin-user :only [automated-admin-user]]
[pallet.phase :only [phase-fn]]
[pallet.core :only [server-spec group-spec converge]]
[pallet.compute :only [compute-service-from-config-file]]))
(def my-admin-user (make-user "superuser"
:public-key-path "/path/to/public"
:private-key-path "/path/to/private"))
@codification
codification / core.clj
Last active December 16, 2015 00:30
FP-meetup Token-Ring
(ns tokenring.core
(:require [lamina.core :as lamina])
(:require [aleph.tcp :as aleph])
(:require [gloss.core :as gloss]))
(defn connect-and-send [message]
(println (str "connecting and sending: " message))
(let [ch (lamina/wait-for-result
(aleph/tcp-client {:host "192.168.48.35"
;;:host "localhost"
@codification
codification / clojure-intro.md
Last active December 16, 2015 00:39
Introduktioner till Clojure