Skip to content

Instantly share code, notes, and snippets.

View mperham's full-sized avatar

Mike Perham mperham

View GitHub Profile
import httplib2
import argparse
import json
import mysql.connector
import time
import sys
import itertools
from joblib import Parallel, delayed
from apiclient.discovery import build
# This pattern avoids serializing a large object (the Task) to Redis, whilst
# avoiding passing a low-level data type (the id) into the constructor.
# You might choose to call TaskJob.new(task) directly elsewhere (e.g. tests)
class TaskJob
def self.perform(id)
new(Task.find(id)).perform
end
def initialize(task)
@mperham
mperham / gc opts
Last active August 29, 2015 14:01
Ruby 2.1.2 memory bloat/leak
> pp ENV.select {|x| x =~ /^RUBY/ }
{"RUBY_GC_HEAP_GROWTH_FACTOR"=>"1.3",
"RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR"=>"1.3",
"RUBY_GC_HEAP_INIT_SLOTS"=>"600000",
"RUBY_GC_MALLOC_LIMIT"=>"90000000",
"RUBYOPT"=>"-rbundler/setup",
"RUBYLIB"=>
"/usr/local/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib"}
@csfrancis
csfrancis / gdb_ruby_backtrace.py
Last active June 25, 2024 19:12
Dump an MRI call stack from gdb
# Updated for Ruby 2.3
string_t = None
def get_rstring(addr):
s = addr.cast(string_t.pointer())
if s['basic']['flags'] & (1 << 13):
return s['as']['heap']['ptr'].string()
else:
return s['as']['ary'].string()
@scy
scy / opening-and-closing-an-ssh-tunnel-in-a-shell-script-the-smart-way.md
Last active November 24, 2024 21:24
Opening and closing an SSH tunnel in a shell script the smart way

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

@mperham
mperham / gist:3651105
Created September 6, 2012 04:11
Campfire's SSL cert doesn't verify with Ruby 1.9.3 p194
# This works for me in 1.9.3-p125 but not in p194.
# Can anyone explain why?
require 'net/http'
http = Net::HTTP.new("theclymb1.campfirenow.com", 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request = Net::HTTP::Get.new("/login")
response = http.request(request)
raise response.inspect if response.code != '200'
@mrflip
mrflip / maximum_battery_life.md
Created March 19, 2012 08:32
maximum battery life checklist -- use before a long plane flight

Max Battery Life Checklist

Here is a checklist to follow if you want maximum battery life -- for instance if you're about to get on a long plane flight.

10 hour battery life on a non-SSD Macbook Pro 17"

Low power use checklist

With power connected: