Skip to content

Instantly share code, notes, and snippets.

@gabehollombe
gabehollombe / gist:7365170
Created November 8, 2013 02:10
SSH Tricks
TUNNELING
Expose server port 456 on local port 123
$ ssh -L 123:localhost:456 user@yourserver.com
Transparent SOCKS proxy on localhost:12345
$ ssh -D 12345 user@yourserver.com
@gabehollombe
gabehollombe / gist:7244266
Created October 31, 2013 04:10
Capybara ghetto wait_for(selector) when dealing with JS DOM manipulation.
def wait_for(selector)
time_waiting = 0
sleep_tick = 0.1
num_matches = -> { page.evaluate_script("$('#{selector}').length").to_i }
while num_matches.call <= 0 do
time_waiting += sleep_tick
sleep(sleep_tick)
timeout_reached = time_waiting >= Capybara.default_wait_time
raise "Timeout reached while waiting for '#{selector}'" if timeout_reached
end
#Functions for lazy git commiting
#Instead of: git commit -m "some message"
#Type: gci some message
gci() {
if [ -z "$1" ] # Is parameter #1 zero length?
then
echo "You must pass a commit message like this: gci some message here - which then becomes: git commit -m 'some message here'"
else
git commit -m "$*"
fi
@gabehollombe
gabehollombe / gist:2468822
Created April 23, 2012 04:10
SSH tunnel between two NATed machines via a third SSH host
Useful for when you need to have two hosts talk to each other on a specific port but they're both NATed (behind routers).
For example, you want to be able to SSH into your friend's machine to pair program with them.
host-machine$ ssh -R 55555:localhost:22 myaccount@my_ssh_server.com
connecting-machine$ ssh -L 55555:localhost:55555 myaccount@my_ssh_server.com
connecting-machine$ ssh -p 55555 user_on_host_machine@localhost
@gabehollombe
gabehollombe / debug_log.coffee
Created March 8, 2012 12:56
Helpful CoffeeScript console debugging function
d = (s) -> o = {}; o[k] = eval(k) for k in s.split(' '); console.log JSON.stringify(o, null, ' ')
# Or, the compiled JavaScript:
d = function(s) {
var k, o, _i, _len, _ref;
o = {};
_ref = s.split(' ');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
k = _ref[_i];
# These are my notes from the PragProg book on CoffeeScript of things that either
# aren't in the main CS language reference or I didn't pick them up there. I wrote
# them down before I forgot, and put it here for others but mainly as a reference for
# myself.
# assign arguments in constructor to properties of the same name:
class Thingie
constructor: (@name, @url) ->
# is the same as:
@gabehollombe
gabehollombe / gist:979788
Created May 18, 2011 23:05
Adding a custom 'seconds' function on to Number in JavaScript
> Number.prototype.seconds = function(){ return this * 1000 }
=> function (){ return this * 1000 }
> 1..seconds()
=> 1000
> (1).seconds()
=> 1000
> 1['seconds']()
@gabehollombe
gabehollombe / discover.rb
Created March 25, 2011 00:01
Get autotest to run on spec/integration changes and friends
Autotest.add_hook :initialize do |at|
at.add_mapping(%r%^spec/integration/.*_spec.rb$%, true) { |filename, _|
filename
}
at.add_mapping(%r%^app/(models|controllers|helpers|lib)/.*rb$%, true) {
at.files_matching %r%^spec/integration/.*_spec.rb$%
}
at.add_mapping(%r%^app/views/(.*)$%, true) {
@gabehollombe
gabehollombe / Example txt to pivotal format
Created September 28, 2010 06:03 — forked from cjheath/Example Treetop grammar fragment
Parsing a text file for Pivotal Tracker stories with Treetop
LabelOne LabelTwo
- feature one (description one)
- feature two (description two)
- feature three with multiline desc following
desc line 1
desc line 2
desc line 3
grammar PivotalStories
rule stories
story*
end
rule story
feature*
end
rule feature