Skip to content

Instantly share code, notes, and snippets.

View slyphon's full-sized avatar

Jonathan Simms slyphon

View GitHub Profile
class Module
# Use this to replace a method in an alias_method_chain
def inject_alias_method_chain(target, method_to_replace, method_to_use)
method_instance_to_replace = instance_method(method_to_replace)
meths = (private_instance_methods | instance_methods).sort.grep(/^#{target}/)
found = meths.detect do |m|
m != method_to_replace.to_s && instance_method(m) == method_instance_to_replace
end
if found
alias_method found, method_to_use
#
# Ideas stolen from lograge and brought to Rails 2.3
# https://github.com/mattmatt/lograge/blob/master/lib/lograge/log_subscriber.rb
#
module ImprovedControllerLogging
def self.included(base)
base.alias_method_chain :log_processing, :fixup
base.inject_alias_method_chain :perform_action,
:perform_action_with_benchmark,
#
# Ideas stolen from lograge and brought to Rails 2.3
# https://github.com/mattmatt/lograge/blob/master/lib/lograge/log_subscriber.rb
#
module ImprovedControllerLogging
def self.included(base)
base.alias_method_chain :log_processing, :fixup
base.inject_alias_method_chain :perform_action,
:perform_action_with_benchmark,
class Module
# Use this to replace a method in an alias_method_chain
def inject_alias_method_chain(target, method_to_replace, method_to_use)
method_instance_to_replace = instance_method(method_to_replace)
meths = (private_instance_methods | instance_methods).sort.grep(/^#{target}/)
found = meths.detect do |m|
m != method_to_replace.to_s && instance_method(m) == method_instance_to_replace
end
if found
alias_method found, method_to_use
@capotej
capotej / load-test.rb
Last active December 10, 2015 07:18
basic skeleton for executing tasks in parallel in jruby
require 'java'
java_import 'java.util.concurrent.ThreadPoolExecutor'
java_import 'java.util.concurrent.TimeUnit'
java_import 'java.util.concurrent.LinkedBlockingQueue'
java_import 'java.util.concurrent.FutureTask'
java_import 'java.util.concurrent.Callable'
java_import 'java.util.concurrent.Executors'
### SETTINGS
@wickman
wickman / bootstrap_python.sh
Last active December 17, 2015 04:29
python distro bootstrapper for osx
INSTALL_ROOT=$HOME/Python
CPY=$INSTALL_ROOT/CPython
PYPY=$INSTALL_ROOT/PyPy
SANDBOX=$(mktemp -d /tmp/python.XXXXXX)
CURL='wget --no-check-certificate'
mkdir -p $INSTALL_ROOT
@evnm
evnm / test_changed
Last active December 28, 2015 11:19
A Ruby script that runs tests with Pants for all projects that have been modified in the current working tree.
#!/usr/bin/env ruby
#
# Run tests for all projects that have been modified in the Birdcage,
# relative to HEAD.
#
# For example, if you've edited files in three projects, this script will
# run tests serially for these three projects in one command.
print "Determining which files have been changed..."
$stdout.flush
@bdd
bdd / gcb
Last active December 29, 2015 07:29 — forked from evnm/gcb
a shorter, faster and a bit more helpful version of gcb.sh
#! /bin/sh
match=`git rev-parse --abbrev-ref --branches="*$1*"`
case `wc -w <<< "$match" | tr -d ' '` in
"0") echo "error: '$1' did not match any branch." 2>&1 ;;
"1") git checkout $match ;;
*) echo "error: '$1' is ambigious among:\n$match" 2>&1
esac
@simeonf
simeonf / pex.md
Last active July 5, 2024 06:19
Creating a PEX from a python script

So you want to create a pex that packages your script and its dependencies?

Ok - first to make our script! Call it foo.py:

import requests

if __name__ == '__main__':
  req = requests.get("https://raw.githubusercontent.com/pantsbuild/pex/master/README.rst")
  print req.text.split("\n")[0]
sudo modprobe pcspkr
sudo beep -l 350 -f 392 -D 100 --new -l 350 -f 392 -D 100 --new -l 350 -f 392 -D 100 --new -l 250 -f 311.1 -D 100 --new -l 25 -f 466.2 -D 100 --new -l 350 -f 392 -D 100 --new -l 250 -f 311.1 -D 100 --new -l 25 -f 466.2 -D 100 --new -l 700 -f 392 -D 100 --new -l 350 -f 587.32 -D 100 --new -l 350 -f 587.32 -D 100 --new -l 350 -f 587.32 -D 100 --new -l 250 -f 622.26 -D 100 --new -l 25 -f 466.2 -D 100 --new -l 350 -f 369.99 -D 100 --new -l 250 -f 311.1 -D 100 --new -l 25 -f 466.2 -D 100 --new -l 700 -f 392 -D 100 --new -l 350 -f 784 -D 100 --new -l 250 -f 392 -D 100 --new -l 25 -f 392 -D 100 --new -l 350 -f 784 -D 100 --new -l 250 -f 739.98 -D 100 --new -l 25 -f 698.46 -D 100 --new -l 25 -f 659.26 -D 100 --new -l 25 -f 622.26 -D 100 --new -l 50 -f 659.26 -D 400 --new -l 25 -f 415.3 -D 200 --new -l 350 -f 554.36 -D 100 --new -l 250 -f 523.25 -D 100 --new -l 25 -f 493.88 -D 100 --new -l 25 -f 466.16 -D 100 --new -l 25 -f 440 -D 100 --new -l 50 -f 466.16 -D 400 --new -l 25 -f 311.13 -D 200 --ne