Skip to content

Instantly share code, notes, and snippets.


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
View task_job.rb
# 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 directly elsewhere (e.g. tests)
class TaskJob
def self.perform(id)
def initialize(task)
mperham / gc opts
Last active August 29, 2015 14:01
Ruby 2.1.2 memory bloat/leak
View gc opts
> pp {|x| x =~ /^RUBY/ }
csfrancis /
Last active July 26, 2022 16:25
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()
return s['as']['ary'].string()
scy /
Last active February 6, 2023 12:50
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 / gist:3651105
Created September 6, 2012 04:11
Campfire's SSL cert doesn't verify with Ruby 1.9.3 p194
View gist:3651105
# This works for me in 1.9.3-p125 but not in p194.
# Can anyone explain why?
require 'net/http'
http ="", 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request ="/login")
response = http.request(request)
raise response.inspect if response.code != '200'
mrflip /
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: