Skip to content

Instantly share code, notes, and snippets.

@georgexsh
georgexsh / sqlite_kv_concurrent.py
Created January 17, 2022 06:06
sqlite_kv_concurrent.py
import time
import sqlite3
import os
import random
import multiprocessing
class Store1:
"""sharding to tables"""
@georgexsh
georgexsh / queue_dead_lock.py
Created May 6, 2020 08:55
queue_dead_lock.py
import os
import Queue
import threading
def f(q):
while True:
try:
q.get(block=False)
except Queue.Empty:
@georgexsh
georgexsh / redis.log
Last active March 17, 2020 02:17
strange redis log
1:M 16 Mar 06:48:01.553 * DB saved on disk
1:S 16 Mar 11:31:32.720 * Before turning into a slave, using my master parameters to synthesize a cached master: I may be able to synchronize with the new master with just a partial transfer.
1:S 16 Mar 11:31:32.720 * SLAVE OF 82.118.17.133:8887 enabled (user request from 'id=4 addr=172.18.0.1:42860 fd=8 name= age=0 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=slaveof')
1:S 16 Mar 11:31:33.143 * Connecting to MASTER 82.118.17.133:8887
1:S 16 Mar 11:31:33.143 * MASTER <-> SLAVE sync started
@georgexsh
georgexsh / # git - 2018-09-17_11-52-37.txt
Created September 17, 2018 04:40
git on macOS 10.13.6 - Homebrew build logs
Homebrew build logs for git on macOS 10.13.6
Build date: 2018-09-17 11:52:37
@georgexsh
georgexsh / cal_chef_repo_size.py
Created March 16, 2018 02:58
calculate chef yum repo size
import requests
import re
total = 0
for arch in ['aarch64', 'ppc64', 'ppc64le', 's390x', 'x86_64']:
for ver in range(5, 8):
r = requests.get(f'https://packages.chef.io/repos/yum/stable/el/{ver}/{arch}/')
s = r.text
m = re.findall(r'([\d.]+) MB', r.text)
one = sum(map(float, m))
@georgexsh
georgexsh / py27_share_socket.py
Created October 30, 2017 07:31
share socket object with multiprocessing in python2.7
import os
import time
from multiprocessing import Process, Manager
import socket
import copy_reg
from multiprocessing.reduction import rebuild_socket, reduce_socket
copy_reg.pickle(socket.socket, reduce_socket, rebuild_socket)
@georgexsh
georgexsh / goto.py
Created September 18, 2017 07:47
python goto with system trace function
import sys
def j(lineno):
frame = sys._getframe().f_back
called_from = frame
def hook(frame, event, arg):
if event == 'line' and frame == called_from:
try:
frame.f_lineno = lineno
@georgexsh
georgexsh / shell.py
Created August 5, 2016 10:03
ipython unicode literals on startup
from IPython.terminal.ipapp import TerminalIPythonApp
app = TerminalIPythonApp.instance()
context = make_shell_context()
app.exec_lines = ['from __future__ import unicode_literals',]
app.user_ns = context
app.initialize(argv=['--no-banner',])
app.start()
@georgexsh
georgexsh / error.json
Last active June 14, 2016 11:10
sentry internal error
{
"culprit": "sentry/layout.html",
"datetime": "2016-06-14T10:56:55.000000Z",
"errors": [],
"extra": {
"sys.argv": [
"'uwsgi'"
]
},
"fingerprint": [
@georgexsh
georgexsh / ipipdb.py
Created September 16, 2015 10:10
ipip.net lib
# coding: utf-8
import struct
# opti
from socket import inet_aton
from bisect import bisect_left
_unpack_ul_little = lambda b: struct.unpack("<L", b)[0]
_unpack_ul_big = lambda b: struct.unpack(">L", b)[0]
_unpack_us_big = lambda b: struct.unpack(">H", b)[0]