Skip to content

Instantly share code, notes, and snippets.

View AlexBaranosky's full-sized avatar

AlexBaranosky AlexBaranosky

  • Cisco Secure Malware Analytics (formerly Threat Grid)
  • Massachusetts
  • 05:14 (UTC -04:00)
View GitHub Profile
(fset 'gui-diff-last-failure
(lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ([18 97 99 116 117 97 108 58 13 134217734 19 40 61 13 right 201326624 201326624 134217847 134217790 40 103 117 105 45 100 105 102 102 32 25 41] 0 "%d")) arg)))
(key-chord-define-global "xx" 'gui-diff-last-failure)
(defun g-blame ()
"Which commits last affected this line?"
(interactive)
(shell-command
(format "git show $(git blame '%s' -L %s,%s | awk '{print $1}')"
(buffer-file-name)
(line-number-at-pos)
(line-number-at-pos))))
(defun g-churn ()
@AlexBaranosky
AlexBaranosky / promos.clj
Created February 19, 2014 02:48
How to make a var dynamic at runtime
;; 1. eval this
(def x 1)
;; 2. eval this
(binding [x 2]
(println x))
;; 3. eval this
(.setDynamic #'x)
(fset 'gui-diff-last-failure
(lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ([18 97 99 116 117 97 108 58 13 134217734 19 40 61 13 right 201326624 201326624 134217847 134217790 40 103 117 105 45 100 105 102 102 32 25 41] 0 "%d")) arg)))
(key-chord-define-global "xx" 'gui-diff-last-failure)
(->> (repeatedly (partial rand-int 26))
(map #(+ % 65))
(map char)
(take 100)
(apply str))
(defmacro let-map
"Creates a hash-map which can refer to the symbols of the names of the keys
declared above."
[& kvs]
(assert (even? (count kvs)))
(let [ks (take-nth 2 kvs)
sym-ks (map (comp symbol name) ks)
vs (take-nth 2 (rest kvs))]
`(let ~(vec (interleave sym-ks vs))
~(apply hash-map (interleave ks sym-ks)))))
@AlexBaranosky
AlexBaranosky / *cider-repl*.clj
Last active August 29, 2015 13:58
interesting destructuring behavior I never took advantage of...
;; interesting destructuring behavior I never took advantage of...
;; Wonder if it'd make destructuring faster to remove the seq?
;; checking stuff, which I did know anyone used, at least not explicitly
;; macroexpand:
(let [{:keys [a b] :as c} '(:a 1 :b 2) ] [a b c])
;; =>
(let*
[map__27061
(eval-after-load "sql"
'(progn
(sql-set-product 'postgres)))
(add-hook 'sql-mode-hook 'sql-highlight-postgres-keywords)
(def commonly-used-str->keyword
{"precise" :precise
"messy" :messy
"active" :active
"control" :control})
(defn fast-keywordize [k]
(get commonly-used-str->keyword k))
(defn third-way [k]
(def ^:private default -1.0)
(def ^:private millis-in-a-day 86400000)