Skip to content

Instantly share code, notes, and snippets.

@alexcohn
alexcohn / shuffle.cpp
Created June 3, 2020 11:21
// 1,3,5,7…2,4,6,8… will become 1,2,3,4,5,6,7,8 // for T == int, positive
// 1,3,5,7…2,4,6,8… will become 1,2,3,4,5,6,7,8
// for T == int, positive
#include <iostream>
#include <vector>
#include <string>
using namespace std;
template <typename T>
JNIEXPORT jbyteArray JNICALL
Java_com_company_app_tools_NV21FrameRotator_rotateNV21(JNIEnv *env, jclass thiz,
jbyteArray data, jbyteArray output,
jint width, jint height, jint rotation) {
clock_t start, end;
double cpu_time_used;
start = clock();
jbyte *dataPtr = (*env)->GetByteArrayElements(env, data, NULL);
jbyte *outputPtr = (*env)->GetByteArrayElements(env, output, NULL);
@alexcohn
alexcohn / build_xcframework.sh
Created October 10, 2020 20:46
build_xcframework.sh
#!/bin/sh
cd $(dirname $0)
# set framework name or read it from project by this variable
FRAMEWORK_NAME=$1
#xcframework path
FRAMEWORK_PATH="../${FRAMEWORK_NAME}.xcframework"
if [ -e ${FRAMEWORK_PATH} ]; then
@alexcohn
alexcohn / sharedFlow.kt
Last active February 9, 2021 21:01
Kotlin couroutines: SharedFlow emit from collect
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import java.util.concurrent.Executors
import kotlin.system.exitProcess
val dispatcher = Executors.newSingleThreadExecutor().asCoroutineDispatcher()
val scope = CoroutineScope(dispatcher)
fun main() {
class B: Encodable {
static let needUpdate = Notification.Name("B")
var cnt = 0;
// and many, many other things
func upload() { // serialize and upload it to the cloud
sleep(1000)
}
}
class A1 { // this is not thread-safe
@alexcohn
alexcohn / WebView.extension.kt
Created February 25, 2021 07:37
WebView.postUrl with additionalHttpHeaders via extension
fun WebView.postUrl(url: String, postData: ByteArray, additionalHttpHeaders: MutableMap<String, String>) {
val savedWebViewClient = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
webViewClient
}
else {
getLegacyWebViewClient()
}
webViewClient = object : WebViewClient() {
@alexcohn
alexcohn / webrtc patch.diff
Last active June 1, 2022 15:01
fix cuttlefish build for ARM64
git -C external/webrtc diff
diff --git a/Android.bp b/Android.bp
index 204ee672ef..3a18fe095a 100644
--- a/Android.bp
+++ b/Android.bp
@@ -93,10 +93,10 @@ cc_defaults {
},
arch: {
arm: {
- cflags: ["-DWEBRTC_HAS_NEON"],