Skip to content

Instantly share code, notes, and snippets.

Avatar

Gergely Kőrössy Gericop

View GitHub Profile
@Gericop
Gericop / semaphore.js
Last active Nov 23, 2021
A simple implementation of a semaphore in JS
View semaphore.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();
}
@Gericop
Gericop / VisionApiCameraFix.java
Last active Feb 10, 2021
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.
View VisionApiCameraFix.java
/**
* <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);
@Gericop
Gericop / VisionApiFocusFix.java
Last active Nov 22, 2019
Mobile Vision API fix for missing autofocus feature
View VisionApiFocusFix.java
/*
* 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,