Skip to content

Instantly share code, notes, and snippets.

View taozle's full-sized avatar
💭
I may be slow to respond.

taozle taozle

💭
I may be slow to respond.
View GitHub Profile
@taozle
taozle / highlight_code.py
Last active November 20, 2015 07:42
Using pygments to highlight source code to html
from pygments import highlight
from pygments.lexers import guess_lexer
from pygments.formatters.html import HtmlFormatter
def highlight_code(src, style='manni'):
"""This function highlight :param:`src` into html format using the style provided.
:param src: The source code to highlight.
:param style: The color style, valid style to see:
@taozle
taozle / singleton.py
Last active November 20, 2015 07:54
Singleton implementations
import functools
def singleton(cls, *args, **kwargs):
instances = {}
@functools.wraps(cls)
def wrapper():
if cls not in instances:
instances[cls] = cls(*args, **kwargs)
return instances[cls]
import sys
from cStringIO import StringIO
from contextlib import contextmanager
@contextmanager
def capture(command, *args, **kwargs):
out, sys.stdout = sys.stdout, StringIO()
command(*args, **kwargs)
sys.stdout.seek(0)
yield sys.stdout.read()
logging.config.dictConfig({
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'console': {'format': '[%(levelname)s %(asctime)s %(name)s] %(message)s'},
},
'handlers': {
'console': {
'level': 'INFO',
'formatter': 'console',
@taozle
taozle / hasattr.md
Last active November 6, 2022 10:14
How `hasattr` implemented in python

How hasattr implemented in Python

Python 2.7:

static PyObject *
builtin_hasattr(PyObject *self, PyObject *args)
{
    PyObject *v;
@taozle
taozle / cache.md
Created September 9, 2016 07:52
缓存更新的几种策略

缓存更新的几种策略

Cache aside

Read through

Write through

Write behind caching

@taozle
taozle / css.md
Last active September 11, 2016 16:34
CSS note
  • CSS 优先级?

      1. !important
      2. inline
      3. id
      4. class (多个 class 按照定义顺序)
    
  • Placeholder

Pros

Cons

  • 响应时间不稳定

From Kafka to ZeroMQ for real-time log aggregation

Kafka

架构图:

Problems

env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" pip install cryptography