Skip to content

Instantly share code, notes, and snippets.

View stathissideris's full-sized avatar

Stathis Sideris stathissideris

  • London
View GitHub Profile
@stathissideris
stathissideris / trace-forms.clj
Last active November 30, 2017 08:00
naive Clojure macro for tracing all forms
;; there are quite a few cases where this code would not work, use with caution and check the macro expansion
(require '[clojure.walk :as walk])
(defn- clean-dont [form]
(walk/postwalk
(fn [form]
(if (and (list? form) (= 'dont (first form)))
(second form)
form))
@stathissideris
stathissideris / strict_keys.clj
Last active August 15, 2017 12:31
Make clojure.spec behave more like schema in terms of keys strictness (no unknown keys allowed)
;;; strict keys mode for spec
;; disclaimer: untested, most likely buggy
(require '[clojure.spec.alpha :as s])
(require '[clojure.walk :as walk])
(defmacro only-keys
[& {:keys [req req-un opt opt-un] :as args}]
`(s/and (s/keys ~@(apply concat (vec args)))
@stathissideris
stathissideris / spec.clj
Created July 30, 2017 14:15
How to generate args for a spec'ed function in Clojure
(gen/generate (s/gen (:args (s/get-spec (resolve `calculate-limits)))))
(let [p (Pipeline/create (PipelineOptionsFactory/create))]
(doto
(.. p
(apply TextIO.Read/from ("..."))
(apply "ExtractWords"
(ParDo/of (reify DoFn
(processElement [this context]
...
))))
(apply (Count/perElement))
(require 'hydra)
(global-set-key (kbd "§") 'hydra-windows/body)
(make-face 'move-window-buffer-face)
(set-face-attribute 'move-window-buffer-face nil
:background "#073642")
(setq ss/window-move-remap-cookie nil)
(defun remove-window-move-indicator ()
(if ss/window-move-remap-cookie
(face-remap-remove-relative
@stathissideris
stathissideris / naive_diff.clj
Created February 18, 2017 17:34
slow diff algo
(defn lcs [as bs]
(if-not (and as bs)
[]
(let [[a & ra] as
[b & rb] bs]
(if (= a b)
(cons a (lcs ra rb))
(let [la (lcs as rb)
lb (lcs ra bs)]
(if (> (count la) (count lb)) la lb))))))
@stathissideris
stathissideris / gist:b5600026039d56b483f6c007e8a937e9
Last active February 12, 2017 18:09
Download youtube video from specific time
Example:
youtube-dl -f 22 --get-url https://www.youtube.com/watch?v=mMZriSvaVP8
Then with the link:
ffmpeg -ss 14350 -i (link) -t 11200 -c:v copy -c:a copy react-spot.mp4
One line version:
ffmpeg -ss 14350 -i $(youtube-dl -f 22 --get-url https://www.youtube.com/watch?v=mMZriSvaVP8) -t 11200 -c:v copy -c:a copy react-spot.mp4
You can either pick a format with both video and audio (such as -f 22), or you can use ffmpeg to combine a DASH audio and video stream. You'll need to make sure you're ffmpeg build includes open-ssl (so that it can download the video over https).
@stathissideris
stathissideris / bidi_verbose.clj
Last active September 26, 2016 13:02
bidi verbose
(defn leaf [fragment name]
[fragment name])
(defn branch [fragment & children]
(let [[[tag param]] children]
(if (= tag :bidi/param)
[[fragment param] (vec (rest children))]
[fragment (vec children)])))
(defn param [name]
@stathissideris
stathissideris / deep_merge.clj
Created September 22, 2016 10:38
flexible deep merge implementation in clojure
;;found here: https://github.com/metosin/ring-swagger/blob/1c5b8ab7ad7a5735624986bbb6b288aaf168d407/src/ring/swagger/common.clj#L53-L73
(defn deep-merge
"Recursively merges maps.
If the first parameter is a keyword it tells the strategy to
use when merging non-map collections. Options are
- :replace, the default, the last value is used
- :into, if the value in every map is a collection they are concatenated
using into. Thus the type of (first) value is maintained."
{:arglists '([strategy & values] [values])}
(defun ss/erc-fix-fill (fill-fun)
(save-excursion
(goto-char (point-min))
(re-search-forward "> ")
(replace-match ">➭"))
(funcall fill-fun)
(save-excursion
(goto-char (point-min))
(re-search-forward ">➭")
(replace-match "> ")))