Skip to content

Instantly share code, notes, and snippets.

View raspasov's full-sized avatar
🏎️
If you want things, make them.

Rangel Spasov raspasov

🏎️
If you want things, make them.
View GitHub Profile
public class SystemClock {
public static long lastTime = 0;
/**
* Returns a strictly increasing time in number of 100 ns that passed since Unix Epoch.
*/
public static synchronized long getTime() {
long time = System.currentTimeMillis() * 10L*1000L;
if (time <= lastTime) {
@raspasov
raspasov / gist:81c678961b6292eebe04
Last active August 29, 2015 14:11
clojure core.async pub/sub
;create our publisher
(def pub-ch (chan))
(def publication (pub pub-ch #(:topic %)))
;sub chans
(def sub-1 (chan))
(def sub-2 (chan))
;subscribe subs to publisher
(sub publication "clojure" sub-1)
@raspasov
raspasov / gist:7f89bc69884fea298468
Last active August 29, 2015 14:11
Clojure STM operations
(defn new-ops-collector
"Create a new op collector
The collector is a vector of vectors, each internal vector
is a tuple of f and vector-of-params, i.e. [f vector-of-params].
Later on we execute all the ops in a single transaction via (execute-ops collector)
Example structure: [[f [param1 param2 etc]] etc ] "
[]
(atom []))
(defn add-op
@raspasov
raspasov / gist:f04635aaa7a6f2220108
Created December 5, 2014 09:42
Clojure substring search
(defn string-contains?
"Searches a string s for any number of sub-strings, returns true on the first found, false otherwise"
[s sub & subs]
(if subs
(loop [subs (cons sub subs)]
(if-not (empty? subs)
(if-let [has-sub? (.contains s (first subs))]
has-sub?
(recur (rest subs)))
false))
@raspasov
raspasov / gist:e503798f8d33f32b958d
Created August 26, 2014 04:48
Basic Clojure MySQL wrappers, use at your own risk
;ADD TO YOUR project.clj:
[org.clojure/java.jdbc "0.3.4"]
[mysql/mysql-connector-java "5.1.31"]
[com.jolbox/bonecp "0.8.0.RELEASE"]
;https://github.com/ptaoussanis/timbre for error logging, make sure to set your error log file
[com.taoensso/timbre "3.2.1"]
;SOURCE STARTS BELOW
(ns your-project.mysql-lib
(:require [clojure.java.jdbc :as db-adapter]
@raspasov
raspasov / gist:d7e957025e434e99a819
Created June 6, 2014 20:12
Pallet Debug with SSH Auth Fail
engage-rackspace.groups.core=> (pallet.api/converge (assoc eng-web-test :count 1) :compute rs :user midverse-user)
12:57:02.282 [operate-21] INFO pallet.ssh.execute - 23.253.42.140 22 os: infer-os:
12:57:14.982 [operate-21] ERROR pallet.action-plan - Exception in execute-action-map
clojure.lang.ExceptionInfo: SSH connect: server 23.253.42.140 port 22 user null password null pk-path /Users/raspasov/.ssh/midverse pk null
at clojure.core$ex_info.invoke(core.clj:4403) ~[clojure-1.6.0.jar:na]
at pallet.ssh.transport$connect_ssh_session.invoke(transport.clj:117) ~[na:na]
at pallet.ssh.transport$attempt_connect.invoke(transport.clj:153) ~[na:na]
at pallet.ssh.transport$connect$fn__8485.invoke(transport.clj:172) ~[na:na]
at pallet.ssh.transport$connect.invoke(transport.clj:171) ~[na:na]
at pallet.transport.ssh$lookup_or_create_state.invoke(ssh.clj:53) ~[na:na]