Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Sonnabaum msonnabaum

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am msonnabaum on github.
  • I am msonnabaum (https://keybase.io/msonnabaum) on keybase.
  • I have a public key ASAglXeQJzr-CGEUgFL8hJIrd_NFs5TFViA2uHH9i5s7wQo

To claim this, I am signing this object:

View stackfilter-perf.rb
#!/usr/bin/env ruby
require "optparse"
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename __FILE__} [options]"
opts.on "-p", "--process-names [process names]", "Process names to filter" do |v|
options[:process_names] = v.split(",")
end
end.parse!
View who_posts_the_most.kts
// Download the twitter4j jar:
// wget http://twitter4j.org/maven2/org/twitter4j/twitter4j-core/4.0.4/twitter4j-core-4.0.4.jar
// Fill out the key/token/secrets
// Run the script
// kotlinc -script -classpath ./twitter4j-core-4.0.4.jar who_posts_the_most.kts|sort -n
import twitter4j.Status
import twitter4j.Twitter
import twitter4j.TwitterException
import twitter4j.TwitterFactory
View heap_dump.rb
require "objspace"
trap "USR2" do |signo|
Thread.new {
ObjectSpace.trace_object_allocations_start
GC.start
ObjectSpace.dump_all output: File.open("/tmp/heap-#{Time.now.to_i}.json", "w")
}.join
end
View reduce_wtf.js
[1,2,3].reduce(function(memo, current) {
console.log(memo);
}, {});
// > {}
// > undefined
// > undefined
View test.php
<?php
$application['kernel'] = $application->share(
$application->extend('kernel', function ($kernel, $app) {
return new YourNewHttpKernelInterfaceObject($kernel);
})
);
View wait_until.go
func WaitUntil(f func() bool, seconds int) {
done := make(chan bool)
go func() {
time.Sleep(time.Duration(seconds) * time.Second)
done <- true
}()
go func() {
for {
if f() {
done <- true
View fix-dstat-csv
#!/usr/bin/env ruby
require "csv"
def fix_dstat_csv(file)
dstat_csv = CSV.read file
# Shift off useless metadata rows
dstat_csv.shift 5
# dstat spreads the headers out over two rows, which R does not like, so
View lm.thrift
namespace go thriftgen
namespace rb LatencyMetricsThrift
struct LatencyMetric {
1: string timestamp,
2: required string product,
3: required string host,
4: required string metric,
5: string environment,
6: required double value,
View flatten_json
#!/usr/bin/env ruby
require "json"
def flatten_hash(hash, parent_key = "")
result_hash = {}
hash.each do |key, value|
if value.is_a? Hash
result_hash.merge! flatten_hash(value, key)
else
result_key = if parent_key.empty? then key else "#{parent_key}.#{key}" end