Skip to content

Instantly share code, notes, and snippets.

View stackdump's full-sized avatar

stackdump stackdump

View GitHub Profile
#!/usr/bin/ruby
#-*-ruby-*-
# A script to run ctags on all .rb files in a project. Can be run on
# the current dir, called from a git callback, or install itself as a
# git post-merge and post-commit callback.
CTAGS = '/usr/bin/env ctags'
HOOKS = %w{ post-merge post-commit post-checkout }
HOOKS_DIR = '.git/hooks'
@stackdump
stackdump / multiple_db_connections.rb
Created November 28, 2011 19:12
Method of using multiple db connection in ActiveRecord
# The idea here is to specify that a given model should use another
# database without having to change the entire inheritance hierarchy
# declare model for table in primary connection
class Bar < ActiveRecord::Base
# assume we have logic here that we don't want to refactor into a module
# but we do want to inherit in OtherDb::Bar
end
module Foo
@stackdump
stackdump / gist:1479007
Created December 14, 2011 23:07 — forked from bkimble/gist:1365005
List local memcached keys using Ruby
#!/usr/bin/env ruby
require 'net/telnet'
cache_dump_limit = 100
localhost = Net::Telnet::new("Host" => "localhost", "Port" => 11211, "Timeout" => 3)
slab_ids = []
localhost.cmd("String" => "stats items", "Match" => /^END/) do |c|
matches = c.scan(/STAT items:(\d+):/)
slab_ids = matches.flatten.uniq
end
@stackdump
stackdump / method_missing_respond_to.rb
Created August 16, 2012 21:47
sample illustration of meta-programming with method_missing & respond_to
class Foo
TEST=[:foo, :bar]
def self.count_foo
TEST.find_index(:foo)
end
#TODO try to reuse method missing code between class & instance methods
def self.method_missing(sym, *args, &block)
_=====_ _=====_
/ _____ \ / _____ \
+.-'_____'-.---------------------------.-'_____'-.+
/ | | '. ( )| |( ) .' | _ | \
/ ___| /|\ |___ \ | | / ___| /_\ |___ \
/ | | | ; | | ; | _ _ | ;
| | <--- ---> | | \___________/ | ||_| (_)| |
| |___ | ___| ; ; |___ ___| ;
|\ | \|/ | / _ __ _ \ | (X) | /|
| \ |_____| .','" "', /P ` ,'" "', '. |_____| .' |
@stackdump
stackdump / run_tags.rb
Created November 22, 2013 20:13 — forked from tobias/run_tags.rb
#!/usr/bin/ruby
#-*-ruby-*-
# A script to run ctags on all .rb files in a project. Can be run on
# the current dir, called from a git callback, or install itself as a
# git post-merge and post-commit callback.
CTAGS = '/opt/local/bin/ctags'
HOOKS = %w{ post-merge post-commit post-checkout }
HOOKS_DIR = '.git/hooks'
@stackdump
stackdump / README.md
Created December 11, 2013 15:44 — forked from taylor/README.md

Introduction

ssh-srv-wrapper is bash shell script which tries to find a SSH SRV record for the first host and uses what is found rather than what was passed (if a valid record is found).

Install

Run the script directly or feel free to rename or symlink to the name ssh. It will look for another ssh in your path to execute.

vagrant@vagrant:~$ reddit-shell
Overriding g.--plugin to r2
vagrant:5501 started 44e4803 at 20:43:13 (took 1.14s)
Traceback (most recent call last):
File "/usr/bin/paster", line 4, in <module>
command.run()
File "/usr/lib/python2.7/dist-packages/paste/script/command.py", line 104, in run
invoke(command, command_name, options, args[1:])
File "/usr/lib/python2.7/dist-packages/paste/script/command.py", line 143, in invoke
exit_code = runner.run(args)
@stackdump
stackdump / metaclass-black-magic
Last active August 29, 2015 14:08
metaclass / DSL + inheritance
require 'pp'
module Base
def metaclass
class << self
self
end
end
def p_r
http {
# enable reverse proxy
proxy_redirect off;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwared-For $proxy_add_x_forwarded_for;
upstream streaming_example_com