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
# -*- coding: utf-8 -*- | |
print('Hello, my Gist!') |
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
# Py 文件所在目录 | |
import os | |
print(__file__) # 包括文件名 | |
print(os.path.dirname(os.path.abspath(__file__))) | |
# REDIS SET ADD | |
import redis | |
r = redis.Redis(host='localhost', port=6379, db=0) |
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
# Check http://stackoverflow.com/questions/17285826/flask-redirecting-multiple-routes for more details. |
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 opcount(fname): | |
with open(fname) as f: | |
for i, l in enumerate(f): | |
pass | |
return i + 1 |
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 os | |
import fnmatch | |
matches = [] | |
for root, dirs, files in os.walk('/Users/arischow/Desktop/data'): | |
for file in fnmatch.filter(files, '*.txt'): | |
matches.append(os.path.join(root, file)) |
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 random | |
# 生成5个0~9的不重复随机数 | |
print random.sample(range(10), 5) | |
# [7, 9, 6, 2, 3] | |
# 从a~d中取出不重复的三个字母 | |
print random.sample(['a', 'b', 'c', 'd'], 3) | |
# ['d', 'b', 'c'] |
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
// Get all query string | |
var after_slash = window.location.search // "search?number=007&name=Aris&addr=PHP+is+the+best" | |
var urlParams = new URLSearchParams(window.location.search); | |
console.log(urlParams.get('number')); // "007"; | |
console.log(urlParams.get('name')); // "Aris" | |
console.log(urlParams.get('addr')); // "PHP is the best"; | |
console.log(urlParams.has('name')); // true | |
console.log(urlParams.append('language', 'zh_CN')); // "?number=007&name=Aris&addr=PHP+is+the+best&language=zh_CN" |
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
# dropping a database via pymongo | |
from pymongo import Connection | |
client = MongoClient() # default host localhost, port 27017 | |
client.drop_database('mydatabase') | |
# drop a collection via pymongo | |
from pymongo import Connection | |
client = MongoClient() | |
client['mydatabase'].drop_collection('mycollection') |
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
# Based on https://medium.com/@adriennedomingus/soft-deletion-in-django-e4882581c340 | |
# There’s one other thing that might be interesting to point out about the implementation of the soft-deletion: the unique together constraint. | |
# If you have a model with a unique together rule for fields ‘a’ and ‘b’, when an entry with the values ‘a=1’ and ‘b=2’ is soft-deleted, another one could not be created with the same values for those fields. So the ‘deleted_at’ has to be included on the constraint. | |
from django.db import models | |
from django.utils import timezone | |
class HasDeletedError(Exception): | |
pass |
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
# DAZN | |
DOMAIN-SUFFIX,dazn.com | |
DOMAIN-SUFFIX,dca-ll-voddazn-dznvodjp.s.llnwi.net | |
DOMAIN-SUFFIX,control.kochava.com | |
DOMAIN-SUFFIX,startup-prod.dazn.com | |
DOMAIN-SUFFIX,tags.dazn.com | |
DOMAIN-SUFFIX,api.playback.indazn.com | |
DOMAIN-SUFFIX,rail.discovery.indazn.com | |
DOMAIN-SUFFIX,dc2-vodhls-perform.secure.footprint.net | |
DOMAIN-SUFFIX,favourites-prod.api.dazn.com |
OlderNewer