Skip to content

Instantly share code, notes, and snippets.

🐶
🐸+1

Yao Zuo laike9m

🐶
🐸+1
Block or report user

Report or block laike9m

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View extended_arg.py
# Tests how EXTENDED_ARG works
import bytecode
import dis
import sys
from bytecode import ConcreteInstr, ConcreteBytecode
CONST_ARG = 0x1234567 # The real argument we want to set.
cbc = bytecode.ConcreteBytecode()
cbc.consts = [None] * (CONST_ARG + 1) # Make sure co_consts is big enough.
@laike9m
laike9m / manually_maintain_stack.py
Created May 28, 2019
Record call arguments by manually recording VM stack.
View manually_maintain_stack.py
import dis
import sys
def g(x, y):
# Code that analyzes outer frame to get passed in arguments.
outer_frame = sys._getframe(1)
instructions = list(dis.get_instructions(outer_frame.f_code))
call_start_offset = None
View test.py
def xxxx(ph, sin_id):
with OracleConnect(xxxx) as db_oracle:
sql = u"xxxxx"
has_data, sql_data = db_oracle.get_one(sql)
if has_data:
return sql_data.get("task_id", ""), "rollback"
else:
return sin_id, "calculate"
View freeze_bug.py
# test.py
with freeze_time(datetime.datetime(2016, 2, 10, tzinfo=pytz.timezone('US/Pacific'))):
from mymodule import date_manager
# mymodule.py
class _DateManager(object):
def __init__(self):
self._today = datetime.datetime.now(pytz.timezone('US/Pacific'))
View 百度网盘加速(北京)
61.135.186.214 baidupcs.com
61.135.186.214 cdn.baidupcs.com
61.135.186.214 sslpcslimit.jomodns.com
View pool_connections&pool_maxsize.py
import requests
from requests.adapters import HTTPAdapter
from threading import Thread
import logging
logging.basicConfig(filename='out.txt', level=logging.DEBUG, filemode='w')
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
@laike9m
laike9m / django_cache_for_views.py
Last active Aug 29, 2015
Simple Djano cache system for function/class-based views with automatic key generation
View django_cache_for_views.py
#!/usr/bin/env python
# coding: utf-8
from asset.models import *
from common.models import *
from cost.models import *
from django.core.cache import cache
import inspect
from django.contrib.contenttypes.models import ContentType
from django.db.models.signals import pre_save, pre_delete
You can’t perform that action at this time.