Skip to content

Instantly share code, notes, and snippets.

@softberries
softberries / README.md
Created October 23, 2017 12:18
start up emr cluster with the task attached

aws emr create-cluster --name "Scalding test cluster" --ami-version 3.9.0 --use-default-roles --instance-type m1.medium --instance-count 3 --log-uri s3://grajo001out/2 --steps Type=CUSTOM_JAR,Name="EMR Tutorial",ActionOnFailure=TERMINATE_CLUSTER,Jar=s3://grajo001log/emr-scalding-tutorial-assembly-0.1.jar ,Args=["com.softwaremill.AgeCounterJob","--hdfs","--input","s3n://grajo001log/users/*","--output","s3n://grajo001log/output"] --auto-terminate

@softberries
softberries / task.json
Created October 23, 2017 12:21
task json definition
[
{
"Name": "emr-scalding-tutorial",
"Args": [
"com.softwaremill.AgeCounterJob",
"--input",
"s3://grajo001log/users/*",
"--output",
"s3://grajo001out/scaldingoutput",
"--hdfs"
@softberries
softberries / README.md
Created October 23, 2017 12:27
push task to emr

aws emr add-steps --cluster-id=YOUR-CLUSTER_ID --steps=file://./task.json

@softberries
softberries / camera.js
Created May 24, 2018 08:04
open the camera in a browser
//--------------------
// GET USER MEDIA CODE
//--------------------
navigator.getUserMedia = ( navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
var video;
var webcamStream;
@softberries
softberries / camera.js
Created May 24, 2018 08:06
upload sign in form
function uploadSignIn(filename) {
var dataURL = canvas.toDataURL();
var blobBin = atob(dataURL.split(',')[1]);
var token = $('input[name="csrfToken"]').attr('value');
var array = [];
for(var i = 0; i < blobBin.length; i++) {
array.push(blobBin.charCodeAt(i));
}
var file=new Blob([new Uint8Array(array)], {type: 'image/png'});
var formdata = new FormData();
@softberries
softberries / camera.js
Created May 24, 2018 08:07
log in sequence
$('#loginForm').one('submit', function(ev) {
ev.preventDefault();
var uuid = uuidv4();
snapshot();
uploadSignIn(uuid);
stopWebcam();
$(this).submit();
});
@softberries
softberries / SignInController.scala
Created May 24, 2018 08:10
receiving submit form data on the controller side
def submit = silhouette.UnsecuredAction.async { implicit request: Request[AnyContent] =>
val fileDataOpt: Option[MultipartFormData[TemporaryFile]] = request.body.asMultipartFormData
val signInForm = SignInForm.form.bindFromRequest
val tempFolderPath = configuration.underlying.getString("facenetTempFolder")
@softberries
softberries / FaceUtil.scala
Created May 24, 2018 08:11
extract image data from request
def checkFace(tempFolderPath: String, signInData: Option[MultipartFormData[TemporaryFile]], credentials: Credentials, user: User): Future[Boolean] = {
signInData.map { fileData =>
fileData.file("uploadedImage").map { image =>
import java.io.File
val filename = image.filename
image.ref.moveTo(new File(s"$tempFolderPath/signIn-$filename.png"))
val bos = new BufferedOutputStream(new FileOutputStream(new File(s"$tempFolderPath/orig-$filename.png")))
bos.write(user.face)
bos.close()
checkIfFacesMatch(s"$tempFolderPath/signIn-$filename.png", s"$tempFolderPath/orig-$filename.png")
@softberries
softberries / FaceUtil.scala
Created May 24, 2018 08:12
calling external python script
import sys.process._
import scala.concurrent.ExecutionContext.Implicits.global
def checkIfFacesMatch(facePath1: String, facePath2: String): Future[Boolean] = {
Future {
val result = s"python python/facematch.py --face1=$facePath1 --face2=$facePath2".!!
val res = result.split("\n").tail.headOption.exists(r => Try(r.toBoolean).getOrElse(false))
removeFile(facePath1)
removeFile(facePath2)
res
docker volume create openstreetmap-data
docker volume create openstreetmap-rendered-tiles