Skip to content

Instantly share code, notes, and snippets.

View rocioDEV's full-sized avatar
🚀
Like a sputnik

Rocío rocioDEV

🚀
Like a sputnik
View GitHub Profile
@rocioDEV
rocioDEV / ImageClassifier.js
Created February 28, 2020 10:40
ml5-classifier.train
classifier.train(e => {
console.log(e) // "e" will be null once the training has finished
})
@rocioDEV
rocioDEV / ImageClassifier.js
Created February 28, 2020 10:38
ml5-featureExtractor
const featureExtractor = ml5.featureExtractor('MobileNet', () => {
classifier = featureExtractor.classification(
document.querySelector('video'),
() => {
console.log("Video ready!")
}
)
})
const loop = classifier => {
classifier.classify().then(results => {
setResult({
label: results[0].label,
probability: results[0].confidence.toFixed(4)
})
loop(classifier) // Call again to create a loop
})
}
@rocioDEV
rocioDEV / ImageClassifier-1.js
Created February 28, 2020 08:43
ml5-getUserMedia
navigator.mediaDevices
.getUserMedia({
video: true
})
.then(function(mediaStream) {
const video = document.querySelector('video')
video.srcObject = mediaStream
})
.catch(function(err) {
console.warn('Error accessing camera')
@rocioDEV
rocioDEV / index.html
Created February 28, 2020 08:09
ml5-index.html
<head>
<title>Ml5.js test</title>
<script src="https://unpkg.com/ml5@0.4.3/dist/ml5.min.js"></script>
</head>
@rocioDEV
rocioDEV / ImageClassifier.js
Last active February 25, 2020 08:32
Image classification in the browser with ml5 and React
import React, { useState, useEffect } from 'react'
import './image-classifier.scss'
const ImageClassifier = () => {
const [result, setResult] = useState({})
const ml5 = window.ml5
useEffect(() => {
// Initialize video element with camera input
navigator.getUserMedia(
@rocioDEV
rocioDEV / api.yaml
Created February 16, 2020 19:10
OpenAPI - GET by url param example
'/users/{email}':
get:
tags:
- USERS
description: Returns the requested user
parameters:
- name: email
in: path
description: email of the requested user
required: true
@rocioDEV
rocioDEV / app.js
Created February 15, 2020 19:32
Express live documentation with swagger-jsdoc & swagger-ui-express
// ... non relevant require statements are omitted
const swaggerJsdoc = require('swagger-jsdoc')
const swaggerUi = require('swagger-ui-express')
const packageJson = require('../package.json')
const appVersion = packageJson.version
const appName = packageJson.name
const API_DOCS_PATH = path.resolve(__dirname, '../api.yaml')
const app = express()
while(browser.alive){
if(stack.empty && !queue.empty){
stack.push(queue.next)
}
}
//No ejecutéis esto, por favor :)
let infinito = true
setTimeout(function() {
infinito = false
}, 10000)
while(infinito) {
console.log("todavía estoy aquí!", Date.now())
}