Skip to content

Instantly share code, notes, and snippets.

(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 19:14
Explode string containing ambiguous characters
(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 August 29, 2015 14:07
Full-text and fuzzy search with Titanium
(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]
(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 15:48
Minimal immutant application to test HornetQ
(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 June 25, 2010 21:46
Process Jan's SNP data with Clojure
;; 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 August 12, 2010 15:33
Process common chunks of a sorted input stream
#!/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 November 23, 2010 16:39
Pair up names for Secret Santa
(defn secret-santa
[names]
(let [s (shuffle names)]
(partition 2 1 (cons (last s) s))))
@ray1729
ray1729 / gist:848069
Created February 28, 2011 21:24
Example keep-only implementation to keep at most n elements in each bucket of a sequence
(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 March 31, 2011 16:30
Possible Regexp::Common API for Clojure
;; Perl: $RE{num}{-base => 2}{real}{-group => 3}{-sep => ','}
(re-seq (re :real {:base 2 :group 3 :sep \,} ) "1.345")