Skip to content

Instantly share code, notes, and snippets.

Stathis Sideris stathissideris

Block or report user

Report or block stathissideris

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
stathissideris / pastebox.clj
Last active Mar 10, 2019
pastebox for Clojure
View pastebox.clj
;; This will open a window with a single textfield where you can paste some HTML,
;; press <enter> and you should see a valid Clojure string get printed in your REPL,
;; without having to worry about escaping double quotes etc.
;; AND it fits a single tweet. :)
(import '[javax.swing JFrame JTextField]
'[java.awt.event ActionListener])
(doto (JFrame.)
(.add (doto (JTextField.)
stathissideris / pedestal.clj
Created Sep 28, 2018
Hierarchical table "syntax" for Clojure Pedestal
View pedestal.clj
(defn- add-path-prefix [[path & more] prefix]
(vec (concat [(str prefix path)] more))) ;;TODO handle stray slashes
(defn- prepend-interceptors [[path verb chain & more] interceptors]
(let [new-chain (if (vector? chain)
(vec (concat interceptors chain))
(vec (concat interceptors [chain])))]
(vec (concat [path verb new-chain] more))))
stathissideris / solver.clj
Created Aug 19, 2018
Sudoku solver clojure
View solver.clj
(ns sat.core
(:require [rolling-stones.core :as sat :refer [!]]
[clojure.string :as str]))
(def rows 9)
(def cols 9)
(def values 9)
(defn possible-square-values
stathissideris / alias.clj
Created Jun 6, 2018
Alias Clojure namespace without requiring it (helps with long namespaced keywords)
View alias.clj
(defn ensure-namespace-alias [ns alias-sym]
(when-not (find-ns ns)
(create-ns ns))
(alias alias-sym ns))
(ensure-namespace-alias ' 'long)
::long/foo =>
stathissideris / pedestal-chain-diff.clj
Created Feb 11, 2018
Simple pedestal interceptors to log how the context changes as it gets passed around in the chain
View pedestal-chain-diff.clj
(require '[io.pedestal.log :as log]
'[ :as diff]
'[io.pedestal.interceptor.chain :as chain])
(defn log-diffs [previous current]
(let [[deleted added] (diff/diff (dissoc previous ::chain/queue ::chain/stack ::previous-ctx)
(dissoc current ::chain/queue ::chain/stack ::previous-ctx))]
(when deleted (log/debug :deleted deleted))
(when added (log/debug :added added))))
stathissideris / trace-forms.clj
Last active Nov 30, 2017
naive Clojure macro for tracing all forms
View trace-forms.clj
;; 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]
(fn [form]
(if (and (list? form) (= 'dont (first form)))
(second form)
stathissideris / strict_keys.clj
Last active Aug 15, 2017
Make clojure.spec behave more like schema in terms of keys strictness (no unknown keys allowed)
View strict_keys.clj
;;; 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 / spec.clj
Created Jul 30, 2017
How to generate args for a spec'ed function in Clojure
View spec.clj
(gen/generate (s/gen (:args (s/get-spec (resolve `calculate-limits)))))
View beam.clj
(let [p (Pipeline/create (PipelineOptionsFactory/create))]
(.. p
(apply TextIO.Read/from ("..."))
(apply "ExtractWords"
(ParDo/of (reify DoFn
(processElement [this context]
(apply (Count/perElement))
View windows.el
(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
You can’t perform that action at this time.