Skip to content

Instantly share code, notes, and snippets.

View tranch's full-sized avatar
🎯
Focusing

Tranch tranch

🎯
Focusing
View GitHub Profile
@tranch
tranch / show_level.js
Last active August 29, 2015 13:57
豆瓣电影评论显示楼层号脚本
(function($) {
$('#comments').find('.comment-item').each(function(i) {
var page, level, paginator = $('.paginator');
page = paginator.length ? parseInt(paginator.find('.on').text()) : 1;
level = i + 1 + (page - 1) * 30;
$(this).find('.author').append($('<strong>').text(level + '楼'));
});
})(window.jQuery);
@tranch
tranch / install_php55.sh
Last active August 29, 2015 14:00
Install php5.5 using Remi Repository on CentOS 6.2
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
yum --enablerepo=remi,remi-php55 install php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-apc php-gd php-mbstring php-mcrypt php-xml
@tranch
tranch / switch_mode.js
Last active August 29, 2015 14:01
切换开发模式和生产模式的域名
// javascript:(function(l){var f=function(u,a,b){return u.indexOf(a)?u.replace(a,b):f(u,b,a)};l.herf=f(l.href,'.com','.dev')})(location);
(function(l) {
var f = function (u, a, b) {
return u.indexOf(a) ? u.replace(a, b) : f(u, b, a);
};
l.href = f(l.href, '.dev', '.com');
})(location);
<?php
function random_text( $type = 'alnum', $length = 8 )
{
switch ( $type ) {
case 'alnum':
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'alpha':
$pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
@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)
<!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 / 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
@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 / 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 / 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,