Skip to content

Instantly share code, notes, and snippets.

View bhenderson's full-sized avatar

Brian Henderson bhenderson

View GitHub Profile
@bhenderson
bhenderson / ncpipe
Last active December 18, 2015 22:08
NetCat (nc) pipe. Using coproc available in bash 4.
#!/bin/bash
server=$1
port=$2
lport=${3:=$port}
# stdout will be server
# stderr will be client
exec 3>&1
@bhenderson
bhenderson / server.rb
Created May 14, 2013 15:15
testing rdoc sinatra methods.
class Foo
##
# Public: This is my foo route
#
# See #/bar for examples (but it doesn't link)
# But this[#baz] does
get '/foo' do
end
gem install image_science -v 1.2.3
gem install image_science -v 1.2.4
export INLINEDIR=/tmp/.ruby_inline
ruby -e "gem 'image_science', '1.2.3'; require './test_inline.rb'"
ruby -e "gem 'image_science', '1.2.4'; require './test_inline.rb'"
rm -rf /tmp/.ruby_inline
@bhenderson
bhenderson / a.rb
Created February 26, 2013 04:40 — forked from tenderlove/a.rb
module A
def test_whatever
flunk 'sucks'
end
end
##
# This method gets doc'd
#
# :method: foo
add_my_method :cool, :method
##
# This method does not get doc'd
#
@bhenderson
bhenderson / gist:4142461
Created November 25, 2012 05:08
connection pooling
require 'thread'
class ThreadPool
##
# Should the worker threads abort on exception? default: false
attr_reader :abort_on_exception
##
@bhenderson
bhenderson / mr.rb
Created July 15, 2012 05:33
manage multiruby
#!/usr/bin/env ruby
# https://gist.github.com/3115168
def shell_execute *args
io = IO.for_fd(3)
io.sync = true
io.puts *args
rescue Errno::EBADF
abort 'FD 3 is not open.'
@bhenderson
bhenderson / sequel-force_typecast.rb
Created June 29, 2012 19:30
sequel plugin to force typecasting
module Sequel
module Plugins
# The ForceTypecast plugin exists because as far as I can tell, ruby-oci8
# nor sequel has a way of overriding the column type returned from the
# database.
#
# This plugin is copied from TypecastOnLoad and offers similar
# functionality. The differences being that instead of taking an array of
# columns it takes a hash.
#
@bhenderson
bhenderson / version_sort.rb
Created June 28, 2012 05:53
cli for using version_sorter
#!/usr/bin/env ruby
require 'optparse'
require 'version_sorter/version'
ARGV.options.version = VersionSorter::Version
# long options also have default short options
opts = ARGV.getopts('', 'reverse') rescue abort( ARGV.options.to_s )
require 'version_sorter'
@bhenderson
bhenderson / git-rpie
Last active September 28, 2015 13:48
ruby replace-in-place for git
#!/bin/bash
# Download:
# $ curl -O https://gist.github.com/bhenderson/1447788/raw/git-rpie
# $ chmod u+x git-rpie
# $ git rpie -h
help() {
cat <<-EOU
Usage: