Skip to content

Instantly share code, notes, and snippets.

View rollup.clj
(ns rollup.core
(:require [clojure.core.async :refer [go chan <! put! timeout alt! alts!]]))
(def ch (chan))
(go
(loop [stash []]
(let [[v c] (alts! [ch (timeout 3000)])]
(if (= c ch)
@ray1729
ray1729 / gist:68f4feb328c4d68b7b1e
Created May 15, 2014
Explode string containing ambiguous characters
View gist:68f4feb328c4d68b7b1e
(ns playground.explode
(:require [clojure.math.combinatorics :refer [cartesian-product]]
[clojure.string :as str]))
(def ambiguous-chars [#{\O \0} #{\I \L \1}])
(defn ambiguate
[c]
(or (first (filter #(contains? % c) ambiguous-chars))
[c]))
@ray1729
ray1729 / gist:6ba102fb09e59a1af3a4
Last active Aug 29, 2015
Full-text and fuzzy search with Titanium
View gist:6ba102fb09e59a1af3a4
(ns titanium-demo.core
(:require [clojure.java.io :as io]
[clojurewerkz.titanium.graph :as tg]
[clojurewerkz.titanium.schema :as scm]
[clojurewerkz.titanium.vertices :as tv]))
(defn generate-config
"Generate a configuration map to use BerkeleyDB and Lucene
with data stored in the given directory."
[dir]
View merge.clj
(def xs (sort (repeatedly 30 #(rand-int 20))))
(def ys (sort (repeatedly 25 #(rand-int 20))))
(defn merge-sorted-seqs
[xs ys]
(lazy-seq (cond
(empty? xs) (seq ys)
(empty? ys) (seq xs)
:else (let [x (first xs) y (first ys)]
@ray1729
ray1729 / HornetQ Test
Created May 22, 2015
Minimal immutant application to test HornetQ
View HornetQ Test
(ns hornetq-test.core
(:require [immutant.messaging :as msg]
[immutant.util])
(:gen-class))
(def running? (atom true))
(def uniq (rand-int 1000000))
(defn do-stuff []
@ray1729
ray1729 / gist:453499
Created Jun 25, 2010
Process Jan's SNP data with Clojure
View gist:453499
;; This is a suggested improvement for processing SNP data, in response
;; to Jan Aerts' blog post <http://saaientist.blogspot.com/2010/06/encounter-with-incanter-about-clojure.html>.
;; Note that this example is for Clojure 1.1.0; if you're using Clojure 1.2, change the ns definition
;; to use clojure.contrib.io instead of duck-streams.
(ns ray1729.clojure.bio.snps
(:use [clojure.contrib.duck-streams :only (read-lines)]))
(defn parse-line
[s]
@ray1729
ray1729 / gist:521160
Created Aug 12, 2010
Process common chunks of a sorted input stream
View gist:521160
#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
my ( $key, @values ) = next_record();
while ( defined $key ) {
my ( $next_key, @next_values ) = next_record();
if ( defined $next_key and $next_key eq $key ) {
@ray1729
ray1729 / secret_santa.clj
Created Nov 23, 2010
Pair up names for Secret Santa
View secret_santa.clj
(defn secret-santa
[names]
(let [s (shuffle names)]
(partition 2 1 (cons (last s) s))))
@ray1729
ray1729 / gist:848069
Created Feb 28, 2011
Example keep-only implementation to keep at most n elements in each bucket of a sequence
View gist:848069
(defn keep-only
[n bucket-fn s]
(letfn [(my-filter
[s seen]
(when (seq s)
(let [e (first s)
b (bucket-fn e)
c (inc (get seen b 0))]
(if (> c n)
(recur (rest s) seen)
@ray1729
ray1729 / gist:896702
Created Mar 31, 2011
Possible Regexp::Common API for Clojure
View gist:896702
;; Perl: $RE{num}{-base => 2}{real}{-group => 3}{-sep => ','}
(re-seq (re :real {:base 2 :group 3 :sep \,} ) "1.345")