Skip to content

Instantly share code, notes, and snippets.

View tranch's full-sized avatar
Focusing

Tranch tranch

Focusing
View GitHub Profile
@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 / 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 / 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 / HeidiSQLForward.py
Last active August 29, 2015 14:14
HeidiSQL protocol forwarding
import sys
import subprocess
from urlparse import urlparse, parse_qs
def main(script, plate):
url = urlparse(plate)
query_string = parse_qs(url.query)
application = r'D:\Program Files\HeidiSQL\heidisql.exe'
command = [application,
@tranch
tranch / hacker_news_spam_blocker.user.js
Created December 10, 2014 19:24
Hacker News Spam Blocker
// ==UserScript==
// @name block it
// @namespace tranch
// @description block item by domain on hacknews
// @include http://news.dbanotes.net/*
// @version 0.1
// @grant none
// ==/UserScript==
(function() {
@tranch
tranch / xiami_download_helper.user.js
Last active August 29, 2015 14:09
虾米音乐下载 Grease Monkey 插件。
// ==UserScript==
// @name 虾米音乐下载
// @namespace tranch
// @description 替换下载按钮的链接
// @include http://www.xiami.com/album/*
// @include http://www.xiami.com/song/*
// @version 0.06
// @grant none
// ==/UserScript==
(function (d, l) {
@tranch
tranch / encoding.sh
Last active August 29, 2015 14:04
编码转换
#!/bin/bash
for i in $(find -name '*.ext'); do
encoding=$(file -bi "$i" | sed -e 's/.*[ ]charset=//');
iconv -f $encoding -t UTF-8 -o "$i" "$i";
done
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>Feed Reader</title>
<style>
body { font-size: 14px; line-height: 1.3em; }
#main { max-width: 768px; margin: auto; }
#main-container { padding: 5px; background: #C3D9FF; }
@tranch
tranch / to_qr.js
Last active August 29, 2015 14:01
A JavaScript bookmarklet used to generate a QR code image of current URL.
(function(doc) {
var API = 'https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=',
img = doc.createElement('img');
img.style.cssText = 'position:fixed;top:5px;right:5px;z-index:2147483647';
img.src = API + encodeURI(location.href);
img.onclick = function() {
img.parentNode.removeChild(img)
};
doc.body.appendChild(img)
})(document)
<?php
function random_text( $type = 'alnum', $length = 8 )
{
switch ( $type ) {
case 'alnum':
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'alpha':
$pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;