Skip to content

Instantly share code, notes, and snippets.

Jonathan Halterman jhalterman

Block or report user

Report or block jhalterman

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am jhalterman on github.
  • I am jhalterman (https://keybase.io/jhalterman) on keybase.
  • I have a public key whose fingerprint is 43F6 97A7 C494 AD19 CFCA 48F4 489D 4D97 977C 14CE

To claim this, I am signing this object:

View minscalaactors.scala
/*
Copyright 2012 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@jhalterman
jhalterman / ThreadAwareExceptionTest.java
Last active May 27, 2017
Experiments in thread aware exceptions
View ThreadAwareExceptionTest.java
import java.util.Arrays;
public class ThreadAwareExceptionTest {
static class ThreadAwareThread extends Thread {
Throwable entryPoint;
ThreadAwareThread(Runnable runnable) {
super(runnable);
}
@jhalterman
jhalterman / kvstore.sh
Last active Aug 11, 2016
The tiniest key / value store (from Designing Data-Intensive Applications: http://dataintensive.net)
View kvstore.sh
#!/bin/bash
db_set () {
echo "$1,$2" >> database
}
db_get () {
grep "^$1," database | sed -e "s/^$1,//" | tail -n 1
}
@jhalterman
jhalterman / MovingAverage.java
Last active Jan 6, 2019
An exponentially weighted moving average implementation that decays based on the elapsed time since the last update, approximating a time windowed moving average.
View MovingAverage.java
/**
* An exponentially weighted moving average implementation that decays based on the elapsed time since the last update,
* approximating a time windowed moving average.
*/
public class MovingAverage {
private final long windowNanos;
// Mutable state
private volatile long lastNanos;
private volatile double average;
@jhalterman
jhalterman / disable-highlighting.md
Created Mar 4, 2016
Disable syntax highlighting in Github pages
View disable-highlighting.md

Add the following to your _config.yml:

kramdown:
  syntax_highlighter_opts:
    disable : true
@jhalterman
jhalterman / gist:44d488ee7f7248ab728b
Last active Dec 8, 2015
How to replace the non-replaceable white base bulbs on a pre-lit GE Christmas tree
View gist:44d488ee7f7248ab728b
Pre-lit GE Christmas tree strands have a common failure - the white base bulbs may burn out, and unfortunately they are not intended to be replaced. Here's how to replace them.
* Cut a ring around the rim of the green plastic socket that the white bulb plugs into, just below the glass part of the bulb. I used a small hacksaw for this - it takes about 2 minutes. Once you've cut a ring, you should be able to pull the white bulb/insert out.
* Pull the glass part of the bulb out of the white base. It might help to fold down/straight the two copper wires first.
* Remove a glass insert from a replacement bulb and insert it into your white bulb base, then bend the two copper wires back into place.
* Re-insert the white bulb base and you're good to go.
Notes:
* Ostensibly, these bulbs are supposedly to limit the load on the strand, but a quick voltage test shows they don't really do anything special.
View try-until-success.clj
(defn try-until-success
"Accepts a try-fn to try a failure-fn to call upon failure, supplying the failure/exception. The try-fn is retried
until no failure is thrown."
[try-fn failure-fn]
(loop []
(if-let [result (try
(try-fn)
(catch Exception e
(failure-fn e)
nil))]
View jepsen-foundationdb-cas-test.clj
(deftest create-cas-test
(let [test (run!
(assoc
noop-test
:name "foundationdb"
:os ubuntu/os
:db db
:client (cas-register)
:model (model/cas-register)
:checker (checker/compose {:html timeline/html
View jepsen-foundationdb-cas-register.clj
:cas (timeout 5000 (assoc op :type :info :value :timed-out)
(let [cas (reify Function
(apply [this, tr]
(let [
[value value'] (:value op)
key_var (byte-array (map byte key))
old_value (.getLong (Tuple/fromBytes (.get (.get tr (byte-array (map byte key))))) 0)
new_value (.pack (Tuple/from (into-array [value'])))]
(if (= old_value value)
(do
You can’t perform that action at this time.