Skip to content

Instantly share code, notes, and snippets.

View tranch's full-sized avatar
Focusing

Tranch tranch

Focusing
View GitHub Profile
@tranch
tranch / scroll_document_title.js
Last active August 29, 2015 14:25
scrolling document title when it longer than browser tab width.
(function (doc) {
var origin_title = doc.title;
setInterval(function() {
doc.title = doc.title.length <= 15
? origin_title
: doc.title.slice(1, 1) + doc.title.slice(1, doc.title.length + 1);
}, 300);
})(document);
@tranch
tranch / mode-impala.js
Created September 12, 2015 10:05
ACE syntax highlight for impala.
define("ace/mode/sql_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var SqlHighlightRules = function() {
var keywords = (
"add|aggregate|all|alter|and|api_version|as|asc|avro|between|bigint|binary|boolean|by|cached|case|cast|change|char|class|close_fn|column|columns|comment|compute|create|cross|data|database|databases|date|"+
@tranch
tranch / phpkafka.php
Last active February 29, 2016 09:06 — forked from edenhill/phpkafka.php
PHP Kafka new API
<?php
# Kafka configuration (https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md)
$config = [ "metadata.broker.list" => "broker1.example.com", "socket.timeout.ms" => 30000, ... ];
# Create Kafka Producer object.
# Brokers are specified through $config, but we could make it easier for people by having the first
# argument be brokers as well, and rdkafka will use all brokers specified?
$producer = new Kafka::Producer([$brokers,]? $config);
@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];
@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 / 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 / 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:**
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 / 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

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 可用,但端口一致,就设置这个