Skip to content

Instantly share code, notes, and snippets.

View wangyung's full-sized avatar

Freddie Wang wangyung

View GitHub Profile
@wangyung
wangyung / android-file-exporter.kt
Created August 6, 2023 05:42
Create files in Android's external folder
/**
* Exports file to the given target folder on Android.
*
* ref: https://stackoverflow.com/questions/75055593/access-images-in-external-storage-created-by-my-app
*/
@Throws(IOException::class)
suspend fun exportImage(
contentResolver: ContentResolver,
file: File,
targetFolder: String,
@wangyung
wangyung / wsl2-network.ps1
Created May 5, 2022 04:19 — forked from xmeng1/wsl2-network.ps1
WSL2 Port forwarding port to linux
$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if( $found ){
$remoteport = $matches[0];
} else{
echo "The Script Exited, the ip address of WSL 2 cannot be found";
exit;
}
@wangyung
wangyung / find_cli_tips.md
Last active April 19, 2022 06:39
The tips of using find command

Find jpg files and calculate the total size

  • find [Folder] -name "*.jpg" -exec du -ch {} +

Find png files and excludes some folders

  • find [Folder] -name "*.png" | grep -v build (Slow)

Find png files and run commands (convert to webp)

  • find [Folder] -name "*.png" | xargs -I {} cwebp -lossless {} -o {}.webp
@wangyung
wangyung / InnerClosureExample.kt
Created March 7, 2022 00:44
kotlin inner closure example
fun countingLambda(): () -> Int {
var counter = 0
val incrementalCounter: () -> Int = {
counter += 1
counter
}
return incrementalCounter
}
// decompiled java
@wangyung
wangyung / enable_full_context_menu_for_win11.reg
Last active January 9, 2022 14:36
Enable Full Context Menus in windows 11
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32]
@=""
@wangyung
wangyung / android.vmoptions
Last active May 3, 2022 23:04
vmoptions for large memory and JDK 11
# For 32G+ memory and JDK11+
-Xss2m
-Xms1g
-Xmx8g
-XX:PermSize=512m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=256m
@wangyung
wangyung / enable_photo_viewer.reg
Created April 13, 2021 08:03
Enable windows photo viewer
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations]
".tif"="PhotoViewer.FileAssoc.Tiff"
".tiff"="PhotoViewer.FileAssoc.Tiff"
".gif"="PhotoViewer.FileAssoc.Tiff"
".jpg"="PhotoViewer.FileAssoc.Tiff"
".jpeg"="PhotoViewer.FileAssoc.Tiff"
".webp"="PhotoViewer.FileAssoc.Tiff"
".png"="PhotoViewer.FileAssoc.Tiff"
@wangyung
wangyung / change_name.sh
Last active September 14, 2020 15:32
Change all file names by incremental number. #tips
#!/bin/bash
INDEX=1
for file in `ls | sort -g`
do
filename=$(basename "$file")
extension=${filename##*.}
filename=$(printf "%03d\n" $INDEX)
mv "$file" "$filename.$extension"
@wangyung
wangyung / get-image-urls.js
Created April 13, 2020 00:08 — forked from tobek/get-image-urls.js
Save images from chrome inspector/dev tools network tab
/* open up chrome dev tools (Menu > More tools > Developer tools)
* go to network tab, refresh the page, wait for images to load (on some sites you may have to scroll down to the images for them to start loading)
* right click/ctrl click on any entry in the network log, select Copy > Copy All as HAR
* open up JS console and enter: var har = [paste]
* (pasting could take a while if there's a lot of requests)
* paste the following JS code into the console
* copy the output, paste into a text file
* open up a terminal in same directory as text file, then: wget -i [that file]
*/
@wangyung
wangyung / CoroutineScheduler.kt
Created March 5, 2020 05:40
The dispatch function in CoroutineScheduler.kt
fun dispatch(block: Runnable, taskContext: TaskContext = NonBlockingContext, fair: Boolean = false) {
trackTask() // this is needed for virtual time support
val task = createTask(block, taskContext)
// try to submit the task to the local queue and act depending on the result
val notAdded = submitToLocalQueue(task, fair)
if (notAdded != null) {
if (!addToGlobalQueue(notAdded)) {
// Global queue is closed in the last step of close/shutdown -- no more tasks should be accepted
throw RejectedExecutionException("$schedulerName was terminated")
}