Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
It's Complicated

Dmitry Sabanin dsabanin

💭
It's Complicated
View GitHub Profile
@dsabanin
dsabanin / port_redirect.sh
Created May 23, 2014
Script for setting up redirect for a local port to a remote host's port (root or sudo needed)
View port_redirect.sh
#!/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 Aug 29, 2015
Tiny capistrano-like script for dploy.io
View deploy.sh
# 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
View config.yml
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 Sep 8, 2008
Save this file as .git/hooks/pre-commit. No broken tests in repo
View pre-commit.sh
#!/bin/sh
# Save this file as .git/hooks/pre-commit
rake spec
View string_tidy_example.rb
"<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\">
View rails_mock_openid_request.rb
# 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 Apr 26, 2011
Install Magma 1.1r in Pharo 1.2
View install-magma-1.1.st
Deprecation raiseWarning: false.
Gofer new
squeaksource: 'MetacelloRepository';
package: 'ConfigurationOfMagma';
load.
((Smalltalk at: #ConfigurationOfMagma) project version: #stable) load: 'Tester'.
View array_permutation_ext.rb
# 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
View gist:2146349
(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)