Skip to content

Instantly share code, notes, and snippets.

@vitrun
vitrun / enum.thrift
Last active December 14, 2022 08:25
map json to thrift object
namespace java base
namespace js base
enum Status {
SUCCESS = 1,
FAIL = 2,
}
struct Children {
1: optional string name,
@vitrun
vitrun / pre-commit-for-go
Created April 13, 2020 05:22
pre-commit-for-go
#!/bin/sh
# Run some pre commit checks on the Go source code. Prevent the commit if any errors are found
echo "Running pre-commit checks on your code..."
FILES=$(go list ./... | grep -v /vendor/|grep -v /thrift_gen)
# Format the Go code
go fmt ${FILES}
@vitrun
vitrun / .zshrc
Last active February 23, 2020 08:09
alias dl="cd ~/Downloads/"
alias gos="cd ~/go/src/"
alias unproxy="unset http_proxy; unset https_proxy"
# Command history search
bindkey -v
bindkey '^R' history-incremental-search-backward
# Go proxy
export GOPROXY=https://goproxy.cn
@vitrun
vitrun / .tmux.conf
Last active February 23, 2020 11:13
# vim style tmux config
# use C-q, since it's on the home row and easier to hit than C-b
set-option -g prefix C-q
unbind-key C-q
bind-key C-q send-prefix
set -g base-index 1
# Easy config reload
bind-key R source-file ~/.tmux.conf \; display-message "tmux.conf reloaded."
@vitrun
vitrun / eatitjuzi.py
Created January 16, 2017 08:18
crawl company infomation from http://www.itjuzi.com/company. IT桔子公司信息抓取,无视其web端的反爬虫限制。
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright ©2017-01-16 Alex <[email protected]>
#
"""
crawl the itjuzi.com company data
"""
import requests
import time
@vitrun
vitrun / SpreadsheetExportToXLSX.scpt
Last active January 12, 2017 11:14 — forked from idStar/SpreadsheetExportToCSV.scpt
Export spreadsheet to UTF8 xlsx using Numbers 3.6 on a Mac with AppleScript
#! /usr/bin/osascript
(*
---------------------------------------------------------------------------------
Script: SpreadsheetExportToCSV
Command-line tool to convert a spreadsheet document to CSV
This AppleScript is tested with and compatible with Apple iWork Numbers 3.6,
current as at October 23, 2015.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright ©2016-12-08 Alex <[email protected]>
#
"""
当当分布式id生成器冲突概率计算,生成器设计见:
http://dangdangdotcom.github.io/sharding-jdbc/post/id-generator/
"""
import sys
@vitrun
vitrun / Redis hash and string performance
Created May 21, 2015 09:02
Redis hash and string performance
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright ©2015-05-21 Alex <[email protected]>
#
"""
对比:
pipe : pipe line 方式一次读取hash内多个key
loop : 遍历读取这些hash key
mget : 原生命令一次性读取string key

(python)jay@localhost:~/Desktop$ python --version

Python 2.7.2

(python)jay@localhost:~/Desktop$ cat urllib2-leaks.py

import gc
import inspect
import logging
function killall(ns, wet_run) {
ns = (typeof (ns) != 'undefined') ? ns : "";
inprog = db.currentOp().inprog;
for (var i in inprog) {
var op = inprog[i];
if (op.ns.indexOf(ns) != -1) {
if (wet_run == true) {
db.killOp(op.opid);
} else {
var toprint = {}