Skip to content

Instantly share code, notes, and snippets.

View stathissideris's full-sized avatar

Stathis Sideris stathissideris

  • London
View GitHub Profile
(setq ss/erc-shorten-links-limit 50)
(defun ss/erc-shorten-links ()
(goto-char (point-min))
(while (re-search-forward url-regexp nil t)
(let ((start (match-beginning 0))
(end (match-end 0)))
(when (> (- end start) ss/erc-shorten-links-limit)
(let* ((url (buffer-substring start end))
(replacement (concat (substring url 0 ss/erc-shorten-links-limit) "...")))
(message "replacing with URL: %s" replacement)
(ns bsq.arch
(:require [dali.io :as dio]
[dali.layout :as l]
[dali.layout.utils :refer [place-by-anchor bounds->anchor-point]]
dali.layout.stack
dali.layout.distribute
dali.layout.align
dali.layout.connect
dali
[dali.syntax :as d]
@stathissideris
stathissideris / macroexpand-replace.el
Last active November 9, 2015 16:23
macroexpand-replace.el
;;code for "How to use Clojure macros to refactor Clojure code in Emacs" video
;; https://www.youtube.com/watch?v=Szu0wNttfek
;;function that macroexpands the previous Clojure sexp and
;;replaces the expression in the buffer with the macroexpanded version
(defun macroexpand-replace ()
(interactive)
(let ((exp
(cider-sync-request:macroexpand
@stathissideris
stathissideris / positano-session.clj
Last active October 11, 2015 12:00
positano session for yada
;;add this:
(ns yada.core
...
[positano.trace :as tr :refer (deftrace)])
;;instrument all interceptors (there is functionality to do this in a
;;less invasive way with trace-var*, but it may require changing
;;default-interceptor-chain to contain vars (#'available? etc)
@stathissideris
stathissideris / bonjai.clj
Created May 18, 2015 12:01
Possible syntaxes
;;This says: I'm looking for a :text "tag" whose direct parent is a :p
;;the ^= ensures that the rule matches at the level of the :text not at the level of the :p
[:p ^= [:text & =content]]
;;I'm looking for a :text in the among the children of :p that has
;;a subsequent :text2 sibling whose content I'd like to also
;;capture
[:p
^* _
^= [:text & =content]
@stathissideris
stathissideris / bonjai.clj
Last active August 29, 2015 14:21
bonjai syntax experiments
;;this is a theoretical re-implementation of https://github.com/stathissideris/dali/blob/master/src/cljx/dali/syntax.clj#L78
;;to explore the different ways to implement the bonjai syntax
(def v vector)
;;right part is provided with the captured vars "anaphorically".
;;I think = is a good alternative to ?, looks a bit cleaner
;;and it conveys the meaning of capturing
(def dali->hiccup
(defn zipify [value pattern]
(loop [[value-zipper pattern-zipper :as both-zippers] (map #(z/zipper coll? seq {} [%]) [value pattern])
result (transient {})]
(let [[value-node pattern-node :as both-nodes] (map z/node both-zippers)]
(condp apply [z/end? both-zippers]
every? (when (seq both-zippers) (persistent! result)) ;;both zippers exhausted at the same time, result!
some nil ;;reached the end of one of the zippers when the other one still had stuff left
(recur
(cond
@stathissideris
stathissideris / test.clj
Last active August 29, 2015 14:21
unification as destructuring
(unify-let [[?a _ & ?more] [1 5 6 7]] [a more])
;=> [1 (6 7)]
(unify-let [[{:a 6}] []] :yes :no)
;=> :no
(unify-let [{?key 8} {:a 8}] key)
;=> :a
;;*SADTROMBONE* http://soundbible.com/1830-Sad-Trombone.html
(defn generic-zip
"Works on maps and vectors. Any other seq is treated as a vector."
[root]
(zip/zipper
(some-fn map? vector?)
seq
(fn [node children]
(->
(cond
(instance? clojure.lang.MapEntry node) [(first children) (second children)]
@stathissideris
stathissideris / long-process-control.org
Created March 27, 2015 18:00
Abstraction for controlling long processes

Restartability

Measure rate, % progress, count done, estimated total time, estimated time left

Control rate by making slower

Count exceptions and aggregate them

Retries