Skip to content

Instantly share code, notes, and snippets.

@rhybroy
rhybroy / ses.py
Created February 4, 2012 14:45 — forked from fanzeyi/ses.py
session for tornado
import os
import uuid
import marshal
import binascii
import tornado.web
def Session(func):
def warpper(self, *args, **kwargs):
@rhybroy
rhybroy / tornado_temp_file_put.py
Created April 17, 2012 09:52 — forked from joshmarshall/tornado_temp_file_put.py
Temporary File PUT Transfer Handler for Tornado
import tornado.ioloop
import tornado.web
import tornado.httpserver
import tornado.httputil
import tempfile
class MainHandler(tornado.web.RequestHandler):
def put(self):
filename = self.request.body.name
# do stuff with the image
@rhybroy
rhybroy / resize.py
Created April 27, 2012 12:13
resize image by origin percent
import Image
basewidth = 300
img = Image.open(‘fullsized_image.jpg’)
wpercent = (basewidth / float(img.size[0]))
hsize = int((float(img.size[1]) * float(wpercent)))
img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS)
img.save(‘resized_image.jpg’)
@rhybroy
rhybroy / fetchsub.sh
Created October 28, 2012 06:43 — forked from ravageralpha/fetchsub.sh
shell script get subtitle from shooter.cn
#!/bin/sh
# Author: RA <ravageralpha@gmail.com>
USAGE(){
echo "Usage:fetchsub [eng] file"
}
[ $# -eq 0 -o "$1" = '--help' ] && USAGE && exit 0
ERROR(){
@rhybroy
rhybroy / arithmetic.py
Created November 28, 2012 03:53
计算字符串相似度(编辑距离算法)
#!/user/bin/env python
# -*- coding: utf-8 -*-
class arithmetic():
def __init__(self):
pass
''' 【编辑距离算法】 【levenshtein distance】 【字符串相似度算法】 '''
def levenshtein(self,first,second):
if len(first) > len(second):
@rhybroy
rhybroy / pptp.sh
Created December 25, 2012 02:09
pptp install for ubuntu
#!/bin/bash
if [ $(id -u) != "0" ]; then
printf "Error: You must be root to run this tool!\n"
exit 1
fi
clear
printf "
####################################################
# #
@rhybroy
rhybroy / default-ips
Last active December 10, 2015 05:38
generate vpn routes from ip txt
#
#Google
#
216.73.93.70/31
216.73.93.72/31
216.239.32.0/19
64.233.160.0/19
66.249.80.0/20
72.14.192.0/18
209.85.128.0/17
@rhybroy
rhybroy / tmux-iterm2.rb
Last active December 16, 2015 11:48
tmux-iterm2 brew install
require 'formula'
class TmuxIterm2 < Formula
url 'https://iterm2.googlecode.com/files/tmux-for-iTerm2-20130319.tar.gz'
sha1 'f14a0bad6991b9e3380d5c3a6057e09f62597d1f'
head 'git://tmux.git.sourceforge.net/gitroot/tmux/tmux'
depends_on 'pkg-config' => :build
depends_on 'libevent'
@rhybroy
rhybroy / bashrc
Created April 23, 2013 10:05
linux server rc
alias fp='ps aux|grep'
alias vi='mvim'
alias df="df -h"
alias mv="mv -i"
alias slink="link -s"
alias l="ls -lh"
alias la="ls -lhAF"
alias ll="ls -lhF"
alias lt="ls -lhtrF"
alias l.="ls -lhtrdF .*"
@rhybroy
rhybroy / pptp_autocon.applescript
Last active April 5, 2017 12:17
auto connect/disconnect pptp-vpn from the command line for mac
set msg to ""
tell application "System Events"
tell current location of network preferences
set VPNservice to service "VPN (PPTP)"
if exists VPNservice then
set isConnected to connected of current configuration of VPNservice
if isConnected then
disconnect VPNservice
set msg to "Disconnected"
else