Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Kahn akahn

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@akahn
akahn / bash_power.txt
Last active Mar 23, 2020
Some helpful keyboard shortcuts for bash
View bash_power.txt
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 Dec 6, 2018
Advent of Code 2018
View 3.rb
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 = ''
View gist:6c743a3c64ce2488176f6560cbc9224f
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
View notifier.rb
[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
View codeadvent1.hs
input = "()(((()))(()()()((((()(((())(()(()((((((()(()(((())))((()(((()))((())(()((()()()()(((())(((((((())))()()(()(()(())(((((()()()((())(((((()()))))()(())(((())(())((((((())())))(()())))()))))()())()())((()()((()()()()(()((((((((()()())((()()(((((()(((())((())(()))()((((()((((((((())()((()())(())((()))())((((()())(((((((((((()()(((((()(()))())(((()(()))())((()(()())())())(()(((())(())())()()(()(()((()))((()))))((((()(((()))))((((()(()(()())())()(((()((((())((((()(((()()(())()()()())((()((((((()((()()))()((()))()(()()((())))(((()(((()))((()((()(()))(((()()(()(()()()))))()()(((()(((())())))))((()(((())()(()(())((()())))((((())))(()(()(()())()((()())))(((()((()(())()()((()((())(()()((())(())()))()))((()(())()))())(((((((()(()()(()(())())))))))(()((((((())((((())((())())(()()))))()(())(()())()())((())(()))))(()))(()((()))()(()((((((()()()()((((((((()(()(())((()()(()()))(())()())()((())))()))()())(((()))(())()(())()))()((()((()(()()())(())()()()((())())))((()()(()()((()(())()()())(((()(()()))))(())))(()(()())(
View wakeup.rb
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 Jun 22, 2015
Sequel errors added in after_validation don't prevent save
View gist:b52d42b82437dfd02786
# 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"]}
View cellular.hs
module Cellular where
import System.Random
import Data.List.Split
import Data.Maybe
isWall False = '.'
isWall True = '#'
mapWithIndex :: (Enum a, Num a) => (a -> b -> c) -> [b] -> [c]
@akahn
akahn / elasticsearch.sh
Created Nov 5, 2013
Trying to understand elasticsearch's schema and types
View elasticsearch.sh
$ curl -XPOST http://localhost:9200/myindex/mytype -d '{"foo": ["bar"]}'
{"ok":true,"_index":"myindex","_type":"mytype","_id":"YYfPUL3TQLaL17zhXQ-ELw","_version":1}
$ curl -XPOST http://localhost:9200/myindex/mytype -d '{"foo": [{"foo": "bar"}]}'
{"error":"MapperParsingException[Failed to parse [foo]]; nested: ElasticSearchIllegalArgumentException[unknown property [foo]]; ","status":400}
$ curl -XDELETE http://localhost:9200/myindex/mytype
{"ok":true}
$ curl -XPOST http://localhost:9200/myindex/mytype -d '{"foo": [{"foo": "bar"}]}'