Skip to content

Instantly share code, notes, and snippets.

@evanphx
evanphx / json.conf
Created June 23, 2015 04:04
nginx json access log
log_format json '{'
'"host": "lb01", '
'"status": "$status", '
'"scheme": "$scheme", '
'"uri": "$request_uri", '
'"args": "$args", '
'"dest_host": "$http_host", '
'"content_type": "$sent_http_content_type", '
'"protocol": "$server_protocol", '
'"referer": "$http_referer", '
// Given
struct StackFrame {
VALUE* locals
}
N = local wanted
$1 = load getelementptr %struct.StackFrame, *%struct.StackFrame, 0, 0, N
@evanphx
evanphx / guide.txt
Created May 25, 2015 05:55
My self guided mediation routine
Laying in bed completely still, imagine yourself laying on the beach.
Feel yourself sunk slightly into the warm sand.
Feel the hot sun warming your body slightly, then a cool breeze wafts over you.
Hear the ocean just over the rise, the waves breaking on the beach.
Feel yourself sink into the sand a little more. As you do, feel your feet relax.
@evanphx
evanphx / 1test.go
Created May 2, 2015 05:21
Go pprof broken?
package main
import (
"fmt"
"os"
"runtime/pprof"
)
func main() {
f, err := os.Create("test.pprof")
@evanphx
evanphx / check.rb
Created April 30, 2015 17:21
Ruby "type" checking
def foo(a : String)
# the method prologue is injected with
raise TypeError unless String === a
end
# Allows for other interesting ones, like:
def use_as_number(a : /\d+/)
end
@evanphx
evanphx / 1.code
Last active August 29, 2015 14:18
you had one job stat
package main
import (
"fmt"
"os"
"syscall"
)
const path = "/home/vagrant/blah"
@evanphx
evanphx / cref.rb
Last active August 29, 2015 14:15
CREF for sclass shared between threads
num_threads = (ARGV[0] || 2).to_i
num_iterations = (ARGV[1] || num_threads).to_i
def url_helpers
Module.new do
class << self
# This line changes everything. It causes the GIL to switch to another
# thread. That other thread mutates the CREF that is accidentally shared
# between these independent sclass scopes, causing the def below to add
# the method on an entirely different sclass.
@evanphx
evanphx / gist:9caedb7dd11f8d5d89a1
Created January 26, 2015 23:47
on_fork advise
irb(main):003:0> require 'socket'
=> true
irb(main):004:0> s = TCPServer.new 9999
=> #<TCPServer:fd 10>
irb(main):005:0> Thread.new { s.accept }
=> #<Thread:0x007fedf33f0e88 run>
irb(main):006:0> c = TCPSocket.new "0.0.0.0", 9999
=> #<TCPSocket:fd 11>
irb(main):007:0> Process.fork { p $$ }
on_fork: Detected open IO at fork: #<TCPServer:0x007fedf33e8f08>
@evanphx
evanphx / ko1.rb
Created January 13, 2015 18:24
micro benchmarks with benchmark-ips
require 'benchmark'
require 'benchmark/ips'
outer_b = 0
Benchmark.ips do |x|
outer_a = 0
x.report "inner a block" do
inner_a = 1
end
type A interface {
Foo() int
}
type B interface {
Foo() int
}
type D interface {
Report(a A)