Skip to content

Instantly share code, notes, and snippets.

🤡
Focusing

Han Feng hanx11

🤡
Focusing
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
View fractal_tree.py
import pygame, math
pygame.init()
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)
View process_big_file_v1.py
# -*- 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
View fib_gen.py
# -*- coding:utf-8 -*-
def fib(n):
a, b = 0, 1
for _ in range(n):
yield a
a, b = b, a + b
View process_big_gbk_file.py
# -*- coding:utf-8 -*-
from datetime import datetime
def read_many_lines(fp, buffer_size=10000):
"""
:param fp:
:param buffer_size: default 10000
:return:
@hanx11
hanx11 / Radar.py
Created Mar 15, 2019 — forked from anthonydouc/Radar.py
Radar chart using bokeh
View Radar.py
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
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
hanx11 / README.md
Created Nov 20, 2018 — forked from lbolla/README.md
Asynchronous programming in Tornado
View README.md

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
hanx11 / tornadoweb_pika.py
Created Nov 19, 2018 — forked from brimcfadden/tornadoweb_pika.py
Using Pika asynchronously with tornado.web.RequestHandler
View tornadoweb_pika.py
#!/usr/bin/env python
"""A Tornado example of RPC.
Designed to work with rpc_server.py as found in RabbitMQ Tutorial #6:
http://www.rabbitmq.com/tutorials/tutorial-six-python.html
Some code is borrowed from pika's tornado example.
"""
@hanx11
hanx11 / http_streaming.md
Created Nov 16, 2018 — forked from CMCDragonkai/http_streaming.md
HTTP Streaming (or Chunked vs Store & Forward)
View http_streaming.md

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
hanx11 / amqp.py
Created Nov 14, 2018 — forked from sjlongland/amqp.py
Tornado Coroutine interface to AMQP (pika)
View amqp.py
#!/usr/bin/python
import datetime
import logging
import threading
import weakref
import tornado
import tornado.gen
import pika
You can’t perform that action at this time.