Skip to content

Instantly share code, notes, and snippets.

View overthink's full-sized avatar

Mark Feeney overthink

  • Waterloo, Ontario, Canada
View GitHub Profile
overthink /
Created June 20, 2018 17:01
Copy of in case original disappears (don't want to fork whole repo).

Bash Initalization Behaviour

A Bash process may be:

State Invocation
Login (L) argv[0][0] == '-', --login
Interactive (I) -i, stdin is tty
Remote (R) stdin is "network connection" (see below)
overthink / core$simple.class
Last active June 13, 2018 18:14
Compile Clojure regex literals.
Classfile /home/mark/src/clj-re/target/classes/clj_re/core$simple.class
Last modified 13-Jun-2018; size 1119 bytes
MD5 checksum 7a8f0ea3a3b22a33c335acffef1eda0a
Compiled from "core.clj"
public final class clj_re.core$simple extends clojure.lang.AFunction
minor version: 0
major version: 49
Constant pool:
#1 = Utf8 clj_re/core$simple
overthink / gist:e6a4a9264110190b7e00f1a3880599f1
Last active May 29, 2018 13:52
Demo of why vals in traits are "bad" (aka you have to be very careful)
The issue is that the superclass gets instantiated first, and if it has an eager val that
calls an abstract def (or abstract lazy val, if such a thing is possible) it will capture
the not-yet-fully-initialized value of that val in the subclass (which is usually null).
scala> trait T { def f: String; val callsF = f } // *val* `callsF` calls abstract def `f` -- risky!
defined trait T
scala> object X extends T { val f = "foooo" } // `f` is implemented with a strict val -- bomb is set
defined object X
overthink / parens.scala
Created April 30, 2018 14:52
Fiddling with scala empty parens vs. parameterless
object Parens {
def parameterless: String = "foo"
def emptyParens(): String = "bar"
def fireNukes(): String = "nukes fired"
def log(f: () => String): Unit = { println("fn: " + f) }
def log(msg: String): Unit = { println("string: " + msg) }
def main(args: Array[String]) {
overthink / find-dup-repo-files
Created April 18, 2018 20:34
find duplicate files in a git repo
# Print filenames that are duplicated at least once (by content hash) in the
# repo.
import fileinput
from collections import defaultdict
import subprocess
digest_to_path = defaultdict(list)
p = subprocess.Popen(
overthink / get-loved
Created December 9, 2017 05:16
Get artist, track name, url from loved tracks for a user.
set -euo pipefail
API_KEY=$(cat ~/.lastfm_api_key)
getpage() {
local page="${1?need page number to fetch}"
curl -s "$LASTFM_USER&api_key=$API_KEY&format=json&limit=$LIMIT&page=$page" \
overthink / die-on-nils.clj
Last active December 15, 2016 20:54
Sort of nice nil checker in Clojure
(defn- ellipses-if-long
"Append \"...\" to string version of x if x's length exceeds n."
([x] (ellipses-if-long x 50))
([x n]
(assert (pos? n) "n must be positive")
(let [s (str x)]
(if (> (.length s) n)
(str (subs s 0 n) "...")
overthink / app.js
Created August 7, 2016 06:47 — forked from mjackson/app.js
Using webpack with pixi.js
var PIXI = require('pixi.js')
(ns foo.core
"Looking at ways to mock out records when testing and also using schema."
[schema.core :as s]))
;; approach 1 (problematic for mocks) --------------------------------------------------
(s/defrecord Thing
[name :- s/Str
age :- s/Int])
overthink / gist:c7efe144abbd23524004
Created April 30, 2015 19:56
Bytecode for Using.apply()
public <A extends java/lang/Object, B extends java/lang/Object> B apply(A, scala.Function1<A, B>);
stack=3, locals=7, args_size=3
0: aload_2
1: aload_1
2: invokeinterface #77, 2 // InterfaceMethod scala/Function1.apply:(Ljava/lang/Object;)Ljava/lang/Object;
7: astore_3
8: aload_1
9: ifnull 37