Skip to content

Instantly share code, notes, and snippets.

View betawaffle's full-sized avatar

Andrew Hodges betawaffle

View GitHub Profile
package jscan
import (
"bytes"
"errors"
"fmt"
)
var (
errIncomplete = errors.New("json: incomplete token")
package main
import (
"bytes"
"crypto/sha1"
"encoding/hex"
"errors"
"fmt"
"io"
"io/ioutil"
@betawaffle
betawaffle / keybase.md
Last active June 6, 2016 00:36
Keybase Proof

Keybase proof

I hereby claim:

  • I am betawaffle on github.
  • I am betawaffle (https://keybase.io/betawaffle) on keybase.
  • I have a public key ASCb-r2xz37rjxp4POJ0VKHYiztV3uwpUKrIsFgzTKFvSAo

To claim this, I am signing this object:

@betawaffle
betawaffle / etcd-q-and-a.txt
Last active January 2, 2016 03:59
etcd Questions (and Answers)
Q: How do I remove a node from an etcd cluster?
A: We don't have a way to do that yet, but that functionality is slotted for the 0.3.0 series as part of the Cluster Management API.
Q: Can I count on a value I read from the slave always being a value that was at some point the current "true" value on the master?
A: Yes. Writes never go through the slaves.
Q: When reading from a slave that is in a minority partition, can I still read that (potentially old) value?
A: Yes.
Q: If each CoreOS machine has an etcd in the same cluster, doesn't that limit the number of CoreOS machines you can have?
@betawaffle
betawaffle / bug.rb
Last active December 29, 2015 00:49
Thread.new([1].to_enum) { |e| e.next while true }.join
class Timers
def initialize
@timers = SortedSet.new
@mutex = Mutex.new
@mutex.synchronize do
@thread = Thread.new { loop }
@thread.abort_on_exception = true
end
end
class BackoffTimer
class << self
def create(range, stepper, opts = {})
timer = new(intervals(range, stepper), opts[:immediate], opts[:callback] || Proc.new)
timer.start unless opts[:start] == false
timer
end
def exponential(range, opts = {})
opts[:callback] ||= Proc.new
class WaitGroup
def initialize(initial_count = 0)
@count = initial_count
@cond = ConditionVariable.new
@mutex = Mutex.new
end
def add(delta = 1)
synchronize do
count = @count += 1
@betawaffle
betawaffle / gist:7477418
Last active December 28, 2015 09:18 — forked from jsvd/gist:7477358
def format event
{ header, payload } = SomeModule.somefn(event)
join_results(format_header(header), format_payload(payload))
end
def format_header(header)
# do stuff
....
# and return
@betawaffle
betawaffle / actor.rb
Created October 24, 2013 12:16
Ruby Actors
require 'fiber'
require 'eventmachine'
module Actor
class << self
def current
Mailbox.current
end
end