Skip to content

Instantly share code, notes, and snippets.

@felinx
felinx / grab_instagram_users_photos.py
Created July 19, 2015 13:36
Grab instagram user's photos through client API
# -*- coding: utf-8 -*-
#
# Copyright(c) 2015 http://feilong.me
#
# @author: Felinx Lee <felinx.lee@gmail.com>
#
from tornado.httpclient import HTTPClient, HTTPRequest
from tornado import escape
import hashlib
@felinx
felinx / gist:5516568
Created May 4, 2013 07:09
tornado.options.options don't parse default value automatically
# -*- coding: utf-8 -*-
#
# Copyright (c) 2013 feilong.me All rights reserved.
#
# @author: Felinx Lee <felinx.lee@gmail.com>
# Created on May 4, 2013
#
"""
tornado.options.options don't parse default value automatically, sometimes,
# based on http://uberblo.gs/2011/06/high-performance-url-shortening-with-redis-backed-nginx
# using code from http://stackoverflow.com/questions/3554315/lua-base-converter
# "database scheme"
# database 0: id ~> url
# database 1: id ~> hits
# database 2: id ~> [{referer|user_agent}]
# database 3: id ~> hits (when id is not found)
# database 4: id ~> [{referer|user_agent}] (when id is not found)
# database 5: key "count" storing the number of shortened urls; the id is generated by (this number + 1) converted to base 62
@felinx
felinx / gist:3021514
Created June 29, 2012 23:59
Handling exif info(orientation) losing after thumbnail a image with PIL
def _thumbnail_image(self, body, size):
try:
im = Image.open(StringIO(body))
# rotate image according rotation meta of this image
# for orientation in ExifTags.TAGS.keys():
# if ExifTags.TAGS[orientation] == 'Orientation' : break
orientation = 274 # get 274 through upper loop
try:
exif = im._getexif()
@felinx
felinx / zipdb.py
Created June 20, 2012 01:56 — forked from mayli/zipdb.py
Use a zipfile store a dict like k-v database
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# zipdb.py
# Use a zipfile store a dict like k-v database.
# Known bug: duplicate key(filenames) allowed
#
# Copyright 2012 mayli <mayli.he@gmail.com>
#
@felinx
felinx / gist:899253
Created April 2, 2011 05:23
Get self.request.remote_ip when running tornado behind a reverse proxy
# To get remote_ip, it should set xheaders=True when initializing HTTPServer
http_server = HTTPServer(Application(), xheaders=True)