Skip to content

Instantly share code, notes, and snippets.

View YiqinZhao's full-sized avatar
🎯
Focusing

Yiqin Zhao YiqinZhao

🎯
Focusing
View GitHub Profile
@YiqinZhao
YiqinZhao / Apple Icon Generator
Created August 2, 2020 19:03
Generate icon with multiple scaled size for Apple platform.
from PIL import Image
img = Image.open('./icon.png')
sizes = [16, 32, 128, 256, 512]
for s in sizes:
img_resized = img.resize((s, s))
img_resized.save(f'./dist/icon-{s}x{s}@1x.png')
@YiqinZhao
YiqinZhao / hard-break-fixer.py
Created April 4, 2020 21:37
A dirty script for removing hard line break in Markdown files.
#!/usr/bin/env python3
import re
import sys
f = open(sys.argv[-1], 'r+')
document = f.read()
build = ''
@YiqinZhao
YiqinZhao / ua.py
Created March 1, 2019 07:02
Keras multi-class average recall (aka. unweighted accuracy) metric.
class MulticlassAverageRecall(Layer):
def __init__(self, name='multiclass_recall', classes=4,
output_idx=0, **kwargs):
super(MulticlassAverageRecall, self).__init__(name=name, **kwargs)
self.stateful = True
self.classes = classes
self.output_idx = output_idx
self.t = K.variable(np.zeros(classes), dtype='int32')
@YiqinZhao
YiqinZhao / result.py
Created December 24, 2018 14:18
Training Result Utility
import math
import pandas as pd
import numpy as np
from keras.models import Model
from keras.callbacks import Callback
from sklearn.metrics import confusion_matrix
@YiqinZhao
YiqinZhao / bastard.py
Last active December 5, 2018 12:19
GPU Bastard, control the resource belong to you!
import os
import time
import argparse
import GPUtil
from multiprocessing import Process
parser = argparse.ArgumentParser(description='GPU Bastard, control the resource belong to you!')
parser.add_argument('--index',
help='GPU Index',
@YiqinZhao
YiqinZhao / SavePredictResult.py
Last active April 9, 2018 01:38
Automatic confusion matrix calculation
'''
Automatic Keras callback class for:
- Confusion matrix calculation
- Weighted accuracy(AKA. WA)
- Unweighted accuracy(AKA. UA)
- Label distribution
- Predict correctness
Dependences: pandas, numpy
@YiqinZhao
YiqinZhao / index.js
Created March 22, 2018 02:24
[Promise waterfall] Async function queue #interview
var func1 = function() {
return new Promise(function(resolve) {
setTimeout(function() {
console.log('func1');
resolve();
}, 500);
});
};
var func2 = function() {
return new Promise(function(resolve) {
@YiqinZhao
YiqinZhao / main.cpp
Created March 21, 2018 03:33
[Lemo Puzzle] Two array, boxes and lemos stand for size of boxes and size of lemos. Every lemo can be put into a box which has equal or bigger size. Pick a start point i from lemos array, find a possible box and repeat this action for i+1, i+2. All lemos in boxes should keep their original orders. What is the longest sequence of lemos in boxes. …
#include <iostream>
int boxes[10] = {5, 3, 2, 7, 10, 9, 1, 6, 4, 8};
int lemons[10] = {2, 6, 7, 1, 10, 5, 4, 3, 9, 8};
int main() {
int globalMax = -1;
for (int k = 0; k < 10; k++) {
int i = k, j = 0;
@YiqinZhao
YiqinZhao / index.js
Created March 20, 2018 11:25
[Self increasement function]
function * selfIncreasement() {
let i = 0
while (true) {
i++
yield console.log(i)
}
}
let a = selfIncreasement()
@YiqinZhao
YiqinZhao / index.js
Created March 9, 2018 07:34
[Split URL Parameters] Simple code for URL parameters split. #web
let result = window.location.href
.split('?')[1]
.split('&')
.map(v => v.split('='))
.reduce((obj, v) => { obj[v[0]] = v[1]; return obj }, {})
console.log(result)