Skip to content

Instantly share code, notes, and snippets.

View gguuss's full-sized avatar

Gus Class gguuss

View GitHub Profile
@gguuss
gguuss / vision.py
Last active November 19, 2019 11:47
Process images with vision API
def image_to_object_localization(
project_id, sub_name, duration, binary, cloud_region, registry_id,
device_id):
import base64
import binascii
import io
import time
from google.cloud import pubsub
from google.cloud import vision
@gguuss
gguuss / bb.py
Created November 19, 2019 11:38
Label and draw a bounding box around an image target
def draw_obj(image_file, text, vects):
"""Draw a border around the image using the label and vector list."""
from PIL import Image, ImageDraw, ImageFont
im = Image.open(image_file)
w = im.width
h = im.height
draw = ImageDraw.Draw(im)
fnt = ImageFont.truetype('Verdana.ttf', 40)
draw.text(
@gguuss
gguuss / recv.py
Created November 19, 2019 10:53
Receive image from Cloud PubSub
def receive_image(project_id, sub_name, prefix, extension, duration, binary):
"""Receieve images transmitted to a PubSub subscription."""
import base64
import binascii
import io
import time
from google.cloud import pubsub
from PIL import Image
@gguuss
gguuss / script.gs
Created November 7, 2019 20:36
Example showing you how to retrieve rows for plotting SQL data from IoT core
// Replace the variables in this block with real values.
var address = '<your-server-ip-address>';
var user = 'root';
var userPwd = '<your-password>';
var db = '<your-db-name>';
var dbUrl = 'jdbc:mysql://' + address + '/' + db;
// Read up to 1000 rows of data from the table and log them.
function readFromTable() {
/*
* Whitelist the following IPs on https://cloud.google.com/sql
* One at a time!
*
* 64.18.0.0/20
* 64.233.160.0/19
* 66.102.0.0/20
* 66.249.80.0/20
* 72.14.192.0/18
* 74.125.0.0/16
gcloud config set project <your-project-id>
gcloud sql connect wifistr --user=root
use wifistr
select * from wifistr;
@gguuss
gguuss / main.py
Last active October 30, 2019 15:50
import base64
import sqlalchemy
from sqlalchemy import update
def hello_pubsub(event, context):
pubsub_message = base64.b64decode(event['data']).decode('utf-8')
db_user = 'root' # os.environ.get("DB_USER")
db_pass = 'your-db-pass' # os.environ.get("DB_PASS")
google-cloud-pubsub==1.0.2
PyMySQL==0.9.3
sqlalchemy==1.3.8
@gguuss
gguuss / create_db.sh
Created October 30, 2019 12:34
Create a MySQL database for storing wifi strength
create database wifistr;
use wifistr;
create table wifistr(id int auto_increment primary key not null, wifistr varchar(32));
desc wifistr;
@gguuss
gguuss / sql.sh
Last active October 30, 2019 12:29
Cloud SQL proxy Mysql
gcloud config set project <your-project-id>
gcloud sql connect <dbname> --user=<user>