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
@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]
@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: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: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: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)
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) {
;looking to transform:
(def x ([14227624954630003 3] [14227624954630004 4] [14227624954630005 5] [14227624954630006 6]))
;... into:
[[14227624954630003 14227624954630004 14227624954630005 14227624954630006] [3 4 5 6]]
;anything more idiomatic than:
(reduce (fn [result new]
[(conj (nth result 0) (nth new 0))
(conj (nth result 1) (nth new 1))]) [[] []] x)
;?
@raspasov
raspasov / gist:d006968103b6854a4565
Created March 12, 2015 18:21
core.async sample
(ns my-project.test-core-async
(:require [clojure.core.async :refer [chan thread sliding-buffer timeout go <! <!! >!! >! go-loop put! thread alts!! alts! dropping-buffer pipeline-blocking]]))
(def events-ch (chan 1000))
;alternatively, try a sliding buffer if events can't be processed fast enough
;in GUI one **usually** cares about latest instead of *all* events
;Defaults to buffer size to 1000, that can be tuned based on use case
;(def events-ch (chan (sliding-buffer 1000)))
(defn start-go-loop
(ns cloud-monkey.env
(:require [environ.core :as environ]))
(defonce env environ/env)
(defn merge-with-env! [a-map]
(alter-var-root #'env (fn [x] (merge x a-map))))
@raspasov
raspasov / gist:7c34b7744782e01a6170
Created March 13, 2016 05:59
The lesser-known Clojure de-structuring
(let [{elkn :extremely-long-key-name} {:extremely-long-key-name 42}]
(println elkn))
;=> 42