Skip to content

Instantly share code, notes, and snippets.

View tsh-code's full-sized avatar

TSH code sharing tsh-code

View GitHub Profile
<?php
chdir(__DIR__);
$http = new swoole_http_server('php', 8080);
$http->on('start', function ($server) {
echo "Server has been started!\n";
});
$http->on('request', function ($request, $response) {
swoole_async_readfile('index.html', function($filename, $content) use ($response) {
<?php
$server = new swoole_websocket_server('php', 9501);
$server->on('start', function (swoole_websocket_server $server) {
echo "Server has been started!\n";
});
$server->on('open', function (swoole_websocket_server $server, $request) {
echo "websocket: new connection, id: {$request->fd}\n";
});
<?php
$counter = 0;
$http = new swoole_http_server('php', 8080);
$http->on('request', function ($request, $response) use ($counter) {
$response->header("Content-Type", "text/plain");
$response->end($counter++);
});
$http->start();
<application ...>
<!-- ... -->
<meta-data
android:name="com.google.firebase.ml.vision.DEPENDENCIES"
android:value="ocr" />
</application>
@tsh-code
tsh-code / ocr-mlkit-configuration.gradle
Created October 15, 2018 07:12
Simple OCR implementation on Android with Google’s ML Kit snippet
dependencies {
// ...
implementation 'com.google.firebase:firebase-ml-vision:16.0.0'
}
val detector = FirebaseVision.getInstance().visionTextDetector
detector.detectInImage(visionImage)
FirebaseVisionImage.fromBitmap(textBitmap)
class TextDetector {
private val detector = FirebaseVision.getInstance().visionTextDetector
private val detectionOutput = PublishProcessor.create<FirebaseVisionText>()
private val frameInput = PublishProcessor.create<Bitmap>()
init {
frameInput.map { it.toFirebaseVisionImage() }
.flatMap(::detect)
.subscribe(detectionOutput)
val blocks = text.blocks
val blocksRect = blocks.mapNotNull { it.boundingBox }
val lines = blocks.flatMap { it.lines }
val linesRect = lines.mapNotNull { it.boundingBox }
val elements = lines.flatMap { it.elements }
val elementsRect = elements.mapNotNull { it.boundingBox }
// copy bitmap and make it mutable if necessary (optional step)