Skip to content

Instantly share code, notes, and snippets.

View mishok13's full-sized avatar

Andrii Mishkovskyi mishok13

View GitHub Profile
{
"VU": "VUT",
"SR": "SUR",
"ML": "MLI",
"LK": "LKA",
"GF": "GUF",
"BA": "BIH",
"US": "USA",
"TR": "TUR",
"PN": "PCN",
=> \d test;
Table "public.test"
Column | Type | Modifiers
--------+---------+-----------
id | integer |
value | integer |
=> select * from test;
id | value
----+-------
@mishok13
mishok13 / gist:8707503
Last active August 29, 2015 13:55
RSyslog configuration with dynamic path and overwritten message format
$template TestFormat,"Message: %msg%\n"
$template TestFile,"/tmp/test_%$year%%$month%%$day%%$hour%.log"
# Writes matching messages to path defined by TestFile template in TestFormat format
:syslogtag, contains, "test" -?TestFile;TestFormat
# Drops messages matching this syslog tag
:syslogtag, contains, "test" ~
user> (require '[korma.core :as sql])
nil
user> (def q (-> (sql/select* :test)
(sql/fields :foo :bar)))
#'user/q
;; Just looking whether the query is correct
user> (sql/as-sql q)
"SELECT \"test\".\"foo\", \"test\".\"bar\" FROM \"test\""
@mishok13
mishok13 / gist:7140401
Last active December 26, 2015 10:59
Well, I guess Clojure's hash built-in is properly fucked
user> (count (for [x (range -200 200) y (range -200 200)] (hash {:foo x :bar y :baz "what"})))
160000
user> (count (frequencies (for [x (range -200 200) y (range -200 200)] (hash {:foo x :bar y :baz "what"}))))
487
user> (count (frequencies (for [x (range -200 200) y (range -200 200)] (hash [x y "what"]))))
6369
@mishok13
mishok13 / gist:7102820
Created October 22, 2013 15:32
LOL @ COUNT
user> (def s (apply str (repeat 100 "a")))
#'user/s
user> (bench/quick-bench (count s))
WARNING: Final GC required 2082.410405844158 % of runtime
Evaluation count : 8685690 in 6 samples of 1447615 calls.
Execution time mean : 67.822779 ns
Execution time std-deviation : 1.770044 ns
Execution time lower quantile : 65.381948 ns ( 2.5%)
Execution time upper quantile : 69.642259 ns (97.5%)
Overhead used : 2.812543 ns
@mishok13
mishok13 / reducers to the resque!
Last active December 26, 2015 05:39
Line by line reading
user> (defn c [p]
(with-open [rdr (clojure.java.io/reader p)]
(reduce + (map count (line-seq rdr)))))
#'user/c
user> (bench/quick-bench
(c "/tmp/test"))
WARNING: Final GC required 356.7754050400232 % of runtime
Evaluation count : 6 in 6 samples of 1 calls.
Execution time mean : 525.040480 ms
Execution time std-deviation : 29.017225 ms
Exception in thread "main" java.lang.ExceptionInInitializerError
at clojure.main.<clinit>(main.java:20)
Caused by: java.io.FileNotFoundException: Could not locate clj_http:client__init.class or clj_http:client.clj on classpath:
at clojure.lang.RT.load(RT.java:443)
at clojure.lang.RT.load(RT.java:411)
at clojure.core$load$fn__5018.invoke(core.clj:5530)
at clojure.core$load.doInvoke(core.clj:5529)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5336)
at clojure.core$load_lib$fn__4967.invoke(core.clj:5375)
(defproject druid-example "0.1.0-SNAPSHOT"
;; Additional repository as described here https://github.com/metamx/druid/issues/34#issuecomment-10830530
:repositories {"metamx-libs" "https://metamx.artifactoryonline.com/metamx/pub-libs-releases-local"
"jboss-libs" "https://repository.jboss.org/nexus/content/repositories/thirdparty-uploads"}
:dependencies [[org.clojure/clojure "1.4.0"]
[com.metamx/druid "0.3.2"]]
:main druid.core)
;; Dependencies are not resolved correctly :(
$ lein deps
@mishok13
mishok13 / gist:3945518
Created October 24, 2012 11:16
Failing to make UserAgentUtils work with Clojure
# Project created by running the following command
$ lein new helloworld
# src/helloworld/core.clj
(ns helloworld.core
(:import [nl.bitwalker.useragentutils.UserAgent])
(:gen-class :main true))
(defn -main
[& args]