Skip to content

Instantly share code, notes, and snippets.

View dsabanin's full-sized avatar
💭
It's Complicated

Dmitry Sabanin dsabanin

💭
It's Complicated
View GitHub Profile
@dsabanin
dsabanin / port_redirect.sh
Created May 23, 2014 14:55
Script for setting up redirect for a local port to a remote host's port (root or sudo needed)
#!/bin/sh
TARGET_HOST=9.9.9.9
TARGET_PORT=22
PROXY_PORT=23
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport $PROXY_PORT -j DNAT --to $TARGET_HOST:$TARGET_PORT
iptables -t nat -A PREROUTING -p tcp --dport $PROXY_PORT -j DNAT --to $TARGET_HOST:$TARGET_PORT
@dsabanin
dsabanin / deploy.sh
Last active August 29, 2015 14:07
Tiny capistrano-like script for dploy.io
# Execute as ./deploy.sh /data/project 19851203123502
# It will deploy final release as a symlink from /data/project/current to /data/project/releases/19851203123502
BASE=$1
TIMESTAMP=$2
RELEASE=$BASE/releases/$TIMESTAMP
mkdir -p $BASE/releases $BASE/shared $BASE/logs
cp -al $BASE/deploy-cache $RELEASE
root: "/Users/railsmonk/xfiles"
server_ip: "*"
apache2_configs_directory: "/sw/etc/apache2/alpha.d"
hooks_path: "#{root}/application/script/x"
storage_path: "#{root}/storage"
server_restart_marker: "/tmp/restart-server-please.flag.%d"
## Send emails about exceptions to
exception_recipients:
- sdmitry@gmail.com
@dsabanin
dsabanin / pre-commit.sh
Created September 8, 2008 08:51
Save this file as .git/hooks/pre-commit. No broken tests in repo
#!/bin/sh
# Save this file as .git/hooks/pre-commit
rake spec
#!/bin/sh
rake spec
"<p>blah".tidy # => "<p>blah</p>"
"blah".tidy # => "blah"
"blah<p>".tidy # => "blah"
"blah".tidy(:show_body_only => false) # =>
# Renders:
# "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
# \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
# Mocks a request to OpenID server with given response status.
# If you give it a hash of args as a third argument, it will act
# like information about user transmitted from OpenID server.
class ActiveSupport::TestCase
# Example:
# mock_openid_response("http://identity.url", OpenID::Consumer::SUCCESS,
# 'fullname' => 'Joe Black',
# 'email' => 'joe.black@gmail.com',
# 'nickname' => 'joeeeey')
@dsabanin
dsabanin / install-magma-1.1.st
Created April 26, 2011 01:38
Install Magma 1.1r in Pharo 1.2
Deprecation raiseWarning: false.
Gofer new
squeaksource: 'MetacelloRepository';
package: 'ConfigurationOfMagma';
load.
((Smalltalk at: #ConfigurationOfMagma) project version: #stable) load: 'Tester'.
@dsabanin
dsabanin / array_permutation_ext.rb
Created January 6, 2012 09:33
Array#each_permutation
# Taken here http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/247669. Reformatted.
# based on the C++ standard library's implementation by Ken Bloom
class Array
def next_permutation!
return self if length<2
i = length-1
while true
ii = i
i -= 1
@dsabanin
dsabanin / gist:2146349
Created March 21, 2012 11:39
Midge example
(fact "configuration"
server-port => number?
server-url => string?
server-static-path => string?)
(fact "on-connect handler"
(on-connect --connection--) => anything)
(fact "on-disconnect handler"
(on-disconnect --connection--) => anything)