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 / 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 / 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 / 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 / gist:3c50a9bc32f63c10b0421f5e045f16d7
Last active September 18, 2020 17:32
windows tips #tips #windows
  1. Fix the hidden attribue can't be changed in files
    attrib -s -h file1, file2 …

  2. Recovery "show desktop" command

#Edit Desktop.scf with
[Shell]
Command=2
IconFile=explorer.exe,3
[Taskbar]
@wangyung
wangyung / mactips.sh
Last active September 14, 2020 15:41
some mac os tips #mac #tips
#1. Show hidden files in Finder
defaults write com.apple.finder AppleShowAllFiles -bool true
killall Finder
#2. Show full path in Finder
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
#3. Cancel the auto backup in iTunes
defaults write com.apple.iTunes DeviceBackupsDisabled -bool true
@wangyung
wangyung / scan_all_files.kt #for_medium
Last active September 14, 2020 15:41
Pseudo code for scanning all files and get the cover image.
private fun scanDirectory(directory: Path) {
Files
.walk(directory)
.filter {
Files.isDirectory(it, LinkOption.NOFOLLOW_LINKS)
}.forEach {
scope.launch { readBooksFromPath(it) }
}
}