Skip to content

Instantly share code, notes, and snippets.

@pepetox
pepetox / index.js
Created September 24, 2020 14:58
Workshop OpenSpace 2020 ML - Step 2
//gcloud functions deploy processData --runtime nodejs10 --trigger-resource mysandoxbucket --trigger-event google.storage.object.finalize --project sandbox-project
//set the vars
const datasetId = 'openspace2020';
const tableId = 'imageData';
//load the dependences
const {BigQuery} = require('@google-cloud/bigquery');
const bigquery = new BigQuery();
const vision = require('@google-cloud/vision');
const client = new vision.ImageAnnotatorClient();
@pepetox
pepetox / index.js
Last active September 24, 2020 14:33
Workshop OpenSpace 2020 ML - Step 1
//gcloud functions deploy getData --runtime nodejs12 --trigger-resource mysandoxbucket --trigger-event google.storage.object.finalize --project my-sandbox-project
exports.getData = async (file, context) => {
//set the vars
const bucketName = "mysandoxbucket";
//load the dependences
const vision = require('@google-cloud/vision');
console.log(`Data for ${file.name}:`);
//Ask for labels of image
@pepetox
pepetox / index.js
Created September 13, 2020 16:39
Simulate Fail
let count = 0;
exports.helloWorld = (req, res) => {
count++;
if(count<5){
res.status(500).json({"error": "System error"});
}else{
res.status(200).json({"llamada": count});
}
};
@pepetox
pepetox / PACKAGE.JSON
Created September 10, 2020 06:44
Function to encode md5
{
"name": "encode-md5",
"version": "0.0.1",
"dependencies": {
"md5": "^2.3.0"
}
}
@pepetox
pepetox / basic
Last active September 11, 2020 09:16
Post workflows ejemplo 1
- getCurrentTime:
call: http.get
args:
url: http://worldtimeapi.org/api/timezone/Europe/Madrid
result: CurrentDateTime
- readWikipedia:
call: http.get
args:
url: https://en.wikipedia.org/w/api.php
query:
@pepetox
pepetox / Dockerfile
Created July 8, 2020 13:45
Cloud Run to use Gcloud, gstuil, kubectl....
FROM docker:19.03.11 as static-docker-source
FROM debian:buster
ARG CLOUD_SDK_VERSION=299.0.0
ENV CLOUD_SDK_VERSION=$CLOUD_SDK_VERSION
ENV CLOUDSDK_PYTHON=python3
ENV PATH "$PATH:/opt/google-cloud-sdk/bin/"
COPY --from=static-docker-source /usr/local/bin/docker /usr/local/bin/docker
RUN apt-get -qqy update && apt-get install -qqy \
curl \
@pepetox
pepetox / index.html
Created April 29, 2020 19:50
tensoflow.js html
<script src="https://unpkg.com/@tensorflow/tfjs"></script>
<script src="https://unpkg.com/@tensorflow/tfjs-automl"></script>
<img id="daisy" crossorigin="anonymous" src="/hattori.jpeg">
<script>
async function run() {
const model = await tf.automl.loadImageClassification('model.json');
const image = document.getElementById('daisy');
const predictions = await model.classify(image);
console.log(predictions);
// Show the resulting object on the page.
@pepetox
pepetox / Dockerfile
Last active April 25, 2020 15:34
AutoML --> Cloud run
FROM gcr.io/automl-vision-ondevice/gcloud-container-1.12.0:latest
RUN mkdir -p /tmp/mounted_model/0001/
COPY saved_model.pb /tmp/mounted_model/0001/
@pepetox
pepetox / query1.sql
Created March 24, 2020 19:19
Queries Webinar BigQuery
SELECT count(repo_name) as numberOfRepos, lang_data.name
FROM `bigquery-public-data.github_repos.languages`, UNNEST(language) AS lang_data
WHERE lang_data.name IN ("JavaScript","Java","Python","Ruby","PHP","C","Go") AND
repo_name IN (
SELECT repo_name
FROM `bigquery-public-data.github_repos.sample_repos`
WHERE watch_count>10
ORDER BY watch_count
)
GROUP BY lang_data.name
@pepetox
pepetox / app.yaml
Last active April 1, 2020 17:40
server.js Front with GAE
runtime: nodejs10
service: default