This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use memory mapping to copy any file on disk to stdout. | |
#include <unistd.h> | |
#include <sys/mman.h> | |
#include <stdio.h> | |
#include <fcntl.h> | |
int main(int argc, char **argv) { | |
long sz; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lxml.html | |
from lxml import etree | |
root = etree.fromstring(open('UserDefine-UUT ID-2019_02_27_01_51_00_179--00_P.xml').read()) | |
# Get all "Test" nodes | |
root.xpath('//Test') | |
# Get date stamp | |
'/'.join((root.xpath('./*[1]/Date/YYYY')[0].text, root.xpath('./*[1]/Date/MM')[0].text, root.xpath('./*[1]/Date/DD')[0].text)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get a table object | |
table = driver.find_element_by_class_name('my_table_class') | |
# Get all rows, including rows in rows | |
rows = table.find_elements_by_tag_name('tr') | |
# Get header which is in the first row | |
# Get text from <th> element | |
header = rows[0] | |
header_text_list = [i.text for i in header.find_elements_by_tag_name('th')] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# webdriver can initialize object that control supported browsers, such as Chrome | |
from selenium import webdriver | |
# Keys contain keyboard keys such as left arrow | |
from selenium.webdriver.common.keys import Keys | |
# Select can wrap html <select> tag into an object that has powerful methods | |
from selenium.webdriver.support.ui import Select | |
# this is a parser for HTML | |
import lxml.html | |
# Create driver object |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python decorator is a convenient way to wrap functions with reused logic | |
def Dec(F): | |
def G(*args): | |
print('wrapper starts') | |
F(*args) | |
print('wrapper ends') | |
return G | |
@Dec |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# descriptor, is like a simplification on property | |
# one descriptor can be used in multiple classes, instead of repeated property definitions | |
class Name: | |
def __get__(self, instance, owner): | |
print(instance, 'get name') | |
return instance._name | |
def __set__(self, instance, value): | |
print(instance, 'set name to', value) | |
instance._name = value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter as tk | |
from tkinter import ttk | |
import tkinter.messagebox as mbx | |
import tkinter.filedialog as fdg | |
import tkinter.scrolledtext as stxt | |
class MyWindow(tk.Tk): | |
def __init__(self, screenName=None, baseName=None, className='Tk', useTk=1, sync=0, use=None, | |
geometry='600x400', title='My tkinter Window'): | |
super().__init__(screenName, baseName, className, useTk, sync, use) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def merge_sort(input_list: list) -> list: | |
"""Sort list using merge sort algorithm. | |
:param input_list: list to be sorted. | |
:type input_list: list | |
:return: sorted list in ascending order. | |
:rtype: list | |
""" | |
def merge(lst:list, p: int, q: int, r: int): | |
"""Helper function for merge sort: merge lst[p:q+1] and lst[q+1:r+1]. | |
:param lst: list to be sorted. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def insertion_sort(input_list: list) -> list: | |
"""Sort a list with insertion sort algorithm. | |
:param input_list: a list to be sorted. | |
:type input_list: list | |
:return: sorted list in ascending order. | |
:rtype: list | |
""" | |
# Check if need to sort | |
if input_list == [] or len(input_list) == 1: | |
return input_list |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adb devices | |
adb shell screencap -p /sdcard/screen.png | |
adb pull -p -a /sdcard/screen.png | |
adb shell rm /sdcard/screen.png | |
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b) | |
For /f "tokens=1-3 delims=/:" %%a in ("%TIME%") do (set mytime=%%a-%%b-%%c) | |
set mytime=%mytime: =% |
NewerOlder