Skip to content

Instantly share code, notes, and snippets.

View spraints's full-sized avatar
🦦

Matt Burke spraints

🦦
View GitHub Profile
#/ Usage: ruby timeout.rb <seconds> -- command arg arg arg
timeout, separator, *command = ARGV
timeout = timeout.to_f
if timeout <= 0.0 || separator != '--' || command.empty?
system "cat #$0 | grep ^#/ | cut -c4-"
exit 1
end
trap(:CHLD) { exit 0 }
@spraints
spraints / Gemfile
Last active December 30, 2015 21:49
Demonstrate memory use of streaming HTTP clients in ruby.
source 'https://rubygems.org'
# Graph memory use.
gem 'stripmem'
gem 'typhoeus', :git => 'https://github.com/spraints/typhoeus', :ref => 'stream'
gem 'ethon', :git => 'https://github.com/spraints/ethon', :ref => 'streaming'
gem 'em-http-request'
worker_pool 6
queue '*'
before_fork do
require File.expand_path('config/environment')
Rails.application.eager_load!
ActiveRecord::Base.connection.disconnect!
end
@spraints
spraints / application_controller.rb
Created August 14, 2013 17:45
Rails cache + dom manip testing, based on http://www.twmagic.com/misc/cache.html
# add this to app/controllers/application_controller.rb:
def cache
options = {
'no-store' => 'no-store',
'no-cache' => 'no-cache',
'zero-age' => 'max-age=0',
}
if cc = options[params[:id]]
headers['Cache-Control'] = cc
end
@spraints
spraints / 00.rb
Created June 17, 2013 23:30
Optimization doesn't always work.
require 'multi_json'
require 'stringio'
require 'zlib'
def gz(infile)
outfile = infile + '.gz'
File.open(outfile, 'w') do |f|
f << `gzip -9 -c #{infile}`
end
outfile
20:09:53 (0) [master] >>> cat
]
==
]]]]]
^[[B\\\\=]
\\\\=]
'[
'\\'\\\\
'\\;'[-0kkkkkkkkkk[i-k-=k;/. \\m[''''
@spraints
spraints / my-haunts.md
Created May 19, 2013 20:21
Places around town where you can find me. Come say hi, introduce yourself, and learn about GitHub or food.
Farmers Marketmarket at Normandy Farms, 79th and Marsh Rd, Fridays, 4-7 pm Carmel Farmers Market, Saturdays 8:00 a 11:30 am Code @ Coffee (Carmel or Fishers)
#!/bin/sh
# Make sure sudoing works first, because tcpdump is going in the background
sudo -p "Root privileges are required in order to run tcpdump. Password: " test
pcap=$TMPDIR/nethog.$$.pcap
# 10.0.1.1 is my LAN's AirPort Extreme, so it gets lots of backup traffic.
sudo tcpdump -i en0 -w $pcap not host 10.0.1.1 >&/dev/null &
tcpdump_pid=$!
@spraints
spraints / gist:5362874
Created April 11, 2013 12:09
fun with procs, blocks, and lambdas
def a
[1,2,3].each do |x|
return :a if x == 2
end
:not_a
end
def a2
block = lambda { |x| return :a if x == 2 }
[1,2,3].each(&block)
original:
T1 ----- T2 ----- T3 ----- T4
\
----- G1 ----- G2
after rcheckin, how it works now:
T1 ----- T2 ----- T3 ----- T4 ----- G1' ----- G2'