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 time | |
import sys | |
import MultipartPostHandler, urllib2, cookielib | |
import threading | |
st = 0 | |
def test(url): | |
# cookies = cookielib.CookieJar() | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(), |
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 sys | |
import os | |
import traceback | |
import hashlib | |
from flask import Flask, request, redirect, jsonify, abort | |
app = Flask(__name__) | |
_HERE = os.path.dirname(os.path.abspath(__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
upstream frontends { | |
server 127.0.0.1:8222; | |
} | |
server { | |
listen 8666; | |
# Allow file uploads max 50M for example | |
client_max_body_size 50M; | |
upload_buffer_size 16M; |
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 get_free_space(folder): | |
""" Return folder/drive free space | |
""" | |
if platform.system() == 'Windows': | |
free_bytes = ctypes.c_ulonglong(0) | |
ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes)) | |
return free_bytes.value | |
else: | |
st = os.statvfs(folder) | |
return st.f_bavail * st.f_frsize |
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
### in a seperated file define the function | |
from django.core.exceptions import SuspiciousOperation | |
def skip_suspicious_exception(record): | |
if record.exc_info: | |
exc_type, exc_value = record.exc_info[:2] | |
if isinstance(exc_value, SuspiciousOperation): | |
return False | |
return True | |
### in settings.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 copy | |
a = set([hashabledict({1:11}), hashabledict({2:22})]) | |
b = set([hashabledict({1:11}), hashabledict({3:33})]) | |
for i in range(3): | |
print "set a:", a | |
delta = a-b | |
print "delta", delta | |
for item in copy.deepcopy(delta): | |
print id(item) | |
item[1] = "xx" |
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
a = set([hashabledict({1:11}), hashabledict({2:22})]) | |
b = set([hashabledict({1:11}), hashabledict({3:33})]) | |
for i in range(3): | |
print "set a:", a | |
delta = a-b | |
print "delta", delta, id(delta) | |
for item in delta: | |
print id(item) #always same | |
item[1] = "xx" | |
print "*"*10 |
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
a = set([hashabledict({1:11}), hashabledict({2:22})]) | |
b = set([hashabledict({1:11}), hashabledict({3:33})]) | |
for i in range(3): | |
print "set a:", a, id(a) | |
copyofa = set(a) | |
print "shallow copy ofset a:", copyofa, id(copyofa) | |
delta = copyofa-b | |
print "delta", delta | |
for item in delta: | |
print id(item) |
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
db.pop.aggregate([ | |
{$group:{_id:{state:"$state",city:"$city"}, allpop:{$sum:"$pop"}}}, | |
{$match:{allpop:{$gt:25000},"_id.state":{$in:["CA","NY"]}}}, | |
{$group:{_id:null, avgpop:{$avg:"$allpop"}}} | |
] | |
) |
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
db.posts.aggregate([ | |
{$project:{comments:1, author:1}}, | |
{$unwind:"$comments"}, | |
{$group:{_id:"$comments.author",commentnum:{$sum:1}}}, | |
{$sort:{commentnum:-1}}, | |
{$limit:2} | |
]); |
OlderNewer