Skip to content

Instantly share code, notes, and snippets.

@exupero
exupero / advent-of-code-2018.clj
Last active December 25, 2018 20:09
Advent of Code 2018
(ns exupero.advent-of-code.2018
(:require [clojure.string :as string]
[clojure.set :refer [intersection rename-keys map-invert]]
[clojure.zip :as zip]
[net.cgrand.xforms :as xf]))
(def parse-int #(Integer/parseInt %))
; Day 1, puzzle 1
(def input-1 (map parse-int (string/split-lines (slurp "./resources/advent-of-code/2018/day-1-input.txt"))))
@exupero
exupero / building.clj
Created October 23, 2018 00:55
A state machine example
; Constructing a physical building is, ideally, a linear process, but in reality there can be twists
; and turns and backtracking to previous steps. Here's a state machine that models a simple,
; hypothetical construction process:
(def construction-process
{:concept {:revised-concept :concept
:township-approved :township-permission
:township-rejected :terminated}
:township-permission {:blueprints-delivered :blueprints}
:blueprints {:code-violations :blueprints-in-revision
@exupero
exupero / cl.cljs
Last active April 26, 2018 18:42
Ad hoc text transformation via Planck
#!/usr/local/bin/planck
(require '[clojure.string :as string])
(require 'cljs.reader)
(require '[planck.core :refer [slurp eval *in* *command-line-args*]])
(def in (slurp *in*))
(defn format-output [x]
(cond
@exupero
exupero / README.md
Last active April 17, 2018 11:28
Putting the Space in Workspace

I use my terminal as an IDE, largely thanks to Tmux. I spin up sessions for the API, the client front-end, and any other codebases I happen to be working in, as well as a session for tracking to do's and ideas.

I launch a session using a script I call zmux. If given a session name, zmux attaches to the session. If given a directory, zmux launches a new session and looks for a .tmuxrc file in the directory that it can source to set up the session, allowing me to easily spin up a workspace and daemon processes for a project. This is especially useful for projects I haven't touched in years.

I created a Tmux binding to switch between sessions on partial session name matches:

unbind t; bind t command-prompt -p "session" "run-shell \"find-tmux-session %%\""
@exupero
exupero / README.md
Last active February 29, 2016 12:57
instruct

instruct

A shell script to give step-by-step instructions. Pipe text into it. It'll be processed as follows:

  • Each line is echoed back to you one at a time.
  • Hit the Enter key to see the next instruction.
  • Lines surrounded by triple backticks are copied to the system clipboard, and the next line of text has the icon next to it.
  • Blank lines are ignored.
  • To insert a blank line, use a triple dash (---).
@exupero
exupero / whichpull.py
Last active January 13, 2016 16:25
Getting the pull request for a branch with Python and Jq.
import json
import sys
for p in json.load(sys.stdin):
if p['head']['ref'] == sys.argv[1]:
print p['html_url']
@exupero
exupero / index.html
Last active December 30, 2015 08:38 — forked from mbostock/.block
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
background: #fcfcfa;
}
.stroke {
fill: none;
@exupero
exupero / README.md
Last active December 21, 2015 03:28 — forked from mbostock/.block
D3-raylabel plugin

Demonstrates the D3 ray-label plugin for labeling slices of pie and donut graphs based on the angle of each slice's centroid.

Label font sizes are scaled (within bounds) based on the size of the slice.

Plugin is hosted on Github.

@exupero
exupero / README.md
Last active December 20, 2015 19:58
Uncertain Future Projection

A line graph with a projected future that waves to indicate uncertainty in the projection.

from contextlib import contextmanager
@contextmanager
def assert_change_by(fn, delta):
original = fn()
yield
final = fn()
assert final - original == delta