Skip to content

Instantly share code, notes, and snippets.

destroy_instance.rb:
#!/usr/bin/env ruby
EventBusWorker.new do |e|
msg = e.publish 'destroy_instance', {:id => ARGV[1]}
e.wait_for 'aws_destroyed', {:req => msg}
e.wait_for 'scout_removed', {:req => msg}
end
aws_destroyed.rb:
> class A
* def a
* "foo"
* end
* def bind
* binding
* end
* def run
* yield bind
* end
require 'benchmark'
short_array = [1, 2, 3, 4, 1, 2, 5, 6]
long_array = ([1] * 1000) + short_array
short_match = [1, 2, 5]
long_match = short_match * 10
class Array
def find_sub_1(match)
(each_cons(match.size).with_index.find {|x, i| x == match } || []).last
def find_first a, b
0.upto(a.length-b.length) do |i|
catch :fail do
0.upto(b.length-1) do |j|
throw :fail unless a[i+j] == b[j]
end
return i
end
end
nil
0.000206443 Assembly
0.000210307 C (musl, static)
0.000210635 C (diet, static)
0.000270350 C (musl, dynamic)
0.000273091 C (static)
0.000317843 Fortran (static)
0.000352856 BusyBox shell
0.000432001 C (dynamic)
0.000550067 dash
0.000594262 MLton
{"foo": [
{"bar": "-4"},
{"bar": "::1"}
]}
@pcarrier
pcarrier / gist:4639579
Last active December 11, 2015 18:09
"Hardlink" a tree
package main
import (
"flag"
"log"
"os"
"path"
)
var src = flag.String("src", "/usr", "source path")
@pcarrier
pcarrier / gist:4498154
Last active December 10, 2015 21:58
/etc/X11/xorg.conf.d/99-macbookair.conf
Section "InputClass"
Identifier "touchpad catchall"
MatchIsTouchpad "on"
Driver "synaptics"
Option "PalmDetect" "on"
EndSection
@pcarrier
pcarrier / gist:4497877
Last active December 10, 2015 21:48
ISOs for Macbook without optical drive
Q: Does this Linux ISO support booting off a USB pendrive on a Mac EFI?
(I don't want no BIOS jail, that shit drove me insane about 8 hours ago and I'm out of coffee now)
A: Simple! Yes if it starts with ER. No if it doesn't start with ER.
Examples:
% (dd bs=8 count=1 2>/dev/null|xxd) < Fedora-17-x86_64-Live-Desktop.iso
0000000: 4552 0800 0000 9090 ER......
===> That's a yes.
Trying to be "idiomatic" yet fair. Used JD GUI to show the bytecode in human-readable Java.
Somehow mirah breaks JD GUI, which is probably interesting.
So I went through an intermediate Java file thanks to mirah -j instead.