Skip to content

Instantly share code, notes, and snippets.

@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 / sliding-window-counter.clj
Created March 30, 2016 21:42
Simple time-based sliding window counter implementation in Clojure
(ns sliding-window-counter.core
(:refer-clojure :exclude [inc]))
(defprotocol ICounter
(reset [this])
(inc [this])
(value [this]))
(defrecord SlidingWindowCounter [window-size bucket-size num-buckets buckets]
ICounter
@ray1729
ray1729 / split.clj
Created December 9, 2016 08:55
Split on pred implemented by reducing with a state machine
(defn split-after
[pred coll]
(let [post-accum (fn [accum x]
(update accum :after conj x))
pre-accum (fn [accum x]
(cond-> (update accum :before conj x)
(pred x) (assoc :f post-accum)))]
((juxt :before :after)
(reduce (fn [{:keys [f] :as accum} x] (f accum x))
{:before [] :after [] :f pre-accum}
@ray1729
ray1729 / insert.clj
Created December 9, 2016 08:57
Insert before/after pred implemeted with split-with
(defn insert-after
[pred coll x]
(let [[before after] (split-with (complement pred) coll)]
(concat before (take 1 after) x (drop 1 after))))
(defn insert-before
[pred coll x]
(let [[before after] (split-with (complement pred) coll)]
(concat before x after)))
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
)
@ray1729
ray1729 / thumbnailator.clj
Created July 5, 2024 17:56
Using Thumbnailator from Clojure
(ns thumbnailator
(:require [clojure.java.io :as io])
(:import [net.coobird.thumbnailator Thumbnailator]))
(Thumbnailator/createThumbnail
(io/file "/home/ray/Pictures/self.png")
(io/file "/tmp/self_thumb.png")
74 69)