Skip to content

Instantly share code, notes, and snippets.


Han Feng hanx11

Block or report user

Report or block hanx11

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
import pygame, math
window = pygame.display.set_mode((600, 600))
pygame.display.set_caption("Fractal Tree")
screen = pygame.display.get_surface()
def drawTree(x1, y1, angle, depth):
if depth:
x2 = x1 + int(math.cos(math.radians(angle)) * depth * 10.0)
# -*- coding:utf-8 -*-
import codecs
from datetime import datetime
source_file = 'big_gbk_file.csv'
target_file = 'big_utf8_file.csv'
block_size = 10000 * 1024 # or some other, desired size in bytes
# -*- coding:utf-8 -*-
def fib(n):
a, b = 0, 1
for _ in range(n):
yield a
a, b = b, a + b
# -*- coding:utf-8 -*-
from datetime import datetime
def read_many_lines(fp, buffer_size=10000):
:param fp:
:param buffer_size: default 10000
hanx11 /
Created Mar 15, 2019 — forked from anthonydouc/
Radar chart using bokeh
import numpy as np
from bokeh.plotting import figure, show, output_file
from bokeh.models import ColumnDataSource, LabelSet
num_vars = 9
theta = np.linspace(0, 2*np.pi, num_vars, endpoint=False)
# rotate theta such that the first axis is at the top
theta += np.pi/2
hanx11 / gist:0028c5fe743e12cb6a43e973b477dc40
Created Nov 23, 2018 — forked from methane/gist:2185380
Tornado Example: Delegating an blocking task to a worker thread pool from an asynchronous request handler
View gist:0028c5fe743e12cb6a43e973b477dc40
from time import sleep
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.web import Application, asynchronous, RequestHandler
from multiprocessing.pool import ThreadPool
_workers = ThreadPool(10)
def run_background(func, callback, args=(), kwds={}):
def _callback(result):
hanx11 /
Created Nov 20, 2018 — forked from lbolla/
Asynchronous programming in Tornado

Asynchronous programming with Tornado

Asynchronous programming can be tricky for beginners, therefore I think it's useful to iron some basic concepts to avoid common pitfalls.

For an explanation about generic asynchronous programming, I recommend you one of the [many][2] [resources][3] [online][4].

I will focus on solely on asynchronous programming in [Tornado][1]. From Tornado's homepage:

hanx11 /
Created Nov 19, 2018 — forked from brimcfadden/
Using Pika asynchronously with tornado.web.RequestHandler
#!/usr/bin/env python
"""A Tornado example of RPC.
Designed to work with as found in RabbitMQ Tutorial #6:
Some code is borrowed from pika's tornado example.
hanx11 /
Created Nov 16, 2018 — forked from CMCDragonkai/
HTTP Streaming (or Chunked vs Store & Forward)

HTTP Streaming (or Chunked vs Store & Forward)

The standard way of understanding the HTTP protocol is via the request reply pattern. Each HTTP transaction consists of a finitely bounded HTTP request and a finitely bounded HTTP response.

However it's also possible for both parts of an HTTP 1.1 transaction to stream their possibly infinitely bounded data. The advantages is that the sender can send data that is beyond the sender's memory limit, and the receiver can act on

hanx11 /
Created Nov 14, 2018 — forked from sjlongland/
Tornado Coroutine interface to AMQP (pika)
import datetime
import logging
import threading
import weakref
import tornado
import tornado.gen
import pika
You can’t perform that action at this time.