Skip to content

Instantly share code, notes, and snippets.

@madlep
madlep / version_of_spec.rb
Created January 10, 2012 21:46
Breaking babushka spec for deps like "Google Chrome.app"
require 'spec_helper'
def version_of *args
Babushka::VersionOf::Helpers.VersionOf *args
end
describe "creation" do
it "should store name" do
version_of('ruby').name.should == 'ruby'
end
@madlep
madlep / gist:2464052
Created April 22, 2012 13:08
Well, this might explain why the PVT app is borked
192.168.1.102 GET https://chronos.jimbolos.com.au/v1/journey-planner/o/%5B-37.809002,144.895660%5D%7CSeddon%20Station/d/%5B-37.818310,144.966965%5D%7CFlinders%20Street%20Station?departFrom=true&transferMethod=walk&transferMaxTime=10&inclTrain=true&inclTram=true&inclBus=true&inclVline=true&inclRegCoach=true&inclSkybus=true&token=97A431C0AD983ACF6A31DCDAD9AEAD845239FD77
Host: chronos.jimbolos.com.au
User-Agent: PTV 1.0 rv:23032012 (iPhone; iPhone OS 5.1; en_AU)
Accept-Encoding: gzip
Connection: keep-alive
Proxy-Connection: keep-alive
<< 200 OK 977B
Cache-Control: private
@madlep
madlep / my-innodb-heavy-4g-install.sh
Created May 25, 2012 03:38
beef up default homebrew mysql install
#!/usr/bin/env bash
set -e
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
rm /usr/local/var/mysql/ib_logfile*
cp /usr/local/Cellar/mysql/5.5.19/support-files/my-innodb-heavy-4G.cnf /usr/local/etc/my.cnf
sed -i -e 's/innodb_buffer_pool_size.*/innodb_buffer_pool_size = 4G/' /usr/local/etc/my.cnf
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
@madlep
madlep / mysqldbimport.sh
Created June 20, 2012 22:51
Script to import a gzipped mysql backup, piping it through pv to give progress status
#!/usr/bin/env bash
set -e
if [ "$#" == "0" ]; then
echo "Usage mysqldbimport MYSQLGZIPPEDBACKUPFILE [args to pass to mysql]"
echo "e.g. mysqldbimport mybackup.sql.gz -u root my_database_name"
fi
BACKUP_FILE="$1"
shift
@madlep
madlep / 1 - curl on data node
Created August 23, 2012 02:01
Bug: _mlt on a document does not route properly on node clients
Thu 11:54:32 madlep@elastic1 ~
$ curl -XPUT 'http://localhost:9200/foo/bar/1' -d '{"foo":{"bar":"boz"}}'
{"ok":true,"_index":"foo","_type":"bar","_id":"1","_version":1}
Thu 11:56:21 madlep@elastic1 ~
$ curl -v "http://localhost:9200/foo/bar/1"
* About to connect() to localhost port 9200 (#0)
* Trying ::1... connected
* Connected to localhost (::1) port 9200 (#0)
> GET /foo/bar/1 HTTP/1.1
@madlep
madlep / db_table_sizes.sql
Created August 28, 2012 01:30
MySQL query to list table sizes (index + data) for each schema
SELECT
TABLE_NAME,
table_rows,
AVG_ROW_LENGTH,
data_length / 1024 /1024 / 1024 AS data_length_gb,
index_length / 1024 /1024 / 1024 AS index_length_gb,
(data_length / 1024 /1024 / 1024 + index_length / 1024 /1024 / 1024) AS total_length_gb
FROM information_schema.tables
ORDER BY table_schema, total_length_gb DESC;
@madlep
madlep / spearman.rb
Created November 21, 2012 21:58
Spearman’s rank correlation coefficient function
# xs & ys are arrays of results in order of rank
def spearman(xs, ys)
# remove items that aren't common to both result sets
# these are mostly outliers anyway which we want to ignore
xs_common = xs.select{|i| ys.include? i }
ys_common = ys.select{|i| xs.include? i }
# calculate the mean of each set of ranks (simple sum/length calculation)
# as both are just the sum of ranks [1,2,3,4...] and have same length,
# we can figure it out based on an arithmetic sum
@madlep
madlep / update_ruby_hash_syntax.sh
Created February 24, 2014 03:26
recursively update all files in a directory to ruby 1.9 hash syntax
# stolen from http://effectif.com/ruby/update-your-project-for-ruby-19-hash-syntax
find . -name \*.rb -exec perl -p -i -e 's/([^:]):(\w+)\s*=>/\1\2:/g' {} \;
@madlep
madlep / foobar.ex
Created November 17, 2015 10:34
which is preferable style: destructuring struct with pattern matching in function definition, or accessing struct members in function body?
defmodule Foobar do
defstruct :my_field, :another_field
def do_a_thing_destructure(%Foobar{my_field: mf, another_field: af}) do
something_else(mf, af)
end
def do_a_thing_struct_access(foobar = %Foobar{}) do
something_else(foobar.my_field, foobar.another_field)
end

Keybase proof

I hereby claim:

  • I am madlep on github.
  • I am madlep (https://keybase.io/madlep) on keybase.
  • I have a public key whose fingerprint is 6A92 159D 5E40 7094 FABE B73A 0B4D 44BE 816C C67C

To claim this, I am signing this object: