Skip to content

Instantly share code, notes, and snippets.

@artemave
artemave / SSH reverse tunnels
Created June 7, 2010 08:55
SSH reverse tunnels
# command line usage
local$ ssh -gR 8022:localhost:22 remote
remote$ scp -P 8022 file.tgz localhost:
# local ~/.ssh/config
Host remote
HostName remote.example.com
RemoteForward 8022 localhost:22
# remote ~/.ssh/config
desc "Tell app to use local gems and tweak bundler to not break with gems coming from git"
task :enable_local_gems_and_bundler do
run %(perl -pi -e 'print "ENV[\\"GEM_HOME\\"] = \\"/home/#{user}/.gems\\"\\nGem.clear_paths\\n" if $. == 1' #{release_path}/config/application.rb)
run "echo 'BUNDLE_PATH: /home/#{user}/.gems/bundler' >> #{release_path}/.bundle/config"
end
@artemave
artemave / gist:818678
Created February 9, 2011 15:43
find files with non-ascii content
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
File::Find::find(
sub {
return unless -f;
@artemave
artemave / gist:1006135
Created June 3, 2011 10:16
setup vnc server for any subsequent process (like cucumber -> firefox) to use vnc display
def _vnc_setup
d = '22' # vnc desktop number
ENV['DISPLAY'] = "localhost:#{d}"
hostname = `hostname`.chomp
vnc_pid_file = File.join(ENV['HOME'], ".vnc", "#{hostname}:#{d}.pid")
if File.exist?(vnc_pid_file)
pid = File.open(vnc_pid_file).read.chomp
log "Xvnc appears to be already running with pid #{pid}"
if `/bin/ps -p #{pid}`.split.last =~ /Xvnc/
return
@artemave
artemave / gist:1166574
Created August 23, 2011 21:17
class variable mystery
#code.rb
class Resource
end
module SomeModule
class Consumer
def singleton_resource
@@sr ||= Resource.new
end
@artemave
artemave / gist:1281864
Created October 12, 2011 17:15
rack one liner
run Proc.new {|env| [200, {"Content-Type" => "text/html"}, "Hello Rack!"]}
@artemave
artemave / gist:1303619
Created October 21, 2011 11:33
custom shoulda validate_inclusion_of matcher
RSpec::Matchers.define :validate_inclusion_of do |field, list|
match do |actual|
list.each do |i|
actual.should allow_value(i).for(field)
end
end
end
@artemave
artemave / gist:1354726
Created November 10, 2011 12:19
sinatra handler options
module Sinatra
class Base
class << self
def run!(options={})
set options
handler = detect_rack_handler
handler_name = handler.name.gsub(/.*::/, '')
# handler specific options use the lower case handler name as hash key, if present
handler_opts = begin
send(handler_name.downcase)
@artemave
artemave / env.rb
Created December 6, 2011 18:09
Temporary copy/paste solution to start/stop rest-assured
# Somewhere in you env.rb /spec_helper.rb or the like
require_relative "rest-assured-server"
at_exit do
RestAssuredServer.stop
end
RestAssuredServer.start
@artemave
artemave / gist:1501116
Created December 20, 2011 10:33
find free tcp port
require 'socket'
server = TCPServer.new('127.0.0.1', 0)
free_port = server.addr[1]
server.close