Skip to content

Instantly share code, notes, and snippets.

View diewland's full-sized avatar
🧩
Jigsaw Fam

diewland.eth diewland

🧩
Jigsaw Fam
View GitHub Profile
@diewland
diewland / province_th.js
Last active October 26, 2021 18:44
Javascript Thai provinces array and dict
// https://th.wikipedia.org/wiki/จังหวัดของประเทศไทย
// 77 จังหวัด
var province_th = [
'กรุงเทพฯ',
'กระบี่',
'กาญจนบุรี',
'กาฬสินธุ์',
'กำแพงเพชร',
'ขอนแก่น',
'จันทบุรี',
@diewland
diewland / sleep_8bit.kt
Created May 5, 2021 08:32
Sleep in 8-bit style
fun sleep8bit (second: Int, width: Int=10, callback: (String)->Unit) {
val d = (second * 1000 / width ).toLong()
(1..width).forEach {
Thread.sleep(d)
val progress = "[${"#".repeat(it)}${" ".repeat(width-it)}]"
callback(progress)
}
}
@diewland
diewland / LoopBlockingWithoutFreeze.kt
Last active March 25, 2021 08:33
Loop heavy blocking process without UI freeze
fun main() {
val h = Handler(Looper.getMainLooper())
GlobalScope.launch(Dispatchers.Main) {
(1..5).forEach { proc(it, h) }
}
h.removeCallbacksAndMessages(null)
}
suspend fun proc(no: Int, h: Handler): Boolean = suspendCoroutine {
h.post {
@diewland
diewland / gb.bat
Created July 11, 2018 11:48
show git branch in windows command prompt
@echo off
set GITBRANCH=
for /f "tokens=2" %%I in ('git.exe branch 2^> NUL ^| findstr /b "* "') do set GITBRANCH=%%I
if "%GITBRANCH%" == "" (
prompt $P$G
) else (
prompt $P $C$E[10;7;32;47m%GITBRANCH%$E[0m$F $G
)
@diewland
diewland / TempSetting.kt
Last active May 20, 2020 06:47
Parse nested json object to data class
import com.alibaba.fastjson.JSON
data class Setting (
val title: String,
val info: List<TimeRange>
)
data class TimeRange (
val from: String,
val to: String,
val temp: Int
@diewland
diewland / default
Last active April 29, 2020 18:12 — forked from ColeMurray/default
my nginx config example
server {
listen 80;
server_name YOUR_SERVERS_IP_ADDRESS;
location ~ ^/(js/|img/|css/) {
root /path/to/public/static/;
access_log off;
expires 24h;
}
location / {
@diewland
diewland / ReadLine.kt
Created April 15, 2020 15:55
Utility class for read line
class ReadLine {
private val EOL = listOf(
13.toByte(), // CR
10.toByte() // LR
)
private val EOL_SIZE = EOL.size
private val MSG_MAX_LENGTH = 99
private var line = byteArrayOf()
@diewland
diewland / n10_hdmi_resolution.txt
Created June 16, 2016 04:44
Nexus 10 change resolution script for fix hdmi problem
# ----------------
# http://forum.xda-developers.com/showthread.php?t=2278508
# http://forum.xda-developers.com/showthread.php?t=2294786
#
# (require root)
# reset
wm size reset
wm density reset
wm overscan reset
@diewland
diewland / ajax_json.js
Last active September 17, 2019 03:35
jQuery ajax json mode
function ajax_json(type, url, data, success_fn, failure_fn){
let ajax_options = {
type: type,
url: url,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(data),
success: function(resp){
success_fn(resp);
},
@diewland
diewland / fix_width_print_wo_tab.py
Last active August 31, 2019 07:02
Print fix-width without tab
for i in range(10):
print('{:<10}: {}'.format('*'*(i+1), 'row %s' % (i+1)))