Skip to content

Instantly share code, notes, and snippets.

@evanphx
evanphx / eat.rb
Created October 15, 2014 23:23
Eat memory
mem = 1024 * 1024
ary = []
i = 0
loop {
p i
ary << (" " * mem)
i += 1
}
@evanphx
evanphx / enable_zram.sh
Last active August 29, 2015 14:07
Enable zram swap with 512Mb
modprobe zram
echo 512M > /sys/block/zram0/disksize
mkswap /dev/zram0
swapon /dev/zram0
@evanphx
evanphx / eat_rando.rb
Created October 15, 2014 23:25
Eat memory filled with random data
mem = 1024 * 1024
ary = []
i = 0
seed = (0..mem).map { rand(255) }.pack("C*")
loop {
p i
x = seed.dup
@evanphx
evanphx / enable_zram.sh
Created October 15, 2014 23:26
Enable zram
modprobe zram num_devices=1
totalmem=`free | grep -e "^Mem:" | sed -e 's/^Mem: *//' -e 's/ *.*//'`
mem=$(((totalmem / 2) * 1024))
echo $mem > /sys/block/zram0/disksize
mkswap /dev/zram0
swapon -p 5 /dev/zram0
@evanphx
evanphx / gist:358c1627b69f7a33fca6
Created October 29, 2014 16:54
Tachyon installer with hash verification
curl http://tachyon.vektra.io/install.sh > it.sh && test $(openssl sha1 < it.sh) = "23fb0450b152dfaa8331dd37c3a4c13d4de9dbb8" && bash it.sh
type A interface {
Foo() int
}
type B interface {
Foo() int
}
type D interface {
Report(a A)
@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
@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>
<match path="project"> rubinius </match>
<formatter medium="irc">
<lineLimit>1</lineLimit>
<wrapWidth>150</wrapWidth>
<widthLimit>150</widthLimit>
<crunchWhitespace/>
<format appliesTo="CommitToIRC">
hoshi :: /var/log>
Message from syslogd@hoshi at Fri Aug 1 10:02:17 2008 ...
hoshi kernel: [172392.427177] Uhhuh. NMI received for unknown reason 3c on CPU 0.
Message from syslogd@hoshi at Fri Aug 1 10:02:17 2008 ...
hoshi kernel: [172392.431038] Do you have a strange power saving mode enabled?
Message from syslogd@hoshi at Fri Aug 1 10:02:17 2008 ...
hoshi kernel: [172392.431038] Dazed and confused, but trying to continue