Skip to content

Instantly share code, notes, and snippets.

View Ivlyth's full-sized avatar
🎯
Focusing

Ivlyth Ivlyth

🎯
Focusing
View GitHub Profile
@Ivlyth
Ivlyth / Makefile
Created June 28, 2017 01:34
使用Makefile 在 centos 6.x 系统上一键安装 python2.7 并安装 virtualenvwrapper
env ?=upy
PYTHON_VENV := $(env)
version ?=2.7.10
PYTHON_VERSION := $(version)
PYTHON_DIR := Python-$(PYTHON_VERSION)
all: task-install-venv-wrapper
@ echo 'All done ...'
@Ivlyth
Ivlyth / commit_time_in_seconds.py
Last active November 25, 2016 10:44
从git commit中提取时间相关信息计算其距离现在的秒数
'''
例子:
1. '*********** - 1 year, 4 months ago - someone do something1' => 1*365*24*60*60 + 4*30*24*60*60
2. '*********** - 3 months, 7days ago - someone do something2' => 3*30*24*60*60 + 7*24*60*60
3. '*********** - 5 hours ago - someone do something3' => 5*60*60
'''
unit_map = {
'years': 365 * 24 * 60 * 60,
'year': 365 * 24 * 60 * 60,
@Ivlyth
Ivlyth / hproxy.conf
Created November 18, 2016 17:11
使用 SSH 隧道将内网服务暴露在公网上(主要用于临时调试等目的, 不推荐长时间的内网服务暴露)
# 使用了 lua 模块的 nginx 配置文件
# 推荐使用 openresty 或者自行编译 nginx with lua
lua_shared_dict proxy_ports 5m;
server {
listen 80;
server_name *.hproxy.yourdomain.com;
set $real_host $http_host;
if ($http_host ~* "(.*).hproxy.yourdomain.com") {
@miraculixx
miraculixx / asciidecodeerror.py
Last active November 22, 2021 15:57
Tired of Python's UnicodeDeocodeError, ascii codec can't decode? Here's how to fix it, once and for all.
# Python ascii codec can't decode and unicode mess
#
# check this out https://pythonhosted.org/kitchen/unicode-frustrations.html
# and this http://www.joelonsoftware.com/articles/Unicode.html
#
# The short of it is this
# 1. If you can, always set PYTHONIOENCODING=utf8 before you start your python programs.
# 2. If you can't or you can't ensure this, always use the following lambda _u to get unicode text
# whereever you convert to strings (str.format, str % etc.)
#
@myusuf3
myusuf3 / delete_git_submodule.md
Created November 3, 2014 17:36
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@jboner
jboner / latency.txt
Last active July 6, 2024 06:48
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@igniteflow
igniteflow / redis-producer-consumer.py
Created February 20, 2012 16:37
A very simple implementation of a Redis producer-consumer messaging queue in Python
import redis
import time
import sys
def producer():
r = redis.Redis()
i = 0
while True:
r.rpush('queue', 'Message %d' % i)