Skip to content

Instantly share code, notes, and snippets.

View Kuanlin-Chen's full-sized avatar

Corey Kuanlin-Chen

View GitHub Profile
Key Description
wim_file_path The path of the WIM file from the mounted ISO.
image_name Windows version that will be used.
image_path The destination of the generated image.
virtual_disk_format Select between VHD VHDX QCOW2 VMDK or RAW.
image_type Choose between MAAS KVM VMware or Hyper-V
cpu_count The number of CPU cores assigned to the VM.
ram_size RAM (bytes) assigned to the VM used to generate the image.
disk_size Disk space (bytes) assigned to the boot disk for the VM.
external_switch The name of the virtual switch that VM will be using.
Key Section Default Vlue
wim_file_path default D:\Sources\install.wim
image_name default Windows Server 2012 R2 SERVERSTANDARD
image_path default ${ENV:TEMP}\win-image.vhdx
virtual_disk_format default VHDX
image_type default HYPER-V
cpu_count vm 1
ram_size vm 2147483648
disk_size vm 42949672960
external_switch vm external
@Kuanlin-Chen
Kuanlin-Chen / get_port_from_serial.rb
Created June 5, 2019 03:35
Get USB bus/port information from serial number.
#!/usr/bin/env ruby
=begin
Pass the serial number of device to this program, it will print the corresponding usb bus/port info.
Example:
$ adb devices
List of devices attached
56789AAAAAAAAAA device
@Kuanlin-Chen
Kuanlin-Chen / merge_sheets.py
Last active November 1, 2022 02:53
Merge multiple Excel sheets
#!/usr/bin/env python
#
# Program:
# This program will merge multiple sheets in an excel file.
import sys
import xlwt
from xlrd import open_workbook
def main(orig_args):
@Kuanlin-Chen
Kuanlin-Chen / build.gradle
Created February 23, 2019 09:14
Check command exists or not in Gradle.
task checkCommand{
doLast{
def result = exec{
def command = "command -v docker"
ignoreExitValue = true
executable "bash" args "-l", "-c", command
}
if(result.getExitValue()==0){
println "Has Docker"
}else{
@Kuanlin-Chen
Kuanlin-Chen / nested_string_splitting.bat
Created February 23, 2019 08:16
Split string by space first, then split the 6th string by colon.
@ECHO off
for /f "tokens=1,2,3,4,5,6" %%a in ('adb devices -l') do (
if "%%b" == "device" (
ECHO Serial Number : %%a
for /f "tokens=2 delims=:" %%A in ( "%%f" ) do (
ECHO Transport Id : %%A
start adb_by_transportid.bat %%A
)
)
)
@Kuanlin-Chen
Kuanlin-Chen / BootstrapTableBuilder.java
Last active January 11, 2019 12:22
Generate Bootstrap Table
/*
* BootstrapTableBuilder bsTable = new BootstrapTableBuilder();
* bsTable.addTableHeader("Weight Table", 3, "Age", "Name", "Weight");
* bsTable.addRowValues("26", "Corey", "75");
* bsTable.addRowValues("25", "Daisy", "60");
* bsTable.addRowValues("30", "Kevin", "100");
* String table = bsTable.build();
*/
public class BootstrapTableBuilder {
@Kuanlin-Chen
Kuanlin-Chen / Dockerfile
Created January 8, 2019 12:59
Run Firefox in Docker with GUI.
FROM ubuntu:18.04
# docker build -t firefox .
# docker run -ti --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix firefox
# install firefox
# -y: assume yes as answer
RUN apt-get update && apt-get install -y firefox
# add user
@Kuanlin-Chen
Kuanlin-Chen / referendum_for_taipei.py
Last active January 8, 2019 12:15
Scrap and print data from 2018 Referendum.
from lxml import html
from lxml import etree
import requests
taipei_district_dic = {1:[527,644], 2:[644,786], 3:[1214,1402], 4:[786,919], 5:[1001,1097], 6:[919,1001],
7:[1097,1214], 8:[1402,1564], 9:[455,527], 10:[305,455], 11:[142,305], 12:[1,142]}
print '==================== Vote for Same-Sex Marriage ===================='
for num in range(1,13):
url_head = 'http://referendum.2018.nat.gov.tw/pc/zh_TW/08/m6300000'
@Kuanlin-Chen
Kuanlin-Chen / cherrypick.py
Last active November 1, 2022 02:52
Cherry-pick changes from commit list remotely.
import sys
from pygerrit2 import GerritRestAPI, HTTPBasicAuth
import base64
import json
from urllib2 import HTTPError
auth = HTTPBasicAuth('username','passwd')
rest = GerritRestAPI(url='http://gerrit.xxxxxx.com:8080', auth=auth)
class Gerrit: