Skip to content

Instantly share code, notes, and snippets.

View lanfon72's full-sized avatar
💭
Nothing new

Lanfon lanfon72

💭
Nothing new
View GitHub Profile
import time
import asyncio
from concurrent import futures
def primes(num):
rv = []
p = [0] * num
k, n = 0, 2
print("start time:", time.time())
@lanfon72
lanfon72 / export.py
Created June 8, 2017 03:39
export word images via python win32com
from pathlib import Path
from win32com.client import Dispatch
xls = Dispatch("Excel.Application")
doc = Dispatch("Word.Application")
def export_images(fp, prefix="img_", suffix="png"):
""" export all of images(inlineShapes) in the word file.
@lanfon72
lanfon72 / 2.py
Created May 17, 2017 15:51
asyncio.callback
import asyncio
def q(val, fut):
print(val)
fut.set_result(val)
def cb(fut):
r = fut.result()
@lanfon72
lanfon72 / 1.py
Created May 17, 2017 15:50
asyncio.callback
import asyncio
loop = asyncio.get_event_loop()
def p(val, stop=False):
print(val)
if stop:
loop = asyncio.get_event_loop()
loop.stop()
@lanfon72
lanfon72 / 3.py
Last active May 17, 2017 15:49
asyncio.callback
import time
import asyncio
def q2(val):
print("delay 1 second")
time.sleep(1)
print(val)
@lanfon72
lanfon72 / app.py
Created May 11, 2017 08:43
routing decorator for flask MethodView
from types import MethodType
from weakref import WeakValueDictionary
from flask import Flask, views
_cached = WeakValueDictionary()
def _route(self, rule, **options):
def wrapper(cls):
@lanfon72
lanfon72 / cmuh.py
Created March 3, 2017 14:39
parse cmuh live ER status board.
#!/usr/bin/env python
# coding:UTF-8
import re
import os
import json
from datetime import datetime
import requests
@lanfon72
lanfon72 / ohlc.py
Created February 7, 2017 09:22
OHLC chart with XlsxWriter.
# extended from http://xlsxwriter.readthedocs.io/example_chart_stock.html
from datetime import datetime
import xlsxwriter
workbook = xlsxwriter.Workbook('chart_ohlc_stock.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': 1})
date_format = workbook.add_format({'num_format': 'dd/mm/yyyy'})
@lanfon72
lanfon72 / sample.py
Created January 19, 2017 12:21
a generator class to shuffle large number.
import os
from array import array
from random import sample
from collections import deque
from os.path import exists
class Shuffler:
def __init__(self, stop, buff=100000, cache=10000):
@lanfon72
lanfon72 / part.py
Last active November 23, 2016 16:32
# scope is thread class.
def run(self):
if self.step.isOpen():
with open('gcode/cathy.gcode', 'r') as f:
gcode = (line for line in f.readlines()) # generator.
while 1:
if self.is_pause:
time.sleep(0.5)
continue
try: