Skip to content

Instantly share code, notes, and snippets.

View JayGoldberg's full-sized avatar

Jay Goldberg JayGoldberg

View GitHub Profile
@JayGoldberg
JayGoldberg / timeout.sh
Last active April 18, 2017 14:37
Implement timeout command for systems that don't have it
## @author Jay Goldberg
## @email [email protected]
## @license Apache 2.0
## @description Implement timeout for systems that don't have it
## @usage source it, then timeout <secs> <command>
#=======================================================================
timeout() {
local timeout_secs=${1:-10}
shift
@JayGoldberg
JayGoldberg / read_JPEG_COM.js
Created April 11, 2017 16:30
Google Cloud Function (HTTP trigger) to read the COM (comment) fields of a JPEG image
// Get a reference to the Cloud Storage component
var storage = require('@google-cloud/storage');
function findCOMmarkers(buffer) {
var comment = [];
for (var i=0; i < buffer.length; i++) {
if (buffer[i] == '0xFF') {
if (buffer[i+1] == '0xFE') { // JPEG COM marker
comment.push(readcomment(buffer, i+4));
@JayGoldberg
JayGoldberg / uri.sh
Last active May 8, 2017 20:01 — forked from yock/uri.sh
URL Parsing function for Bash
#
# URI parsing function
#
# The function creates global variables with the parsed results.
# uri_schema, uri_address, uri_user, uri_password, uri_host, uri_port, uri_path, uri_query, uri_fragment
# It returns 0 if parsing was successful or non-zero otherwise.
#
# [schema://][user[:password]@]host[:port][/path][?[arg1=val1]...][#fragment]
#
function uri_parser() {
@JayGoldberg
JayGoldberg / espruino_longpoll_client.js
Last active January 5, 2018 23:02
Espruino code to do long polling via HTTP
var http = require("http");
var wifi = require("Wifi");
var analogOutPinGREEN = 'D12'; // Analog output pin that the LED is attached to GREEN
var analogOutPinBLUE = 'D13'; // Analog output pin that the LED is attached to BLUE
var analogOutPinRED = 'D15'; // Analog output pin that the LED is attached to RED
var outputValue = 0; // duty cycle of PWM (0-1)
var lastValue = 0;
@JayGoldberg
JayGoldberg / espruino_mqtt_neopixel.js
Created January 18, 2018 18:00
Turn a neopixel strip on and off via MQTT, in Espruino embedded Javascript
function mqttConnect(connVar) {
var mqtt = require("MQTT");
const MQTT_OPTIONS = {
host: 'mqtt.host.net',
keep_alive: 15,
client_id: "espruino",
username: "mqtt_username",
password: "mqtt_password",
path: '/doordash-temp'
};
@JayGoldberg
JayGoldberg / importframes-ds.js
Created February 5, 2018 20:08
Bulk insert of data into Google Cloud Datastore from JSON in CSV
const fs = require('fs');
const readline = require('readline');
const Datastore = require('@google-cloud/datastore');
const parse = require('csv-parse');
const instream = fs.createReadStream(process.argv[2]);
const datastore = Datastore({
projectId: 'cloudprojectid',
keyFilename: 'serviceaccount.json'
@JayGoldberg
JayGoldberg / nginx_cors.conf
Created February 22, 2018 22:16
nginx CORS writing headers for all methods
set $cors '';
if ($http_origin ~* (https?://.*\.foobar\.com(:[0-9]+)?)) {
set $cors "true";
}
if ($request_method = 'OPTIONS') {
set $cors "${cors}options";
}
@JayGoldberg
JayGoldberg / ispperf.sh
Last active March 8, 2019 19:40 — forked from ianrust/ispperf.sh
Script for logging and monitoring isp ping, latency, and bandwidth. Borrowed from here: https://www.blackhatworld.com/seo/bash-script-to-check-isp-bandwidth-and-latency.257820/
#!/bin/bash
# The MIT License
#
# Copyright (c) 2010, MaDeuce
#
# https://en.wikipedia.org/wiki/MIT_License
#
# ============================================================================
# This command measures latency and bandwidth of an internet connection from the command line.
@JayGoldberg
JayGoldberg / datastore_entity_test_1.py
Created July 5, 2019 18:12
Cloud Datastore single entity read test (usable in Cloud Shell)
import os
from google.cloud import datastore
import google.cloud.exceptions
#https://stackoverflow.com/questions/1593019/is-there-any-simple-way-to-benchmark-python-script
def timereps(reps, func):
from time import time
start = time()
for i in range(0, reps):
func()
@JayGoldberg
JayGoldberg / ftp_sync.sh
Last active July 25, 2021 12:55 — forked from guerrerocarlos/copy_to_ftp.sh
Script for syncing OUCAM camera videos automatically to FTP
#!/bin/sh
# FTP_COPY version 0.3 by MP77V www.4pda.ru
# ----------------------------
FTP_DEST_DIR="/FTP_directory"
FTP_DEST_HOST="FTP_host"
FTP_DEST_PORT="21"
FTP_DEST_LOGIN="FTP_user"
FTP_DEST_PASS="FTP_password"
# ----------------------------