Skip to content

Instantly share code, notes, and snippets.

@rplevy
rplevy / htm2clj-region.el
Last active August 21, 2017 20:58
tool for generating (usually valid, or close to valid) sablono markup from raw html
(defun htm2clj-region (beg end)
(interactive "r")
(shell-command-on-region beg end
"html2clj"
(current-buffer)
t))
@rplevy
rplevy / bashrc-excerpt.el
Last active February 23, 2018 00:34
defshell, defshellonreg, defregexp
(defmacro defshell (name cmd)
`(defun ,name ()
(interactive)
(insert (shell-command-to-string ,cmd))))
(defmacro defshellonreg (name cmd &optional replace)
`(defun ,name (beg end)
(interactive "r")
(shell-command-on-region beg end ,cmd
(if ,replace (current-buffer) nil)
@rplevy
rplevy / edn2json.cljs
Last active February 23, 2018 01:06
edn->json command-line script + emacs interactive function interface
#!/usr/local/bin/planck
(ns scripts.edn2json
(:require [cljs.reader :as r]
[planck.core :refer [slurp *command-line-args* *in* line-seq]]))
(defn last-n-chars [n s]
(apply str (reverse (take n (reverse s)))))
(let [s (first *command-line-args*)
#!/usr/bin/env plk -Sdeps {:deps,{inflections,{:mvn/version,"0.13.0"}}}
;; EXAMPLE USAGE:
;;
;; profiles2env profiles.clj > ~/cc-vars
;; . ~/cc-vars
(ns scripts.profiles2env
(:require [cljs.reader :as r]
[clojure.string :as str]
@rplevy
rplevy / filebin-example.sh
Created October 2, 2018 01:58
filebin.net command-line example
export SHA=$(git rev-parse HEAD)
tar czfv $SHA.tgz resources/public/
curl --request POST --data-binary "@${SHA}.tgz" -H "filename: "$SHA.tgz -H "bin: "$SHA https://filebin.net
export T=$(curl -s https://filebin.net/$SHA | grep \?t= | tail -n 1 | sed -e 's/^.*zip.t=//' | cut -c1-8)
curl -s https://filebin.net/$SHA/$SHA.tgz?t=$T --output $SHA.tgz
tar -xzf $SHA.tgz
@rplevy
rplevy / cmd-line-scripting-with-plk-and-clj.org
Last active May 2, 2019 00:47
cmd-line-scripting-with-plk-and-clj.org

command-line scripting with plk & clj

what to write scripts in?

bash?

perl?

python?
why not clojure?

why not?

bash/perl etc pre-installed

unorthodox installation requirements sometimes not worth it

this is actually a pretty good reason not to
@rplevy
rplevy / clj->org.clj
Last active May 29, 2019 23:15
takes a sequence of rows of clojure data and a sequence of fns (keys for example) that produce the columns, and generates an org table
(defn clj->org
[data-rows col-fns]
(doseq [line (map (apply juxt col-fns) data-rows)]
(println (str "|" (clojure.string/join "|" line) "|"))))
;; edit: use print-table, and support col headers
;; I never realized print-table is an org-table!!
(defn clj->org
[data-rows col-fns & [headers]]
@rplevy
rplevy / ticket-sentiment.clj
Last active January 18, 2020 01:28
ticket-sentiment.clj
(ns ticket-sentiment.core
(:require [clojure.data.csv :as csv]
[clojure.java.io :as io]
[clojure.pprint :refer [pprint]]
[damionjunk.nlp.cmu-ark :as ark]
[damionjunk.nlp.stanford :as nlp]))
(defn mean [coll]
(let [sum (apply + coll)
count (count coll)]
@rplevy
rplevy / README.txt
Last active February 3, 2022 07:09
twitter archive
tweets from my twitter archive but in order
@rplevy
rplevy / bitclout_fees.sh
Last active April 1, 2021 00:15
bitclout fees
echo "<html><table><tr><th>type</th><th>amount</th><tr>" > /tmp/transactions.html; cat /tmp/transactions | egrep "^(Transaction Type:|Fees:).*" | while read l ; do if [[ "$l" =~ ^Transaction.*$ ]]; then export transaction=$(echo $l | sed -e 's/^.*://'); else echo "<tr><td>"$transaction"</td><td>"$(echo $(echo $l | sed -e 's/^.*://')" * 154.87" | bc )"</td></tr>"; fi ; done >> /tmp/transactions.html ; echo "</table></html>" >> /tmp/transactions.html