Skip to content

Instantly share code, notes, and snippets.

View tristan2077's full-sized avatar

TristanHou tristan2077

  • Shanghai
View GitHub Profile
@tristan2077
tristan2077 / gen_code.py
Last active July 19, 2019 07:49
一种动态运行代码的方法
import importlib
func_text = """
def add(a,b):
return a + b
"""
with open('func.py', 'w') as f:
f.writelines(func_text)
try:
@tristan2077
tristan2077 / python hook class deco.py
Last active May 29, 2019 09:11
函数执行前后hook
from functools import wraps
def _exec_hook(hook_name, self):
if hasattr(self, hook_name):
getattr(self, hook_name)()
def hooks(fn):
@wraps(fn)
def hooked(self):
@tristan2077
tristan2077 / serialNumInfo()
Created April 23, 2019 08:42 — forked from ptdecker/serialNumInfo()
Evaluates a mobile device serial number, determines its type (ESN, IMEI, MEID) and attempts to check for validity if possible.
// serialNumInfo()
//
// Evaluates a mobile device serial number, determines its type (ESN, IMEI, MEID) and attempts
// to check for validity if possible.
//
// When the passed purported serial number, the serialNumInfo() function returns a boolean flag
// ('isValid') indicating the validity of the number along with 'numType' indicating the type of
// serial number passed. The function expects the passed serialNumber to be not contain any
// spaces and for hexadecimal values to be passed without a leading "0x" or "0h" prefix.
//
@tristan2077
tristan2077 / checkIn.go
Last active February 22, 2019 01:44
redis签到golang实现
package main
import (
"fmt"
"github.com/gomodule/redigo/redis"
"time"
)
//redis bitmap
// getbit setbit bitfield
package main
import (
"fmt"
"strconv"
)
type Position struct{
X int
Y int
@tristan2077
tristan2077 / base.py
Created October 16, 2018 03:00
sqlalchemy添加sql执行的语句和时间
from sqlalchemy.engine import Engine
from sqlalchemy import event
import time
import logging
logging.basicConfig()
@tristan2077
tristan2077 / gist:217935e9445d05072f6da9a96ee21d61
Created August 8, 2018 02:38 — forked from jennyq/gist:5671585
Install m2crypto on Mac
When running "pip install m2crypto" in a virtualenv, I got the following error:
Downloading/unpacking m2crypto
Running setup.py egg_info for package m2crypto
Installing collected packages: m2crypto
Running setup.py install for m2crypto
building 'M2Crypto.__m2crypto' extension
swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
swig -python -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/usr/include -includeall -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i
import sys
# This code exists for backwards compatibility reasons.
# I don't like it either. Just look the other way. :)
for package in ('urllib3', 'idna', 'chardet'):
locals()[package] = __import__(package)
# This traversal is apparently necessary such that the identities are
# preserved (requests.packages.urllib3.* is urllib3.*)
for mod in list(sys.modules):
def validate(self):
"""
Validates the form by calling `validate` on each field, passing any
extra `Form.validate_<fieldname>` validators to the field validator.
"""
extra = {}
for name in self._fields:
inline = getattr(self.__class__, 'validate_%s' % name, None)
if inline is not None:
extra[name] = [inline]
opts = new_class._meta = ModelFormOptions(getattr(new_class, 'Meta', None))