Skip to content

Instantly share code, notes, and snippets.

View noprompt's full-sized avatar
💭
The choice to have discipline is a programmer's worst enemy.

Joel Holdbrooks noprompt

💭
The choice to have discipline is a programmer's worst enemy.
View GitHub Profile
#! /usr/local/bin/lumo
(ns app.core
"This application watches the a directory <DIR> for screen shots
and applies an OCR to them (`tesseract`). The resulting text file is
saved to a directory called '<DIR>/OCR Screen Shots`.")
(def fs
(js/require "fs"))
@noprompt
noprompt / z.clj
Last active April 22, 2020 17:59
Z Algorithm
(defn longest-prefix-at
[s i]
(let [max-k (. s length)]
(or (last (for [j (range 1 max-k)
:let [k (+ i j)]
:when (<= k max-k)
:let [s1 (subs s 0 j)
s2 (subs s i k)]
:while (= s1 s2)]
s2))
@noprompt
noprompt / permutations.clj
Created September 21, 2017 17:19
Permutations in Clojure (based on Heap's algorithm)
(defn swap
"Swap the elements at positions `i` and `j` in `v`."
{:private true}
[v i j]
(-> v
(assoc i (get v j))
(assoc j (get v i))))
;; SEE: https://en.wikipedia.org/wiki/Heap%27s_algorithm
(defn permutations [coll]
def with_repl_friendly_inspect(&block)
x = block.call
case x
# We don't want to and sometimes can't override the #inspect method
# of these classes of values.
when Array,
Class,
FalseClass,
Hash,
(ns conform-case
(:require [clojure.spec :as spec]))
(defn build-clause-form
{:private true}
[expression-form clause else-form]
(let [[spec binding-form & body] clause]
`(let [conform-value# (spec/conform ~spec ~expression-form)]
(if (= conform-value# ::spec/invalid)
@noprompt
noprompt / intero-scratch.el
Last active May 1, 2017 21:11
Intero scratch buffer which provides minimal facilities for sending code to the Intero REPL.
(defun intero-scratch-send-paragraph ()
(interactive)
(let* ((source-code-start (save-excursion
(backward-paragraph)
(point)))
(source-code-end (save-excursion
(forward-paragraph)
(point)))
@noprompt
noprompt / strum.clj
Created December 22, 2016 19:52
Macro for defining instrumented functions which verify their arguments and return values against specs.
(ns strum.core
(:refer-clojure :exclude [defn])
(:require
[clojure.spec :as spec]
[clojure.spec.test :as spec.test]))
;; ---------------------------------------------------------------------
;; Prelude
;; HACK: Currently, as of Clojure 1.9.0-alpha14, there is a bug with
(ns machines.cek
(:require
[clojure.core.match :as match]
[clojure.spec :as spec]))
;; e ∈ Exp ::= x | (e e) | (λ (x) e)
;; x ∈ Var
;; ς ∈ Σ = Exp × Env × Kont
;; v ∈ Val ::= (λ (x) e)
;; ρ ∈ Env = Var →_fin Val × Env
(ns state-box)
(defprotocol IGetState
(-get-state [state key]))
(defprotocol IPutState
(-put-state [state key value]))
(deftype ImmutableBox [get-state put-state state]
IGetState
use std::io::BufRead;
use std::io::BufReader;
use std::io::ErrorKind;
use std::io::Write;
use std::net::TcpListener;
use std::net::TcpStream;
use std::thread;
use std::time::Duration;
fn handle_tcp_stream(mut tcp_stream: TcpStream) {