Skip to content

Instantly share code, notes, and snippets.

View viesti's full-sized avatar

Kimmo Koskinen viesti

View GitHub Profile
@viesti
viesti / gist:bba5c88abbb2f6ecb914
Last active May 31, 2018 14:52
Custom reporter for cljs.test
(ns myapp.test
(:require [cljs.test :as test :refer-macros [deftest is] :refer [report]]))
(enable-console-print!)
(defmethod report [:karma :begin-test-ns] [m]
(println "\nTesting with Karma" (name (:ns m))))
(defmethod report [:karma :summary] [m]
(println "All done"))
@viesti
viesti / gist:25c3ac5920150c596957
Created February 15, 2015 19:21
goog.dependencies_.nameToPath things
(println (str "goog._dependencies.nameToPath count: " (count (js->clj (.. js/goog -dependencies_ -nameToPath )))))
(println (str "i18 stuff: " (count (filter #(re-find #".*i18.*" (name (key %))) (js->clj (.. js/goog -dependencies_ -nameToPath ))))))
goog._dependencies.nameToPath count: 5314
i18 stuff: 3543
@viesti
viesti / count snipplet
Last active August 29, 2015 14:24
count test vars for cljs.test
(ns karma.macros
(:require [cljs.analyzer.api :as ana-api]))
(defmacro ns-metas [re]
(mapv (fn [ns]
`(ns-interns ~['quote ns]))
(filter #(re-matches re (str %))
(ana-api/all-ns))))
-----------------------------------------------------------------
@viesti
viesti / filters.py
Created September 17, 2015 13:10
Ansible filter plugin to create rules fo ec2_group
def make_rules(hosts, ports, proto):
return [{"proto": proto,
"from_port": port,
"to_port": port,
"cidr_ip": host} for host in hosts for port in map(int, ports.split(","))]
class FilterModule(object):
def filters(self):
return {'make_rules': make_rules}
@viesti
viesti / ec2_group_set
Created October 11, 2015 19:28
Alter security groups on EC2 nodes
#!/usr/bin/python
from boto.ec2 import connect_to_region
from boto.ec2.group import Group
def main():
module = AnsibleModule(
argument_spec = dict(
ec2_id = dict(required=True),
group_names = dict(required=True),
@viesti
viesti / composing.clj
Created December 23, 2015 11:36
Composing
user=> (->> (range 20) (drop 3) (filter odd?) (take 5))
(3 5 7 9 11)
user=> (into [] (comp (drop 3) (filter odd?) (take 5)) (range 20))
[3 5 7 9 11]

Keybase proof

I hereby claim:

  • I am viesti on github.
  • I am viesti (https://keybase.io/viesti) on keybase.
  • I have a public key ASB3ZVN7e3l1zmGJt3jyoS9DKhRU18qwmhRiif0a1r2qZgo

To claim this, I am signing this object:

;; Solves math excercise:
;; 9 = 5 [ ] 3 [ ] 4 [ ] 5,
;; , where [ ] should be one of operations: +, -
;; Uses just random brute force :)
user> (def ops #{+ -})
user> (loop [cnt 0
op1 (first ops)
op2 (first ops)
op3 (first ops)]
@viesti
viesti / glow-sample.clj
Last active April 28, 2019 17:35
Clojure code highlight via Glow
(spit "talk-samples.html" (format "<html><head><style>%s</style></head><body>%s</body></html"
(g/generate-css (-> glow.colorschemes/solarized-dark
(dissoc :background)
(assoc :symbol "#0b2a34")
(assoc :string "#1f7a73")))
(g/highlight-html (slurp "talk-samples.clj"))))
@viesti
viesti / utils.py
Created May 2, 2019 15:54
Stream and decompress a gzip file from S3
import boto3
import zlib
def decompress_object(bucket, key, out_file):
s3 = boto3.client("s3")
body = s3.get_object(Bucket=bucket, Key=key)['Body']
with open(out_file, "ab") as out:
decompressor = zlib.decompressobj(zlib.MAX_WBITS|32)
for chunk in body.iter_chunks():
out.write(decompressor.decompress(chunk))