Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

Wafer Li wafer-li

I may be slow to respond.
View GitHub Profile
wafer-li / EquivalentUntilWindowedFlow.kt
Last active Aug 9, 2021
Kotlin Flow emit when the upstream emit the same value [windowSize] times
View EquivalentUntilWindowedFlow.kt
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.collect
import java.util.concurrent.atomic.AtomicInteger
private val defaultKeySelector: (Any?) -> Any? = { it }
private val defaultAreEquivalent: (Any?, Any?) -> Boolean = { old, new -> old == new }
wafer-li / App.kt
Created Jul 15, 2021
CameraX Custom SurfaceCombination
View App.kt
class App : Application(), CameraXConfig.Provider {
override fun getCameraXConfig(): CameraXConfig {
val defaultConfig = Camera2Config.defaultConfig()
val provider = CameraDeviceSurfaceManager.Provider { context, cameraManager, availableCameraIds ->
Camera2DeviceSurfaceManagerModified(context, cameraManager, availableCameraIds)
wafer-li /
Last active Jun 10, 2020
TouchDelegateComposite to handle multiple view delegate their touch event to one specific view
import android.view.MotionEvent;
import android.view.TouchDelegate;
import android.view.View;
import java.util.ArrayList;
import java.util.List;
public class TouchDelegateComposite extends TouchDelegate {
wafer-li / GridSpaceItemDecoration.kt
Last active May 12, 2020
基于公式法写的一个 GridSpaceItemDecoration, 实现 GridLayoutManager 居中元素空隙
View GridSpaceItemDecoration.kt
import android.view.View
import androidx.annotation.Dimension
import androidx.core.text.TextUtilsCompat
import androidx.core.view.ViewCompat
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import li.wafer.nbnhhshandroid.common.extensions.dipToPx
import java.util.*
import kotlin.math.roundToInt
wafer-li / RandomSequencer.kt
Last active Dec 21, 2019
A Random Sequencer generate sequence of random item within range which ensure no duplicate item in a range block
View RandomSequencer.kt
package profile.adapter
import profile.adapter.RandomSequencer.Companion.fromCharRange
import profile.adapter.RandomSequencer.Companion.fromIntRange
import profile.adapter.RandomSequencer.Companion.fromLongRange
import kotlin.random.Random
* A Random Sequencer which accomplish :
* 1. Generate a sequence of random items within range.
import argparse
from netaddr import IPNetwork
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('filename', help='The filename of the file you need to convert')
args = arg_parser.parse_args()
src_filename = args.filename
output_filename = 'ip-range.txt'
wafer-li /
Created May 28, 2019
Soartex-Modded texture pack script. Use it in the root of Soartex-Modded-1-12-2 and it will pack all mods's textures into one.
import os
import zipfile
zip_file = zipfile.ZipFile('', 'w', zipfile.ZIP_DEFLATED)
for root,dirs,files in os.walk('.'):
relative_path = root[2:]
if relative_path.count(os.sep) > 1: # root == App/asserts/lowcase
for f in files:
wafer-li /
Created Jan 21, 2018
My Public PGP Key
Comment: GPGTools -
wafer-li /
Last active Jul 31, 2021
Restore file last modified time in a newly clone repo.Which base on the file's last commited time. Tested with python 3.4 and above
# -*- coding: utf-8 -*-
import subprocess
import os
import shlex
if __name__ != '__main__':
raise ImportError("%s should not be used as a module." % __name__)
# 'git ls-files -z | xargs -0 -n1 -I{} -- git log -1 --format="%ct {}" {} | sort'
wafer-li /
Created Jan 11, 2018
Python script to update all hexo-next plugins
#!usr/bin/env python3
import os
from subprocess import call
from typing import List
if __name__ == '__main__':
root_dir = os.path.abspath('themes/next-reloaded/source/lib')
git_dirs: List[str] = []