Skip to content

Instantly share code, notes, and snippets.

View lukeasrodgers's full-sized avatar

Luke Rodgers lukeasrodgers

View GitHub Profile
@lukeasrodgers
lukeasrodgers / DOMSubtreeModified_logger.js
Last active December 12, 2015 10:19
log dom subtree modifications to the console (works in Chrome, not sure of other browsers)
document.body.addEventListener('DOMSubtreeModified', function(e) { console.log(e.target); });
@lukeasrodgers
lukeasrodgers / mysql_export_import.sh
Last active December 12, 2015 10:18
mysql dumping and importing
mysqldump DB -hHOST > OUTFILE.sql
# copy to local
rsync -avPz --progress USER@HOST:/PATH/TO/OUTFILE.sql .
# import to local db
mysql -uroot -p -DDATABASE < OUTFILE.sql
@lukeasrodgers
lukeasrodgers / quickrubyprof.rb
Created October 15, 2015 17:15
quick ruby profiling
# Gemfile
gem 'ruby-prof'
# code to profile
require 'ruby-prof'
RubyProf.start
# run code
result = RubyProf.stop
printer = RubyProf::CallStackPrinter.new(result)
@lukeasrodgers
lukeasrodgers / monkeypatch_ar_mysql_collation_charset.rb
Created October 6, 2015 21:02
monkeypatch active record mysql adapter to understand collation, charset
# this is ugly and terrible, don't do this
module ActiveRecord
module ConnectionAdapters
class TableDefinition
def column(name, type, options = {})
name = name.to_s
type = type.to_sym
column = self[name] || new_column_definition(@base, name, type)
@lukeasrodgers
lukeasrodgers / jsfactories.js
Last active August 29, 2015 14:16
simple js factories using builder pattern
/**
* Builder pattern for factories, mimic use of FactoryGirl traits.
* usage: factories.boostedBoost({retweets: 1}).twitter().withdrawn().geo(11217).generate();
* must call `generate` as last step
* may pass options to initial method call, as well as subsequent method calls
*/
function addFactory(factoryName, config) {
// add trait function to generated Factory
function addTrait(k, Factory, config) {
Factory.prototype[k] = function() {
@lukeasrodgers
lukeasrodgers / puma_perf_get
Created December 17, 2014 01:34
puma perf testing JSON API GET
Benchmarking 127.0.0.1 (be patient)
Finished 450 requests
Server Software:
Server Hostname: 127.0.0.1
Server Port: 3080
Document Path: /api/v1/users/1/cabinets/1/drinks
Document Length: 801 bytes
@lukeasrodgers
lukeasrodgers / unicorn_perf_get
Created December 17, 2014 01:13
unicorn perf testing JSON API GET
Benchmarking 127.0.0.1 (be patient)
Finished 199 requests
Server Software:
Server Hostname: 127.0.0.1
Server Port: 3080
Document Path: /api/v1/users/1/cabinets/1/drinks
Document Length: 801 bytes
@lukeasrodgers
lukeasrodgers / thin_perf_get
Last active August 29, 2015 14:11
thin perf testing JSON API GET
Benchmarking 127.0.0.1 (be patient)
Finished 390 requests
Server Software: thin
Server Hostname: 127.0.0.1
Server Port: 3080
Document Path: /api/v1/users/1/cabinets/1/drinks
Document Length: 801 bytes
@lukeasrodgers
lukeasrodgers / webrick_perf_get
Last active August 29, 2015 14:11
webrick perf testing JSON API GET
Benchmarking 127.0.0.1 (be patient)
Finished 448 requests
Server Software: WEBrick/1.3.1
Server Hostname: 127.0.0.1
Server Port: 3080
Document Path: /api/v1/users/1/cabinets/1/drinks
Document Length: 801 bytes
@lukeasrodgers
lukeasrodgers / take_select.rb
Created September 18, 2014 19:19
ruby take_select
class Array
def take_select n, &block
count = 0
res = []
select do |x|
r = yield x
if r == true
count += 1
res << x
end