Skip to content

Instantly share code, notes, and snippets.

@semperos
semperos / keybase.md
Created April 8, 2016 17:14
keybase.md

Keybase proof

I hereby claim:

  • I am semperos on github.
  • I am semperos (https://keybase.io/semperos) on keybase.
  • I have a public key ASDAW-1JkM-P2_egYedl99oey9AQVwqp56R0O44Fks1BAAo

To claim this, I am signing this object:

@semperos
semperos / condition-systems-clojure-core.clj
Last active March 31, 2016 16:39
Clojure core condition system from Chris Houser's talk https://www.youtube.com/watch?v=zp0OEDcAro0
;; === errors ===
(defn ^:dynamic *malformed-log-entry-error* [msg info]
(throw (ex-info msg info)))
;; === restarts ===
(def ^:dynamic *use-value*)
(def ^:dynamic *skip-log-entry*)
(def ^:dynamic *reparse-entry*)
;; Low-level function
@semperos
semperos / condition-systems.clj
Created March 31, 2016 15:35
Adapted snippets from Chris Houser's condition systems talk (https://www.youtube.com/watch?v=zp0OEDcAro0)
;; Low-level function
(defn parse-log-entry [text]
(if (well-formed-log-entry? text)
{:successfully-parsed text}
(restart-case
[:skip-log-entry (fn [] nil)
:use-value (fn [value]
value)
:reparse-entry (fn [fixed-text]
(parse-log-entry fixed-text))]
@semperos
semperos / defvar.c
Created February 20, 2016 03:53
Emacs defvar
DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
doc: /* Define SYMBOL as a variable, and return SYMBOL.
You are not required to define a variable in order to use it, but
defining it lets you supply an initial value and documentation, which
can be referred to by the Emacs help facilities and other programming
tools. The `defvar' form also declares the variable as \"special\",
so that it is always dynamically bound even if `lexical-binding' is t.
The optional argument INITVALUE is evaluated, and used to set SYMBOL,
only if SYMBOL's value is void. If SYMBOL is buffer-local, its
@semperos
semperos / go-macroexpand.clj
Created January 13, 2016 15:50
Simple core.async go block
(let [c__18718__auto__ (a/chan 1)
captured-bindings__18719__auto__ (clojure.lang.Var/getThreadBindingFrame)]
(clojure.core.async.impl.dispatch/run
(fn []
(let [f__18720__auto__ (fn state-machine__18533__auto__
([]
(clojure.core.async.impl.ioc-macros/aset-all!
(java.util.concurrent.atomic.AtomicReferenceArray.
7)
0
@semperos
semperos / read-preserve.clj
Created November 19, 2015 18:59
Clojure preserving reader
(defn read-preserve!
"Alter the root definition of clojure.tools.reader/read-discard to allow preserving forms that come after #_ instead of discarding them. Providing options to clojure.tools.reader/read or clojure.tools.reader/read-string in the form of `{:preserve (true|false)}` will determine whether or not forms after #_ are preserved or discarded.
This allows tooling that wishes to read Clojure source to support arbitrary annotations via #_, which to normal Clojure reading will be completely discarded, but to the tool in question can be used for arbitrary purposes."
[]
(alter-var-root #'clojure.tools.reader/read-discard
(fn [_]
(fn [rdr _ opts pending-forms]
(if (:preserve opts)
(#'clojure.tools.reader/read* rdr true nil opts pending-forms)
@semperos
semperos / 00_destructuring.md
Created November 5, 2015 18:26 — forked from john2x/00_destructuring.md
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors

@semperos
semperos / keybase.md
Created October 28, 2015 13:57
keybase.md

Keybase proof

I hereby claim:

  • I am semperos on github.
  • I am semperos (https://keybase.io/semperos) on keybase.
  • I have a public key whose fingerprint is 0065 61EA BE23 4E31 E2BA 2B31 9D39 75BB 0EB3 9F0D

To claim this, I am signing this object:

@semperos
semperos / div.clj
Last active September 11, 2015 22:12 — forked from gfmurphy/Div.hs
Readability
(defn digits
"Generate a list of digits contained in the number"
[number]
(loop [found-digits '() base (quot number 10) digit (rem number 10)]
(let [found-digits (conj found-digits (if (neg? digit) (- digit) digit))]
(if (zero? base)
found-digits
(recur found-digits (quot base 10) (rem base 10))))))
(defn divisible-digits
@semperos
semperos / CMakeLists.txt
Created May 15, 2015 20:17
Minimal, essential CMakeLists.txt (project root)
cmake_minimum_required(VERSION 3.2)
project(SdlTutorial)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(SdlTutorial ${SOURCE_FILES} include/res_path.h include/cleanup.h)
include(FindPkgConfig)
pkg_search_module(SDL2 required sdl2)