Skip to content

Instantly share code, notes, and snippets.

View apwan's full-sized avatar

Yijie apwan

  • The University of Hong Kong
View GitHub Profile

Keybase proof

I hereby claim:

  • I am apwan on github.
  • I am wuyj (https://keybase.io/wuyj) on keybase.
  • I have a public key ASAgLnFoCB8WAkAkPr_KCUz2keFstldIzD2iz_pFcDTb6Ao

To claim this, I am signing this object:

@apwan
apwan / https_localhost.sh
Created March 5, 2020 21:41
test localhost https
#!/usr/bin/env bash
# simply test localhost https, set {rejectUnauthorized: false} when make requests to bypass certificate checking
node -e 'const app=require("https-localhost")(); app.get("/", (req, res)=>{console.log(req.headers); res.send("Hello");}); app.listen(443);'
@apwan
apwan / print_2p1d.py
Created October 28, 2019 12:11
print 2 pages per sheet and double side
# rearrange pages
def gen(n4):
n = n4//4
a1 = [[4*n-2*i, 2*i+1, 2*i+2, 4*n-2*i-1] for i in range(n)]
return [str(k) for x in a1 for k in x]
'''
Example: ','.join(gen(44))
Output: '44,1,2,43,42,3,4,41,40,5,6,39,38,7,8,37,36,9,10,35,34,11,12,33,32,13,14,31,30,15,16,29,28,17,18,27,26,19,20,25,24,21,22,23'
'''
@apwan
apwan / batch_grading.sh
Last active October 20, 2019 15:40
Batch grading using autograder.py from Berkeley AI course
#!/usr/bin/env bash
# batch_grading.sh for COMP3270
# by Yijie
# example:
# (1) ZIP_DIR=folder_of_decompressed_submissions STUDENT_ROOT=output_folder PROJECT=a1 timelimit=60s ./batch_grading.sh
# (2) ./batch_grading.sh summary time_60s.txt > error_ids.txt
CMD="$0"
ZIP_DIR=${ZIP_DIR:-../a1_zip} # download all submitted files and decompress into this directory
STUDENT_ROOT=${STUDENT_ROOT:-student_code}
@apwan
apwan / bashrc
Created July 29, 2019 04:52
useful shell functions for .bashrc
vicmd() {
[ "$#" -lt 1 ] && echo "Usage: $0 [CMD_name]" >&2 && return 1;
# check alias
#echo "type $(type -t $1)"
[[ "$(type -t $1)" =~ ("alias"|"builtin"|"function") ]] && echo "$1 is $(type -t $1), not a valid cmd! " >&2 && return 1
local CMD_="$(which $1 2>/dev/null)"
[ -x "$CMD_" ] && vi "$CMD_" || vi "$MY_SHARE_HOME/bin/$1"
}
@apwan
apwan / check_cron
Last active July 28, 2019 10:36
daemon for git/pypi http server
# check if git/pypi http servers fail # crontab -e
*/20 * * * * root /usr/bin/bash -c ". ~/.bashrc; svgits.sh --check >/dev/null 2>&1"
*/30 * * * * root /usr/bin/bash -c ". ~/.bashrc; svpypis.sh --check >/dev/null 2>&1"
@apwan
apwan / merge_va.sh
Last active October 31, 2018 16:54
merge audio and video file in ffmpeg
# source: https://superuser.com/questions/277642/how-to-merge-audio-and-video-file-in-ffmpeg
# merge with audio re-encoding
ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac -strict experimental output.mp4
# merge without audio re-encoding
ffmpeg -i video.mp4 -i audio.wav -c copy output.mkv
# replace audio stream
ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac -strict experimental \
@apwan
apwan / wget.py
Created September 9, 2018 16:13
python download file
#!/usr/bin/env python
import urllib.request
def get_img(img_src, img_name):
contents = urllib.request.urlopen(img_src).read()
with open(img_name, 'wb') as f
f.write(contents)
@apwan
apwan / read_csv.js
Last active September 9, 2018 13:29
js version read_csv (mimic python version)
const fs = typeof require != 'undefined'? require('fs'): {};
function catFile(path){
return fs.readFileSync(path).toString()
}
function CSVToArray(strData, strDelimiter) {
// Check to see if the delimiter is defined. If not,
// then default to COMMA.
strDelimiter = (strDelimiter || ",");
@apwan
apwan / app.js
Created September 9, 2018 09:54
Use start-stop-daemon to launch/exit node app.
#!/usr/bin/env node
//app.js
var http = require('http');
server = http.createServer(function(req, res){
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<h1>Node.js</h1>');
res.end('<p>Hello World</p>');
}).listen(process.env.PORT||4321);