Skip to content

Instantly share code, notes, and snippets.

@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"],
@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() {
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 / 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() {
@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
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 / 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>
@alexcohn
alexcohn / reorder.cpp
Last active June 1, 2020 13:08
reorder vector of coordinates into vector of points
// x1,x2,…,xn,y1,y2,…,yn will become x1,y1,x2,y2,…,x(n),y(n) in-place
#include <iostream>
#include <vector>
#include <string>
using namespace std;
template <typename T>
vector<T> expected(vector<T> const& a) {
#include "App.h"
using namespace std::chrono_literals;
using namespace std::chrono;
#include "../uSockets/src/internal/eventing/epoll_kqueue.h"
/* Note that uWS::SSLApp({options}) is the same as uWS::App() when compiled without SSL support */
int main() {
@alexcohn
alexcohn / YUV_420_888toNV21.java
Created February 4, 2020 08:33
optimized conversion from YUV_420_888 to NV21, see https://stackoverflow.com/a/52740776/192373
private static byte[] YUV_420_888toNV21(Image image) {
// optimized conversion from YUV_420_888 to NV21
// see https://stackoverflow.com/a/52740776/192373
int width = image.getWidth();
int height = image.getHeight();
int ySize = width*height;
int uvSize = width*height/4;
byte[] nv21 = new byte[ySize + uvSize*2];