Skip to content

Instantly share code, notes, and snippets.

View xsthunder's full-sized avatar
💪
working

xsthunder

💪
working
  • everywhere
View GitHub Profile
@xsthunder
xsthunder / built_in_xml_reader.py
Created February 27, 2019 03:28
parse html or xml into dom
# see ()[https://stackoverflow.com/a/40749716]
from xml.dom.minidom import parseString
html_string = """
<!DOCTYPE html>
<html><head><title>title</title></head><body><p>test</p></body></html>
"""
# extract the text value of the document's <p> tag:
@xsthunder
xsthunder / split_and_counter_hitter.py
Created February 28, 2019 05:25
split string array by regex spliter, counter value frequency
import pandas as pd
def conlusion_hitter_df(arr):
conclusion_counter = {}
def per_item(ac, item):
v = item
if v not in ac:
ac[v] = 0
ac[v] = ac[v] + 1
return ac
conclusion_counter = reduce(per_item, arr, conclusion_counter)
@xsthunder
xsthunder / to_number.py
Created February 28, 2019 05:32
encode string to number and decode number
class To_Number:
def __init__(self, start_of_index = 0, ):
self.end_of_index = start_of_index
self.start_of_index = start_of_index
self.dict={}
self.decode_dict={}
def add(self, ele):
if ele not in self.dict:
self.dict[ele] = self.end_of_index
self.decode_dict[self.end_of_index] = ele
@xsthunder
xsthunder / calling-an-external-command.py
Created February 28, 2019 07:58
Calling an external command in Python
# https://stackoverflow.com/questions/89228/calling-an-external-command-in-python
import subprocess
subprocess.run(["ls", "-l"])
@xsthunder
xsthunder / split_and_match.py
Last active March 16, 2019 02:49
split str by regex,search each str with regex using grouping
# for splitting by regex see https://blog.csdn.net/programmer_at/article/details/77409507
spliters = [
r';',
]
reg = '(胰腺|肝脏)(.+)'
key_names=['部位','情况']
text = '胰腺未见局灶性占位。; 肝脏未见明显局灶性占位。;yes'
import re
def f(spliters, reg, key_names, text, throw_on_unmatch = False):
arr = re.split('|'.join(
@xsthunder
xsthunder / tqdm.py
Created April 28, 2019 11:30
tqdm.py
from tqdm import tdqm
for i in tqdm(range(100)):
print(i)
/**
* recursively resolve children if exits
* obj = {
* name,
* icon,
* } ->{
* ...obj,
* meta:{title:name, icon:icon}
* }
* @param Object obj
// in main.js
import Router from 'vue-Router'
vue.use(Router)
const originalPush = router.push
router.push = function(obj, ...params){
const current = this.history.current
// console.log(this, current)
const currentPath = current.path
const prefix = "/simed/"
if(obj instanceof Object && obj['doNotHack'] !== true){
@xsthunder
xsthunder / dict_in_insertation_order.py
Last active June 2, 2020 10:48
dict orders its key-value pairs in insertation order from python 3.7
# for each value(which is a dict) of input0, reorder the value dict in ascending order constructing output
import sys
assert float(sys.version[:3]) >= 3.7, """
this code only available from python version 3.7, see following for detail
https://stackoverflow.com/questions/39980323/are-dictionaries-ordered-in-python-3-6/39980744
dict orders its key-value pairs in insertation order
"""
input0 = {
'a':{
.container{
width: 500px;
display: flex;
flex-direction: column;
background: yellow;
}
.container-eachline{
display: flex;
flex-direction: row;
margin-top: 10px;