Skip to content

Instantly share code, notes, and snippets.

@amalc
amalc / gist:143790
Created July 9, 2009 16:38
Converting R1C1 style references for spreadsheets to AA1 style
# Converts row / column references to letter based column row references
# for spreadsheet addressing. Assumes 0 base.
def convert_row_column_to_cell_reference(r, c, ref)
throw :column_reference_too_large if c > 255
if c / 26 == 0
ref << (c%26+65).chr+(r+1).to_s
else
ref << (c/26+64).chr
convert_row_column_to_cell_reference(r, c%26, ref)
end
@amalc
amalc / deploy.rake
Created June 26, 2011 02:36 — forked from njvitto/deploy.rake
Rakefile to deploy and rollback to Heroku in two different environments (staging and production) for the same app
#Deploy and rollback on Heroku in staging and production
task :deploy_staging => ['deploy:set_staging_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
task :deploy_production => ['deploy:set_production_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
namespace :deploy do
PRODUCTION_APP = 'YOUR_PRODUCTION_APP_NAME_ON_HEROKU'
STAGING_APP = 'YOUR_STAGING_APP_NAME_ON_HEROKU'
task :staging_migrations => [:set_staging_app, :push, :off, :migrate, :restart, :on, :tag]
task :staging_rollback => [:set_staging_app, :off, :push_previous, :restart, :on]
@amalc
amalc / lithp.rb
Created January 26, 2012 14:47 — forked from fogus/lithp.rb
class Lisp
def initialize
@env = {
:label => lambda { |(name,val), _| @env[name] = val },
:quote => lambda { |sexpr, _| sexpr[0] },
:car => lambda { |(list), _| list[0] },
:cdr => lambda { |(list), _| list.drop 1 },
:cons => lambda { |(e,cell), _| [e] + cell },
:eq => lambda { |(l,r), _| l == r },
:if => lambda { |(cond, thn, els), ctx| eval(cond, ctx) ? eval(thn, ctx) : eval(els, ctx) },
@amalc
amalc / _html_colors.css.sass
Created February 12, 2012 13:50
HTML colors in SASS format
// 17 standard colors are: aqua, black, blue, fuchsia, gray, grey, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow
$alice-blue: #F0F8FF
$antique-white: #FAEBD7
$aqua: #00FFFF
$aquamarine: #7FFFD4
$azure: #F0FFFF
$beige: #F5F5DC
$bisque: #FFE4C4
$black: #000000
$blanched-almond: #FFEBCD
@amalc
amalc / firewall-ssh.sh
Created December 18, 2012 18:28
iptables - only ssh.
sudo iptables -F
sudo iptables -I INPUT 1 -i lo -j ACCEPT
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT
sudo iptables -A INPUT -j DROP
@amalc
amalc / gist:4332396
Created December 18, 2012 21:53
Setting up openvpn via a repo on CentOS 6.xx
yum install gcc make rpm-build autoconf.noarch zlib-devel pam-devel openssl-devel -y
wget http://openvpn.net/release/lzo-1.08-4.rf.src.rpm
# One of the commented ones below for 32 bit or 64 bit. Defaulting to 64 bit. Use uname -a to figure out what you are running.
# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-1.el6.rf.i686.rpm
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
rpmbuild --rebuild lzo-1.08-4.rf.src.rpm
sudo adduser dag
rpm -Uvh lzo-*.rpm
@amalc
amalc / openvpn-forwarding.sh
Created December 19, 2012 00:30
Setting up forwarding on client for OpenVPN for client to reach each other on CentOS 6.xx
service openvpn start
# Now we need to enable IP forwarding. So open the file /etc/sysctl.conf and set ‘net.ipv4.ip_forward’ to 1.
net.ipv4.ip_forward = 1
# To make the changes to sysctl.conf take effect, use the following command.
sysctl -p
# Route Iptables:
# The rule below will work fine on xen and KVM based VPS’s but for OpenVZ use the OpenVZ iptable rule instead:
sudo iptables -F
sudo iptables -I INPUT -i lo -j ACCEPT
sudo iptables -I INPUT -i tun0 -j ACCEPT
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --dport 1194 -m state --state ESTABLISHED -j ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp --dport ssh -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
sudo iptables -A INPUT -j DROP
sudo iptables -A OUTPUT -j DROP
sudo iptables -A FORWARD -j DROP
sudo iptables -F
sudo iptables -I INPUT -i lo -j ACCEPT
sudo iptables -I INPUT -i tun0 -j ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp --dport ssh -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --sport ssh -m state --state ESTABLISHED -j ACCEPT
sudo iptables -A INPUT -j DROP
sudo iptables -F
sudo iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -p udp -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -I INPUT -i lo -j ACCEPT
sudo iptables -I INPUT -i tun0 -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --dport 1194 -m state --state ESTABLISHED -j ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
sudo iptables -A INPUT -i eth0 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT