Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢

diewland NFT diewland

🐢
View GitHub Profile
@diewland
diewland / winner.sh
Last active Aug 12, 2022
shuffle list to find the winner
View winner.sh
# shuffle to tmp file
shuf $1 -o $1.tmp
# shuffle 16 times
for (( i=1; i<=16; i++ )); do
shuf $1.tmp -o $1.tmp
done
# last shuffle and show winner
shuf $1.tmp -n 1
@diewland
diewland / calc_seed_size.js
Created Jul 14, 2022
Calculate seed size
View calc_seed_size.js
let count_seed = (word_size, seed_size) => {
if (seed_size == 1) return word_size;
return word_size * count_seed(word_size-1, seed_size-1);
}
console.log('seed size 12', '=>', count_seed(2048, 12).toLocaleString());
console.log('seed size 24', '=>', count_seed(2048, 24).toLocaleString());
// seed size 12 => 5,271,537,971,301,488,400,000,000,000,000,000,000,000
// seed size 24 => 25,892,008,055,647,378,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000
@diewland
diewland / sleep_8bit.kt
Created May 5, 2021
Sleep in 8-bit style
View sleep_8bit.kt
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 Mar 25, 2021
Loop heavy blocking process without UI freeze
View LoopBlockingWithoutFreeze.kt
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 / run-kitkat-app-on-android-11.md
Last active Apr 27, 2022
Run Kitkat app on Android 11
View run-kitkat-app-on-android-11.md

Run Kitkat app on Android 11

add 2 properties to in Manifest file

android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true"

build.gradle (app) set targetSdkVersion to 29

@diewland
diewland / TempSetting.kt
Last active May 20, 2020
Parse nested json object to data class
View TempSetting.kt
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 / ReadLine.kt
Created Apr 15, 2020
Utility class for read line
View ReadLine.kt
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 / SuUtil.kt
Last active Feb 25, 2020
Execute su commands for android ( root required )
View SuUtil.kt
package com.diewland.installmanager.util
import android.util.Log
import java.io.BufferedReader
import java.io.DataOutputStream
import java.io.InputStreamReader
object SuUtil {
private const val TAG = "SU_UTIL"
@diewland
diewland / remove_game_services_s9plus.sh
Created Dec 11, 2019
Remove Samsung Game Services on S9+
View remove_game_services_s9plus.sh
# [1] list packages
#adb shell pm list packages -f | grep game | grep samsung
#
#package:/system/priv-app/GameHome/GameHome.apk=com.samsung.android.game.gamehome
#package:/system/priv-app/GameTools_Dream/GameTools_Dream.apk=com.samsung.android.game.gametools
#package:/system/app/GameOptimizingService/GameOptimizingService.apk=com.samsung.android.game.gos
# [2] get package path
#adb shell pm path com.samsung.android.game.gamehome
#adb shell pm path com.samsung.android.game.gametools
@diewland
diewland / ajax_json.js
Last active Sep 17, 2019
jQuery ajax json mode
View ajax_json.js
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);
},