Skip to content

Instantly share code, notes, and snippets.

View timmc's full-sized avatar

Tim McCormack timmc

View GitHub Profile
#!/bin/bash
echo "DO NOT USE -- incorrect signature format, see comments on gist."
exit 1
@timmc
timmc / bisect.sh
Last active January 20, 2017 17:23
bisect and lein template
#!/bin/bash
cd ./PATH/TO/PROJECT/BASE
export LEIN_FAST_TRAMPOLINE=true
lein clean
lein trampoline compile || {
echo "Build failed."
exit 125
}
@timmc
timmc / o-sc-reduce.clj
Last active December 19, 2016 18:19
Short-circuiting reduce with RxJava
(require '[rx.lang.clojure.core :as rx])
(defn o-sc-reduce
"Perform a short-circuiting reduce on a series of Observables.
Reduces the series of Observables using the reduction function `f`,
starting the accumulator with `init`. Inputs to the reduction are
provided by subscribing to the input Observables serially, similar to
concat. If at any point (including the initial value) the accumulator
satisfies `final?`, emit the accumulator, complete, and do not

Port-forwarding JMX

Proof of concept:

  • Terminal 1:
    • SSH to remote host
    • Start a Java process with JMX registry port 50004, RMI callback port 50005, and RMI hostname pinned to localhost: java -Dcom.sun.management.jmxremote.port=50004 -Dcom.sun.management.jmxremote.rmi.port=50005 -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -cp /some/jar/file main.class
  • Terminal 2:
@timmc
timmc / gist:cbf503895f08dc39f3bc471aaa5e068a
Last active December 22, 2022 12:36
Code review checklist
Have the following been addressed in the branch, if appropriate?
- Tests (unit, API, integration)
- Docs (both in source and in docs directory, and in public docs if separate)
- Changelog
- Compatibility with previous versions (calls, shared files or DBs, data formats -- backward and forward compatibility)
- Rollback friendly?
- Feature switches?
(ns adhoc.java-types
"Count the amount of space taken up by types in Java code. Problems:
- Not actually a parser! Counts contents of comments!
- Willovercount in code that is heavy in STATIC_FIELDS
- Doesn't capture generics, arrays, and other non-alphabetic type
characters"
(:require [clojure.java.io :as io]
[clojure.string :as str])
(:import java.io.File
@timmc
timmc / Deleting reddit comments.js
Last active June 16, 2023 18:20
Script to delete all reddit comments on the *current page* when viewing own comment history. Quick and dirty approach if you don't have more than a few hundred comments.
function deleteAllOnPage(comments, index) {
var id = comments[index]
if (!id) return
console.debug('wiping ' + id)
$.ajax({
type: 'POST',
url: '/api/editusertext',
data: {
thing_id: id,
;; I needed some lorem ipsum names for a graph of microservices...
user=> (def words (set (clojure.string/split-lines (slurp "/usr/share/dict/words"))))
#'user/words
user=> (keep #(words (str % (last %) "er")) words)
("skipper" "stopper" "bragger" "glummer" "mapper" "tranquiller" "banner" "nipper" "clapper" "rubber" "chipper" "eavesdropper" "robber" "scatter" "madder" "canvasser" "supper" "carpetbagger" "beginner" "cheerfuller" "glibber" "snapper" "trimmer" "fitter" "pettifogger" "blotter" "patter" "transmitter" "plummer" "adder" "offer" "carefuller" "primmer" "cropper" "upper" "woodcutter" "shimmer" "bitter" "spotter" "potter" "tipper" "spitefuller" "putter" "clipper" "eviller" "drabber" "cotter" "mugger" "jabber" "traveller" "jobber" "gunner" "summer" "better" "shutter" "miller" "chatter" "hotter" "slammer" "chiseller" "jogger" "flatter" "pepper" "loyaller" "matter" "stirrer" "hopper" "runner" "hipper" "flipper" "funner" "dunner" "Donner" "ripper" "totter" "logger" "wrapper" "swimmer" "dipper" "mummer" "h
@timmc
timmc / to-bits.clj
Created June 19, 2016 04:56
Incomplete implementation of conversion to binary in swearjure
;; Still needs assoc translated... everything else is trivial.
(defn to-bits
"Yield a map of place indexes to bit values as booleans. Why a map
instead of a vector? Because I can't safely address beyond the end of
a vector when carrying to a new place value."
[n]
(#(((% 1) :main) %)
[n
{:main #(((% 1) :count-up) [(% 0) (% 1) 0 {0 false}]),
@timmc
timmc / even.clj
Created June 19, 2016 04:24
even or odd in swearjure
;; Apologies for the quasi-swearjure
(#(((% 1) :main) %)
[9
{:main #(((% 1) :count-up) [(% 0) (% 1) 0 true]),
:count-up #(if (= (% 0) (% 2))
(% 3)
(((% 1) :count-up) [(% 0) (% 1)
(+ 1 (% 2))
(if (% 3) false true)]))}])