Skip to content

Instantly share code, notes, and snippets.

View akahn's full-sized avatar

Alex Kahn akahn

View GitHub Profile
package main
import (
"io"
"log"
"net/http"
"time"
)
func main() {
package main
import (
"encoding/binary"
"encoding/hex"
"log"
"runtime"
"sync"
"sync/atomic"
"time"

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@akahn
akahn / bash_power.txt
Last active March 23, 2020 15:55
Some helpful keyboard shortcuts for bash
Jump forward/back one word
alt-b/alt-f
Go to beginning/end of line
^a/^e
Delete to beginning of command
^u
Navigate through history of commands (this works in many places in OS X)
@akahn
akahn / 3.rb
Last active December 6, 2018 21:57
Advent of Code 2018
require 'strscan'
require 'pry'
class Sheet
def initialize(x, y, initial = 0)
@matrix = Array.new(y) { (Array.new(x) { initial }) }
end
def to_s
s = ''
May 31 14:30:00 l2met-prod-38 l2met-log: 2016/05/31 18:30:00 receiver.go:540: LOGGED_METRIC_IN: [daniel@dubsmash.com] name=dubsmash.password_recovery.send_mail_returns_1 source=dubsmash vals=[1]
May 31 14:30:01 l2met-prod-32 l2met-log: 2016/05/31 18:30:01 receiver.go:540: LOGGED_METRIC_IN: [daniel@dubsmash.com] name=dubsmash.password_recovery.send_mail_returns_1 source=dubsmash vals=[1]
May 31 14:30:02 l2met-prod-35 l2met-log: 2016/05/31 18:30:01 receiver.go:540: LOGGED_METRIC_IN: [daniel@dubsmash.com] name=dubsmash.password_recovery.send_mail_returns_1 source=dubsmash vals=[1]
May 31 14:30:02 l2met-prod-39 l2met-log: 2016/05/31 18:30:02 receiver.go:540: LOGGED_METRIC_IN: [daniel@dubsmash.com] name=dubsmash.password_recovery.send_mail_returns_1 source=dubsmash vals=[1]
May 31 14:30:03 l2met-prod-33 l2met-log: 2016/05/31 18:30:03 receiver.go:540: LOGGED_METRIC_IN: [daniel@dubsmash.com] name=dubsmash.password_recovery.send_mail_returns_1 source=dubsmash vals=[1]
May 31 14:30:05 l2met-prod-33 l2met-log: 20
[Producer.new(pool, notifications_east, Notifier).thread,
Producer.new(pool, notifications_west, Annotator).thread,
Producer.new(pool, annotations_east, Annotator).thread,
Producer.new(pool, annotations_west, Annotator).thread].each &:join
input = "()(((()))(()()()((((()(((())(()(()((((((()(()(((())))((()(((()))((())(()((()()()()(((())(((((((())))()()(()(()(())(((((()()()((())(((((()()))))()(())(((())(())((((((())())))(()())))()))))()())()())((()()((()()()()(()((((((((()()())((()()(((((()(((())((())(()))()((((()((((((((())()((()())(())((()))())((((()())(((((((((((()()(((((()(()))())(((()(()))())((()(()())())())(()(((())(())())()()(()(()((()))((()))))((((()(((()))))((((()(()(()())())()(((()((((())((((()(((()()(())()()()())((()((((((()((()()))()((()))()(()()((())))(((()(((()))((()((()(()))(((()()(()(()()()))))()()(((()(((())())))))((()(((())()(()(())((()())))((((())))(()(()(()())()((()())))(((()((()(())()()((()((())(()()((())(())()))()))((()(())()))())(((((((()(()()(()(())())))))))(()((((((())((((())((())())(()()))))()(())(()())()())((())(()))))(()))(()((()))()(()((((((()()()()((((((((()(()(())((()()(()()))(())()())()((())))()))()())(((()))(())()(())()))()((()((()(()()())(())()()()((())())))((()()(()()((()(())()()())(((()(()()))))(())))(()(()())(
require 'thread'
t = Thread.current
Thread.new do
puts 'starting server, takes a few seconds'
# return control to main thread
t.wakeup
end
@akahn
akahn / gist:b52d42b82437dfd02786
Created June 22, 2015 15:17
Sequel errors added in after_validation don't prevent save
# Validations added in an instance hook:
model.after_validation_hook { model.errors.add("random_attribute", 'Unrecognized attribute') }
# Later:
> model.valid?
=> false
> model.errors
=> {"random_attribute"=>["Unrecognized attribute"]}