This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.java.io :as io] | |
'[clojure.string :as string] | |
'[clojure.tools.cli :refer [parse-opts]]) | |
(def cli-options | |
[["-o" "--out DIR" "Output directory" | |
:default "out"] | |
["-s" "--source SOURCE" "Source directory" | |
:default "source/_posts"] | |
["-h" "--help"]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; heavily inspired by Mariano Guerra | |
;; http://marianoguerra.org/posts/download-frontend-generated-data-to-a-file-with-clojurescript.html | |
(defn download-blob [file-name blob] | |
(let [object-url (js/URL.createObjectURL blob) | |
anchor-element | |
(doto (js/document.createElement "a") | |
(-> .-href (set! object-url)) | |
(-> .-download (set! file-name)))] | |
(.appendChild (.-body js/document) anchor-element) | |
(.click anchor-element) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; A simple demo of monadic composition of side effects | |
; Program to take 3 nubers as input and print their sum. | |
(defn read-and-add! | |
[prev] | |
(print "Enter a number: ") | |
(+ prev (do (flush) | |
(Integer/parseInt (read-line))))) | |
(defn bind |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#_( | |
"exec" "clojure" "-Sdeps" "{:deps {org.clojure/clojurescript {:mvn/version \"1.10.520\"}}}" "$0" "$@" | |
) | |
;; running js_parser.clj "function foo(x) { var y = x + 1; }" will print: | |
;; [{:type :function, :name "foo", :body [{:variable-statement [{:lvalue "y", :initializer {:type :binary-op, :left "x", :operator "+", :right "1"}}]}], :params ["x"]}] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn get-key | |
[prefix key] | |
(if (nil? prefix) | |
key | |
(str prefix "-" key))) | |
(defn flatten-map-kvs | |
([map] (flatten-map-kvs map nil)) | |
([map prefix] | |
(reduce | |
(fn [memo [k v]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benchmark: transform values of a small map (1000000 iterations) | |
Avg(ms) vs best Code | |
141.61 1.00 (map-vals-map-iterable data inc) | |
146.86 1.04 (reduce-kv (fn [m k v] (assoc m k (inc v))) {} data) | |
156.66 1.11 (reduce-kv (fn [m k v] (assoc m k (inc v))) (empty data) data) | |
161.20 1.14 (transform MAP-VALS inc data) | |
211.53 1.49 (persistent! (reduce-kv (fn [m k v] (assoc! m k (inc v))) (transient {}) data)) | |
227.91 1.61 (map-vals-map-iterable-transient data inc) | |
332.09 2.35 (transform [ALL LAST] inc data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on https://github.com/nodyn/jvm-npm | |
"use strict"; | |
(function() { | |
var System = java.lang.System, | |
File = java.io.File, | |
FileInputStream = java.io.FileInputStream, | |
StringBuilder = java.lang.StringBuilder, | |
BufferedReader = java.io.BufferedReader, | |
InputStreamReader = java.io.InputStreamReader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns org.ozias.git | |
(:require [me.raynes.conch :refer (with-programs)])) | |
(def ^:private git-porcelain | |
["add" "am" "bisect" "branch" "bundle" "checkout" "cherry-pick" "citool" | |
"clean" "clone" "commit" "describe" "diff" "fetch" "format-patch" | |
"gc" "grep" "gui" "init" "log" "merge" "mv" "notes" "pull" "push" | |
"rebase" "reset" "revert" "rm" "shortlog" "show" "stash" "status" | |
"submodule" "tag"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn handle-file-select [evt] | |
(.stopPropagation evt) | |
(.preventDefault evt) | |
(let [files (.-files (.-dataTransfer evt))] | |
(dotimes [i (.-length files)] | |
(let [rdr (js/FileReader.) | |
the-file (aget files i)] | |
(set! (.-onload rdr) | |
(fn [e] | |
(let [file-content (.-result (.-target e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
NewerOlder