Skip to content

Instantly share code, notes, and snippets.

View lanfon72's full-sized avatar
💭
Nothing new

Lanfon lanfon72

💭
Nothing new
View GitHub Profile
class Person(object):
def __init__(self, name):
self.name = name
def say(self,stuff):
return self.name + ' says:' + stuff
def __str__(self):
return self.name
class Lecture(Person):
def lecture(self, stuff):
import yaml
MONSTER = """
--- !Monster
name: Cave spider
hp: [2,6] # 2d6
ac: 16
attacks: [BITE, HURT]
"""
import yaml
class Monster(yaml.YAMLObject):
yaml_tag = u'!Monster'
def __init__(self, name, hp, ac, attacks):
self.name = name
self.hp = hp
self.ac = ac
@lanfon72
lanfon72 / vghks.py
Last active March 2, 2017 13:14
Kaohsiung Veterans General Hospital ER.
#!/usr/bin/env python
# coding: utf-8
import re
import os
import json
from datetime import datetime
import requests
import csv
import pickle
files = ['a.pickle', 'b.pickle', ...]
csv.register_dialect('mycsv', 'excel', delimiter=',')
for fil in files:
csv_name = "%s.csv" % fil.split('.')[0]
pf = open(fil, 'rb')
cf = open(csv_name, 'wb')
csvwriter = csv.writer(cf, dialect='mycsv')
csvwriter.writerows(pickle.load(pf))
@lanfon72
lanfon72 / hch.py
Last active December 4, 2016 02:13
NTU hospital hsin-chu branch ER board.
# !/usr/bin/env python
# coding:UTF-8
import re
import json
from datetime import datetime
import requests
requests.packages.urllib3.disable_warnings()
html = requests.get('https://www.hch.gov.tw/hch/Information/LatestNewsDetail.aspx?MNO=C025&ID=9791', verify=False)
@lanfon72
lanfon72 / tyh.py
Created March 1, 2016 04:12
tonyung hospital ER.
# !/usr/bin/env ptyhon
# coding:UTF-8
import requests, json, re
from datetime import datetime
html = requests.get('http://www.tyh.com.tw/ERActive/ERBMEIMS.aspx')
keys = ['pending_doctor', 'pending_bed', 'pending_ward', 'pending_icu']
pending = re.findall('".+">(.+?)</span>', html.text)
values = [int(ele) for ele in pending[1:5]]
def try_else(x, y):
a = lambda x, y: x % y
b = lambda x, y: x / y
try:
result = a(x,y) + b(x,y)
f = open('Cookie', 'w+')
except ZeroDivisionError as z:
print(z)
# divide by zero.
except PermissionError as p:
@lanfon72
lanfon72 / rmdict.py
Last active December 10, 2015 06:13
snippet
def rm_dict(dicts, keyword, recursive=True):
""" remove a keyword(k-v pair) from (nest) dict. default is recursived.
:param: dicts - an dict (nested allow).
:param: keyword - an tuple with 2 values, means (key, value).
:param: recursive - recursive search, default is True.
... admonition : doctest string below.
pretty a as:
a = \
{
'name':'adam',
@lanfon72
lanfon72 / infix_to_postfix.py
Created November 26, 2015 11:58
simple python
def bi_exp_tree(expstr):
""" infix to postfix.
>>> bi_exp_tree("(a+(b*c))")
'abc*+'
>>> bi_exp_tree("((a+b)*(z+x))")
'ab+zx+*'
>>> bi_exp_tree("((a+t)*((b+(a+c))^(c+d)))")
'at+bac++cd+^*'
"""
result = ""