Skip to content

Instantly share code, notes, and snippets.

#include <jni.h>
JNIEXPORT void JNICALL
Java_com_example_thunks_SomeClass_callback(JNIEnv *env, jobject obj, jint arg1, jlong arg2)
{
jclass SomeClass = (*env)->GetObjectClass(env, obj);
jfieldID nativeCallback_ID = (*env)->GetFieldID(env, SomeClass, "m_nativeCallback", "J"); // it would be wise to cache this ID
void (*callbackPtr)(int, long) = (void (*)(int, long)) (*env)->GetLongField(env, object, nativeCallback_ID);
callbackPtr(arg1, arg2);
}
package com.example.thunks
public class SomeClass {
private long m_nativeCallback;
public native void callback(int arg1, long arg2);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Audio Recorder</title>
<style>
audio {
display: block;
}
@alexcohn
alexcohn / audio.html
Last active May 9, 2018 18:36
experiment around audio duration
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Audio Recorder</title>
<style>
audio {
display: block;
}
#ifndef almost_private
#define almost_private private
#endif
class A {
private:
void Private();
almost_private:
void AlmostPrivate();
}
@alexcohn
alexcohn / hide_behind.xml
Last active August 17, 2019 16:40
To help with https://stackoverflow.com/q/57523822/192373 how texture view can hide behind the activity layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.example.android.camera2basic.AutoFitTextureView
android:id="@+id/texture"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
#include <iostream>
enum SumOfWeights {
N
};
template<class T>
class is_time_point {
template<typename U> static auto test(U const* u) -> decltype(u->time_since_epoch(), std::true_type());
template<typename> static std::false_type test(...);
@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];
#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 / 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) {