Skip to content

Instantly share code, notes, and snippets.

View ratazzi's full-sized avatar

Ratazzi ratazzi

View GitHub Profile
@ratazzi
ratazzi / gist:2429249
Created April 20, 2012 14:50
iptables-rules.sh
# forward openvpn http to local 7777 port, squid cache
iptables -t nat -A PREROUTING -s 10.8.0.0/24 -i tun0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 7777
# VPN NAT
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
# or
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to-source 173.230.148.194
# block ip 200.164.230.186
iptables -A INPUT -s 200.164.230.186/32 -j DROP
#!/bin/bash
# my title
echo -e '\x1b]0;my title\x07'
#!/bin/bash
echo $LINES
echo $COLUMNS
# or
tput lines
tput cols
#!/usr/bin/env python
# encoding=utf-8
# get terminal size
import curses
if __name__ == '__main__':
curses.setupterm()
print curses.tigetnum('lines')
@ratazzi
ratazzi / portabledb.py
Created December 24, 2011 06:24
portable db
#!/usr/bin/env python
# encoding=utf-8
import os, sys
import sqlite3
class PortableDB(object):
def __init__(self, db_path):
self.conn = sqlite3.connect(db_path)
self.cursor = self.conn.cursor()
git config filter.rcs-keyword.clean 'perl -pe "s/\\\$Revision[^\\\$]*\\\$/\\\$Revision\\\$/"'
git config filter.rcs-keyword.smudge 'perl -pe "s/\\\$Revision[^\\\$]*\\\$/\\\$Revision: `env -i git svn info | grep Revision | awk '\''{print $2}'\''`\\\$/"'
# example usage:
# echo 'test.py filter=rcs-keyword' >> .gitattributes
# git add test.py .gitattributes
# need manual checkout file
# rm test.py
# git checkout test.py
Options ExecCGI FollowSymLinks Includes MultiViews
RewriteEngine On
#RewriteCond %{HTTP_HOST} ^[^.]+\.ratazzi\.org$
#RewriteRule ^(.*) %{HTTP_HOST}$1 [C]
#RewriteRule ^([^.]+)\.ratazzi\.org(.*) /static/$1$2 [L]
RewriteCond %{HTTP_HOST} ^static.ratazzi.org$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# gevent on OS X Lion
sudo python setup.py install -I /opt/local/include/ -L /opt/local/lib
@ratazzi
ratazzi / eventlet_example.py
Created October 12, 2011 14:44
eventlet_example.py
#!/usr/bin/env python
# encoding=utf-8
import eventlet
eventlet.monkey_patch()
import sys, os
import xmlrpclib
import subprocess
def download():
@ratazzi
ratazzi / gist:1273519
Created October 9, 2011 10:08
aria2c
aria2c \
--continue=true \
--log=/home/ratazzi/aria.log \
--log-level=warn \
--seed-time=0 \
--file-allocation=none \
--human-readable=false \
--allow-overwrite=true \
--always-resume=true \
--bt-hash-check-seed=false \