Skip to content

Instantly share code, notes, and snippets.

View timmc's full-sized avatar

Tim McCormack timmc

View GitHub Profile
@timmc
timmc / spclsfc.md
Last active March 19, 2019 19:40
Success-prioritized, concurrency-limited stochastic fallback cascade

Algorithm:

  • State
    • For each node, store:
      • Rolling window of 6 historical stat buckets
      • One additional "sticky" bucket
    • Write stats to newest bucket
    • Age out the oldest bucket every 5 seconds, and add a new one
      • If the oldest bucket had data, copy it over the "sticky" bucket
  • Recorded stats: Number of finished requests, number that
#!/bin/bash
while read line; do
url_encoded="${line//+/ }"
printf '%b\n' "${url_encoded//%/\\x}"
done
@timmc
timmc / state-machine.java
Created January 22, 2019 17:53
Custom query term splitter, as state machine (demonstration only; a regex with possessive quantifiers slightly out-performs this)
public static List<String> splitTermsStateMachine(String query) {
// Horizontal or vertical whitespace
Pattern isWhitespace = Pattern.compile("[\\h\\v]");
//== Manually managed state bits ==//
// If non-null, we're in a term, and this contains the term so far
StringBuilder currentTerm = null;
// True iff inside a quoted run
boolean inQuotes = false;
data class MapEntry<K: Any?, V: Any?>(
override val key: K,
override val value: V
): Map.Entry<K, V>
@timmc
timmc / layout.kt
Created November 18, 2018 20:44
Wanted: Fluent interface for specifying filesystem layout
class Repo : Layout() {
val config by leaf("config.json")
val myKeyring by leaf("self.keyring")
val posts by dir("posts", ::PostsDir)
}
class PostsDir : Layout() {
val post by multiple().dir(name = """[0-9]+""".toRegex(), ::OnePost)
}
@timmc
timmc / gist:d95b90336dfc63881a4034fef436c6e1
Created May 3, 2018 01:29
Passphrase compound collision - case analysis
- 3 word passphrases
- 1000 word list, with one collision: dog, under, underdog
Compounding:
under dog x: 1000
x under dog: 1000
Total loss: 2 * 1000 out of 1000^3
@timmc
timmc / gist:55c8e488533e04f34efea3ef8de1f00c
Created August 30, 2017 18:59
Non-terrible JVM parameters
-XX:-OmitStackTraceInFastThrow
-Dfile.encoding=UTF-8
@timmc
timmc / crash-imagemagick.svg
Last active May 6, 2017 23:18
segfaults imagemagick when `convert crash.svg out.jpg`
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@timmc
timmc / gist:1c3fa7504f8abba5f7855e2acee83e5f
Last active April 5, 2017 23:52
Remove LJ user agreement modal - Adblock Plus filter list
[Adblock Plus 1.1]
! Remove LJ user agreement modal
! Expires: 2 days (update frequency)
!
! Moved to https://raw.githubusercontent.com/timmc/abp/master/lj.txt
!
livejournal.com##.rutos
livejournal.com##.b-fader
@timmc
timmc / five.log
Created March 13, 2017 21:45
(= 5 2)
freenode/#clojure on 2014-04-21:
amalloy sets 5 to be 2 using reflection, probably in PM with clojurebot:
(let [field (nth (.getDeclaredFields Long) 3)] (.setAccessible field true) (.set field 5 2))
19:10 < amalloy> justin_smith: i think ''lovecraft should contain (alter-var-root #'defmacro (constantly (fn [& args] `(quote ~(rand-nth '#{various lovecraftian horrors|)))))
19:11 < justin_smith> ouch
19:11 < amalloy> or something like it, anyawy
19:11 < justin_smith> yeah