Skip to content

Instantly share code, notes, and snippets.

Mark Feeney overthink

View GitHub Profile
@overthink
overthink / copy-of-bash-init.md
Created Jun 20, 2018
Copy of https://github.com/0cjs/sedoc/blob/master/lang/bash/init.md in case original disappears (don't want to fork whole repo).
View copy-of-bash-init.md

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
overthink / core$simple.class
Last active Jun 13, 2018
Compile Clojure regex literals.
View core$simple.class
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
flags: ACC_PUBLIC, ACC_FINAL, ACC_SUPER
Constant pool:
#1 = Utf8 clj_re/core$simple
@overthink
overthink / gist:e6a4a9264110190b7e00f1a3880599f1
Last active May 29, 2018
Demo of why vals in traits are "bad" (aka you have to be very careful)
View gist:e6a4a9264110190b7e00f1a3880599f1
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
overthink / parens.scala
Created Apr 30, 2018
Fiddling with scala empty parens vs. parameterless
View parens.scala
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
overthink / find-dup-repo-files
Created Apr 18, 2018
find duplicate files in a git repo
View find-dup-repo-files
#!/usr/bin/python
# 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
overthink / get-loved
Created Dec 9, 2017
Get artist, track name, url from last.fm loved tracks for a user.
View get-loved
#!/bin/bash
set -euo pipefail
API_KEY=$(cat ~/.lastfm_api_key)
LASTFM_USER="overthink"
LIMIT=1000
getpage() {
local page="${1?need page number to fetch}"
curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getlovedtracks&user=$LASTFM_USER&api_key=$API_KEY&format=json&limit=$LIMIT&page=$page" \
@overthink
overthink / die-on-nils.clj
Last active Dec 15, 2016
Sort of nice nil checker in Clojure
View die-on-nils.clj
(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) "...")
s))))
@overthink
overthink / app.js
Created Aug 7, 2016 — forked from mjackson/app.js
Using webpack with pixi.js
View app.js
var PIXI = require('pixi.js')
console.log(PIXI)
View mocks.clj
(ns foo.core
"Looking at ways to mock out records when testing and also using schema."
(:require
[schema.core :as s]))
;; approach 1 (problematic for mocks) --------------------------------------------------
(s/defrecord Thing
[name :- s/Str
age :- s/Int])
@overthink
overthink / gist:c7efe144abbd23524004
Created Apr 30, 2015
Bytecode for Using.apply()
View gist:c7efe144abbd23524004
public <A extends java/lang/Object, B extends java/lang/Object> B apply(A, scala.Function1<A, B>);
flags: ACC_PUBLIC
Code:
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
You can’t perform that action at this time.