View django_cache_for_views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
View pool_connections&pool_maxsize.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
View 百度网盘加速(北京)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61.135.186.214 baidupcs.com | |
61.135.186.214 cdn.baidupcs.com | |
61.135.186.214 sslpcslimit.jomodns.com |
View freeze_bug.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 manually_maintain_stack.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 extended_arg.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
View dot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
digraph "Cyberbrain Output" { | |
graph [forcelabels=true]; | |
node [label="\N"]; | |
subgraph "cluster_(0, 0, 0)" { | |
graph [color=lightgrey, | |
label="(0, 0, 0)", | |
overlap=scale, | |
style=filled | |
]; | |
node [color=white, |
View raw string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://wiki.c2.com/?RawStrings | |
Raw string 是个通用概念。即 escape 不生效的 string,既然不生效,也无法 escape 掉 ending sequence。 | |
所有语言的 raw string 都面临一个问题,即如何处理 ending sequence | |
Python | |
https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals | |
staring sequence: “ or ' | |
ending sequence: “ or ' | |
Python 的做法是允许 ‘, “ 出现,但需要用 \ escape 掉它们(相当于在 Python raw string里有唯一生效的escape就是\”和\’),并且 \ 依然会出现 |
View calc.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
""" | |
@param s: the expression string | |
@return: the answer | |
""" | |
def calculate(self, s): | |
i = 0 | |
left_brac_indexes = [] | |
while i < len(s): |
OlderNewer