Skip to content

Instantly share code, notes, and snippets.

View gregkorossy's full-sized avatar

Gergely Kőrössy gregkorossy

View GitHub Profile
@gregkorossy
gregkorossy / semaphore.js
Last active September 15, 2023 08:08
A simple implementation of a semaphore in JS
function Semaphore(max) {
var counter = 0;
var waiting = [];
var take = function() {
if (waiting.length > 0 && counter < max){
counter++;
let promise = waiting.shift();
promise.resolve();
}
@gregkorossy
gregkorossy / VisionApiCameraFix.java
Last active February 10, 2021 10:20
Mobile Vision API fix for accessing the private Camera instance of the CameraSource object, so that it can be used to set parameters, e.g. focus mode, flash mode, etc.
/**
* <p>Returns the supplied {@link com.google.android.gms.vision.CameraSource}'s {@link android.hardware.Camera} instance that is being used.</p>
* <p>
* If you want to set any of the camera parameters, here's an example that sets the focus mode to continuous auto focus and enables the flashlight:
* <blockquote>
* <code>
* Camera.Parameters params = camera.getParameters();
* params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
* params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
* camera.setParameters(params);
@gregkorossy
gregkorossy / VisionApiFocusFix.java
Last active November 22, 2019 11:38
Mobile Vision API fix for missing autofocus feature
/*
* IF YOU WANT TO JUST ACCESS THE CAMERA INSTANCE SO THAT YOU CAN SET ANY OF THE PARAMETERS, VISIT THE FOLLOWING LINK:
* https://gist.github.com/Gericop/364dd12b105fdc28a0b6
*/
/**
* Custom annotation to allow only valid focus modes.
*/
@StringDef({
Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE,