Skip to content

Instantly share code, notes, and snippets.

View ninehills's full-sized avatar

Tao Yang ninehills

View GitHub Profile
@EdwardBetts
EdwardBetts / pprint_color.py
Last active March 19, 2024 18:17
Python pprint with color syntax highlighting for the console
from pprint import pformat
from typing import Any
from pygments import highlight
from pygments.formatters import Terminal256Formatter
from pygments.lexers import PythonLexer
def pprint_color(obj: Any) -> None:
"""Pretty-print in color."""
@dongweiming
dongweiming / benchmarks.ipynb
Created March 16, 2015 02:27
benchmarks.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@maliubiao
maliubiao / tcpinfo.py
Last active August 29, 2015 14:05
功能: 1, 获取系统当前所有的tcp链接信息, 2: 找到绑定某个端口的进程tcpinfo.port_to_pid(port)
import os
import struct
import socket
state_table = (
"EMPTY SLOT",
"ESTABLISHED",
"SENT",
"RECV",
"WAIT1",
@kchida
kchida / gist:d1c15f3968f4f8272c49
Created July 17, 2014 05:06
etcd vs consul vs ???
- What do Etcd, Consul, and Zookeeper do?
- Service Registration:
- Host, port number, and sometimes authentication credentials, protocols, versions
numbers, and/or environment details.
- Service Discovery:
- Ability for client application to query the central registry to learn of service location.
- Consistent and durable general-purpose K/V store across distributed system.
- Some solutions support this better than others.
- Based on Paxos or some derivative (i.e. Raft) algorithm to quickly converge to a consistent state.
- Centralized locking can be based on this K/V store.
@drsnyder
drsnyder / urandom-reads.py
Last active August 11, 2021 10:44
Demonstrate the contention on /dev/urandom with N threads.
# Create a user land file for testing.
# dd if=/dev/urandom of=/tmp/urandom bs=1M count=10
#
# urandom-reads.py infile threads
# Examples:
# time python2.6 urandom-reads.py /tmp/urandom
# time python2.6 urandom-reads.py /dev/urandom
#
# R to generate a plot of the read time distribution at each level of concurrency
# rdt = read.csv("output.csv", header=F)
@jbenet
jbenet / simple-git-branching-model.md
Last active March 12, 2024 12:16
a simple git branching model

a simple git branching model (written in 2013)

This is a very simple git workflow. It (and variants) is in use by many people. I settled on it after using it very effectively at Athena. GitHub does something similar; Zach Holman mentioned it in this talk.

Update: Woah, thanks for all the attention. Didn't expect this simple rant to get popular.

@ninehills
ninehills / mactype_win8.md
Last active June 19, 2016 02:26
win8使用MacType
@ninehills
ninehills / zerorpc.md
Created June 18, 2013 12:17
ZeroRPC简介 - 轻量级分布式通信框架

ZeroRPC简介 - 轻量级分布式通信框架

概述

分布式系统的核心是分布式通信,而传统上开发一套支持上千台规模集群,可靠性非常高的分布式通信框架,需要不少的精力投入。而在多数情景下,我们(特别是时间宝贵的OP)并不是非常关注技术实现的细节,而是希望有一套成熟、轻量、可靠性高、使用方便而且易于调试的分布式通信框架,可以直接使用,从而把时间放在具体业务逻辑上。

在PyCon 2012大会上,dotcloud公司开源了一套基于ZeroMQ和MessagePack的分布式通信框架(或者说是协议+Python实现)。该框架因为基于ZeroMQ,使用方法是RPC,所以被命名为ZeroRPC。ZeroRPC的特点在其官网的介绍中一目了然[1]:

ZeroRPC is a light-weight, reliable and language-agnostic library for distributed communication between server-side processes.

@ninehills
ninehills / backgroudmix.py
Last active December 10, 2015 17:08 — forked from methane/gist:2185380
tornado add block task to ThreadPool
from time import sleep
import tornado
from multiprocessing.pool import ThreadPool
_workers = ThreadPool(10)
class BackgroundMix(tornado.web.RequestHandler):
"""将block任务放入线程池中执行
EXAMPLE:
# blocking task like querying to MySQL
@Nurdok
Nurdok / python_conversion.md
Last active December 16, 2022 03:45
Python Conversion

Python Number Conversion Chart

From To Expression