This file contains hidden or 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 | |
from PIL import Image | |
from argh import arg, dispatch_command | |
import os | |
def gen_assets(rootdir, force=False): | |
for root, dirs, files in os.walk(rootdir): | |
for d in dirs: | |
gen_thumb(os.path.join(root, d), force=force) | |
for f in files: |
This file contains hidden or 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 lxml | |
root = lxml.html.parse(filename).getroot() | |
# in case the file contains unicode characters | |
parser = lxml.html.HTMLParser(encoding='utf-8') | |
root = lxml.html.parse(filename, parser=parser).getroot() | |
# get matched elements using css selector | |
els = root.cssselect('div.shop-info div.info-name h2 a') |
This file contains hidden or 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 DoublyLinkedList(object): | |
# Copied from Python standard Library Lib/collections.py | |
# The circular doubly linked list starts and ends with a sentinel element. | |
# The sentinel element never gets deleted (this simplifies the algorithm). | |
# Each link is stored as a list of length three: [PREV, NEXT, VAL]. | |
def __init__(self): | |
self.__root = root = [] # sentinel node | |
root[:] = [root, root, None] | |
def append(self, val): |
This file contains hidden or 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
@app.route('/download', methods=['GET']) | |
def download(): | |
data = json.dumps({"example" : "json string"}) | |
response = make_response(data) | |
response.headers['Content-Type'] = 'text/json' | |
response.headers['Content-Disposition'] = 'attachment; filename=example.json' | |
return response |
This file contains hidden or 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 -*- | |
# ############################################################################ | |
# This example demonstrates how to use the MultipartEncoderMonitor to create a | |
# progress bar using clint. | |
# ############################################################################ | |
from clint.textui.progress import Bar as ProgressBar | |
from requests_toolbelt import MultipartEncoder, MultipartEncoderMonitor |
This file contains hidden or 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
from fabric.api import local | |
def sh(command, *args, **kwargs): | |
frame = inspect.currentframe() | |
ctx = frame.f_back.f_globals.copy() | |
ctx.update(frame.f_back.f_locals) | |
command = command.format(**ctx) | |
del frame | |
return local(command, *args, **kwargs) |
This file contains hidden or 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
[ | |
{ | |
"id": 58379, # 主题的ID | |
"title": "Welcome to Glow!", # 主题的标题 | |
"content": "Tell us a little bit about yourself. Where are you from? How old are you?", # 主题的内容 | |
"tag": "Glow Support", # 主题的标签 | |
"views": 9993, # 主题的浏览次数 | |
"time_created": 1415604639 # 主题的创建时间(unix时间戳) | |
"author": { # 主题的作者信息 | |
"id": 72057594048471049, |
This file contains hidden or 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
# Engineer Culture at Glow | |
--- | |
## Should we really care about culture at startups? | |
Good culture makes a company more efficient and scalable | |
- Lower communication cost | |
- Helps individual development, especially for junior members | |
- Makes the team unique |
This file contains hidden or 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
from gevent import monkey | |
monkey.patch_all() | |
import requests | |
import gevent | |
import traceback | |
from gevent.pool import Pool | |
def imap(urls, size, break_time=None): |