Skip to content

Instantly share code, notes, and snippets.

View tranch's full-sized avatar
Focusing

Tranch tranch

Focusing
View GitHub Profile
@tranch
tranch / vimrc.vim
Last active March 26, 2018 15:51
My VIM Profile
set t_Co=256
set laststatus=2
set tabstop=8 softtabstop=0 expandtab shiftwidth=4 wmw=0 smarttab smartindent nu
set listchars=tab:▸\ ,eol:¬ list
if has('gui_running')
colorscheme molokai
set background=dark
set guifont=Inconsolata-g\ for\ Powerline:h12
set guioptions-=r
<?php
class GridView extends \kartik\grid\GridView {
const TYPE_NONE = 'none';
public $toolbar = [];
public $bordered = false;
public $export = false;
public $layout = "{items}\n{pager}\n{pageSize}\n{summary}";
public $summaryOptions = [
@tranch
tranch / docstring.vim
Last active February 28, 2018 03:24 — forked from vpetro/gist:1204166
add docstring for python function in vim
function! WriteParams()
python << endpython
import re
import vim
# get the function definition line
line = vim.eval("getline(line('.'))")
# get the number of spaces to add to the start of the line
num_spaces = 4 + len(line) - len(line.lstrip())
# get the line number wher to do the insertion

ss-redir 的 iptables 配置(透明代理)

透明代理指对客户端透明,客户端不需要进行任何设置就使用了网管设置的代理规则

创建 /etc/ss-redir.json 本地监听 7777 运行ss-redir -v -c /etc/ss-redir.json

iptables -t nat -N SHADOWSOCKS
# 在 nat 表中创建新链
iptables -t nat -A SHADOWSOCKS -p tcp --dport 23596 -j RETURN
# 23596 是 ss 代理服务器的端口,即远程 shadowsocks 服务器提供服务的端口,如果你有多个 ip 可用,但端口一致,就设置这个
@tranch
tranch / ufw_centos.md
Last active March 1, 2018 07:14 — forked from ianchen06/ufw_centos.md
Setting up ufw on Centos

iptablesを直接いじりたくないのでufwを導入します。

sudo yum install wget make
mkdir -p ~/src
cd ~/src
wget https://launchpad.net/ufw/0.33/0.33/+download/ufw-0.33.tar.gz
tar xzf ufw-0.33.tar.gz
cd ufw-0.33
sudo python ./setup.py install
import requests
from db import db
"""
The Douban Group API which not display on http://developers.douban.com/wiki/?title=api_v2
Base url: https://api.douban.com/v2
Group info: /group/:id
@tranch
tranch / github_happy-new-year.js
Last active December 31, 2016 04:30
github new year comment legends.
function getWord(s) {
var ascii = [],
font = {
// 0:
// 1: *
// 2: *
// 3: **
// 4:*
// 5:* *
// 6:**
@tranch
tranch / human_resource_machine.rb
Created September 14, 2016 03:44
Human Resource Machine
def inbox
@register = @inbox.shift
end
def outbox
@outbox.push @register
end
def add(addr)
@register = @register + @ram[addr]
@tranch
tranch / crawler.py
Last active June 15, 2016 03:05
CSS spider
import os
import urlparse
import tinycss
import requests
from bs4 import BeautifulSoup
def crawl(site_url):
html = get_source(site_url)
soup = BeautifulSoup(html, 'html.parser')
@tranch
tranch / router.php
Last active May 9, 2016 17:15
A simple router for PHP built-in server.
<?php
route('GET', '/', function ($data) {
echo 'Welcome!';
});
return false;
function route($method, $uri, $callback) {
$REQUEST_URI = explode('?', $_SERVER["REQUEST_URI"])[0];