Skip to content

Instantly share code, notes, and snippets.

View dcalsky's full-sized avatar
🏠
Working from home

zuozuo dcalsky

🏠
Working from home
  • The University of Hong Kong
  • Hong Kong
View GitHub Profile
@dcalsky
dcalsky / ccdl.command
Created March 23, 2021 07:16 — forked from ayyybe/ccdl.command
Adobe Offline Package Generator v0.1.2 (macOS only)
#!/bin/bash
CYAN="$(tput bold; tput setaf 6)"
RESET="$(tput sgr0)"
clear
if command -v python3 > /dev/null 2>&1; then
if [ $(python3 -c "print('ye')") = "ye" ]; then
clear
@dcalsky
dcalsky / BluetoothService.kt
Last active April 29, 2022 01:44
Bluetooth Service for Android with Kotlin
import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothSocket
import android.util.Log
import com.google.common.primitives.Bytes
import kotlinx.coroutines.*
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import java.util.*
@dcalsky
dcalsky / BindJson.kt
Created March 31, 2020 15:40
Ktor json validation with Hibernate Validator
// Convert application-json content to DTO with validation and rasing error message
suspend inline fun <reified T : Any> ApplicationCall.bindJson(): T {
val dto = this.receive<T>()
val violations = validator.validate(dto);
if (violations.size > 0) {
// Throw error messages when found violdations
val details = violations.map {
val propertyName = it.propertyPath.toString()
val errorMessage = it.message
@dcalsky
dcalsky / champions.csv
Created December 29, 2019 06:55
LOL champion list
name zh_name title nicknames upper_name
olaf 奥拉夫 狂战士 {} Olaf
galio 加里奥 正义巨像 {} Galio
twistedfate 崔斯特 卡牌大师 {} TwistedFate
leblanc 乐芙兰 诡术妖姬 {} Leblanc
kayle 凯尔 正义天使 {} Kayle
alistar 阿利斯塔 牛头酋长 {} Alistar
nunu 努努和威朗普 雪原双子 {} Nunu
ashe 艾希 寒冰射手 {} Ashe
jax 贾克斯 武器大师 {} Jax
@dcalsky
dcalsky / champions.json
Created December 17, 2019 14:11
LOL champion list
{
"黑暗之女": "安妮",
"狂战士": "奥拉夫",
"正义巨像": "加里奥",
"卡牌大师": "崔斯特",
"德邦总管": "赵信",
"无畏战车": "厄加特",
"诡术妖姬": "乐芙兰",
"猩红收割者": "弗拉基米尔",
"末日使者": "费德提克",
@dcalsky
dcalsky / export_tf_model.py
Created October 14, 2019 23:51 — forked from zhanwenchen/export_tf_model.py
Minimal code to load a trained TensorFlow model from a checkpoint and export it with SavedModelBuilder
import os
import tensorflow as tf
trained_checkpoint_prefix = 'checkpoints/dev'
export_dir = os.path.join('models', '0') # IMPORTANT: each model folder must be named '0', '1', ... Otherwise it will fail!
loaded_graph = tf.Graph()
with tf.Session(graph=loaded_graph) as sess:
# Restore from checkpoint
loader = tf.train.import_meta_graph(trained_checkpoint_prefix + '.meta')
@dcalsky
dcalsky / hku-interview.py
Last active May 18, 2023 15:31
Just some programming questions of interview and test of HKU
# 给正整数N,分解成1和3的组合,比如N=4,分解为1111,13,31(递归)
N = 5
res = []
def helper(left, arr=[]):
if left == 0:
res.append(arr)
return
if left < 0: