Skip to content

Instantly share code, notes, and snippets.

@olim7t
olim7t / IntToDateDemo.java
Last active January 21, 2016 16:04
Custom codec to handle CQL `date` columns as Java ints
import com.datastax.driver.core.*;
import com.datastax.driver.core.exceptions.InvalidTypeException;
import java.nio.ByteBuffer;
public class LongToDateDemo {
public static class LongToDateCodec extends TypeCodec<Integer> {
// Piggyback on the default codecs' implementation
@sunng87
sunng87 / reflection.clj
Created November 20, 2015 10:04
clojure: access private field/method via reflection
(defn invoke-private-method [obj fn-name-string & args]
(let [m (first (filter (fn [x] (.. x getName (equals fn-name-string)))
(.. obj getClass getDeclaredMethods)))]
(. m (setAccessible true))
(. m (invoke obj args))))
(defn private-field [obj fn-name-string]
(let [m (.. obj getClass (getDeclaredField fn-name-string))]
(. m (setAccessible true))
(. m (get obj))))
(require '[clojure.core.async :as a])
(def xform (comp (map inc)
(filter even?)
(dedupe)
(flatmap range)
(partition-all 3)
(partition-by #(< (apply + %) 7))
(flatmap flatten)
(random-sample 1.0)
@danlentz
danlentz / flow-diagram.clj
Created February 26, 2014 06:53
Clojure ASCII flow diagrams from google code
;;;;;;;;;;;;;;;;;;
;; $Rev$
;; textflow is a trivial generator of RFC like call flow (a.k.a sequence diagrams)
;;
;; Example usage:
;; (flow [Alice Bob Tzach]
;; [[mmm Tzach Bob]
;; [xxx Bob Alice]
;; []
;; [zzz Alice Tzach]])
@niclashoyer
niclashoyer / docker-cleanup.sh
Created June 6, 2013 20:27
Remove all Docker Containers
#!/bin/bash
containers=`sudo find /var/lib/docker/graph/ -maxdepth 1 -type d -printf "%f "`
docker rmi $containers
@mlimotte
mlimotte / merge-with-key.clj
Created April 24, 2012 15:10
Clojure merge-with-key
(ns mlimotte.util)
; A variation on clojure.core/merge-with
(defn merge-with-key
"Returns a map that consists of the rest of the maps conj-ed onto
the first. If a key occurs in more than one map, the mapping(s)
from the latter (left-to-right) will be combined with the mapping in
the result by calling (f key val-in-result val-in-latter)."
[f & maps]
@nicerobot
nicerobot / jstatd.sh
Created November 18, 2011 00:01
Run jstatd w/o error 'access denied (java.util.PropertyPermission java.rmi.server.ignoreSubClasses write)'
#!/bin/sh
policy=${HOME}/.jstatd.all.policy
[ -r ${policy} ] || cat >${policy} <<'POLICY'
grant codebase "file:${java.home}/../lib/tools.jar" {
permission java.security.AllPermission;
};
POLICY
jstatd -J-Djava.security.policy=${policy} &
@nandub
nandub / ProtobufEnvelope.java
Created May 1, 2011 05:52
ProtobufEnvelope - allows creating a protobuf message without the .proto file dynamically.
import com.google.protobuf.DescriptorProtos;
import com.google.protobuf.Descriptors;
import com.google.protobuf.DynamicMessage;
import com.google.protobuf.Message;
import java.util.HashMap;
/**
* ProtobufEnvelope - allows creating a protobuf message without the .proto file dynamically.
*