Skip to content

Instantly share code, notes, and snippets.

View beordle's full-sized avatar
💌
On vacation, oh..

Jindong Zhang beordle

💌
On vacation, oh..
  • Tencent
  • Beijing, China
View GitHub Profile
@binux
binux / pool.py
Created May 26, 2011 06:39
使用threading+queue的线程池封装,使用对象在每个对象中保存独立的连接,可以安全地使用ctrl-c打断
# !/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
import time
import Queue
import threading
import traceback
class ExitException(Exception):
@andelf
andelf / flatten.py
Created October 24, 2011 05:04
How to flatten a python nested list(tuple)
flatten = lambda lst: reduce(lambda l,i: l + flatten(i) if isinstance(i, (list,tuple)) else l + [i], lst, [])
print flatten([2, [2, [4, 5, [7], [2, [6, 2, 6, [6], 4]], 6]]])
# -> [2, 2, 4, 5, 7, 2, 6, 2, 6, 6, 4, 6]
@mrluanma
mrluanma / flatten.py
Created December 15, 2011 11:07 — forked from andelf/flatten.py
How to flatten a python nested list(tuple)
flatten = lambda lst: reduce(lambda l, i: l + flatten(i) if isinstance(i, (list, tuple)) else l + [i], lst, [])
print flatten([2, [2, [4, 5, [7], [2, [6, 2, 6, [6], 4]], 6]]])
# -> [2, 2, 4, 5, 7, 2, 6, 2, 6, 6, 4, 6]
@KartikTalwar
KartikTalwar / Documentation.md
Last active April 13, 2024 23:09
Rsync over SSH - (40MB/s over 1GB NICs)

The fastest remote directory rsync over ssh archival I can muster (40MB/s over 1gb NICs)

This creates an archive that does the following:

rsync (Everyone seems to like -z, but it is much slower for me)

  • a: archive mode - rescursive, preserves owner, preserves permissions, preserves modification times, preserves group, copies symlinks as symlinks, preserves device files.
  • H: preserves hard-links
  • A: preserves ACLs
@vincenting
vincenting / client.py
Last active February 5, 2021 06:42
微信公共平台脚本
# coding=utf-8
__author__ = 'Vincent Ting'
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Vincent Ting'
import cookielib
import urllib2
@andelf
andelf / EasyJSON.swift
Last active August 29, 2015 14:03
Swift JSON Helper
import Foundation
//let raw = String.stringWithContentsOfURL(NSURL(string: "http://www.weather.com.cn/data/sk/101010100.html"))
struct EasyJSON {
var _obj: AnyObject!
init(_ obj: AnyObject) {
//assert(NSJSONSerialization.isValidJSONObject(obj), "must be valid json object")
_obj = obj
@gchudnov
gchudnov / cpp_utf8_utf16.cpp
Created November 6, 2014 19:33
C++ string conversion UTF8 <-> UTF16
#include <string>
#include <locale>
#include <codecvt>
//UTF-8 to UTF-16
std::string source;
//...
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
std::u16string dest = convert.from_bytes(source);
@aero
aero / readline_ev.cpp
Created March 12, 2015 09:12
Example: Integrating readline with libev eventloop.
// g++ -o readline_ev -g readline_ev.cpp -g -lreadline -lev
//
#include <stdlib.h>
#include <unistd.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <ev.h>
#include <fcntl.h>

最终实现效果:

  1. 无版本概念,任何本地文件均可增量升级到最新.服务器不用管理多版本
  2. 内存小,100M文件升级时只占用500KB内存.

使用流程:

  1. 制作新版本,上传HTTP File Server.
  2. Client自动计算差异,下载差异,合并差异.
  3. done!

#0.起源

@nasitra
nasitra / backtrace.c
Created October 9, 2016 06:31
Print call stack by using libunwind
#include <libunwind.h>
#include <libunwind-ptrace.h>
#include "backtrace.h"
#define MAX_BACKTRACE_FRAMES 64
void unwind(pid_t pid) {
unw_addr_space_t addr_space = NULL;
struct UPT_info* upt_info = NULL;