Skip to content

Instantly share code, notes, and snippets.

View bootrino's full-sized avatar

bootrino bootrino

  • Melbourne, Australia
View GitHub Profile
@bootrino
bootrino / gist:7ae38d38dabf0a4be109374247178e90
Last active August 22, 2018 08:10
Python 3.6 AWS Lambda function to create a hosts file from running EC2 instances and put it in a bucket
import boto3
import json
import jmespath
s3 = boto3.resource('s3')
ec2 = boto3.resource('ec2')
# creates a hosts file for all running ec2 instances
# you can add alias hostnames by adding a tag "hostname" to the EC2 instance
@bootrino
bootrino / gist:d621bfa4040f970e7be5f2472074b710
Last active August 27, 2018 21:27
Incomplete stuff needed for asynch Postgres notification listen/notify
# this would need to be thought through and edited to make it work properly. The bits are cut out of a larger working solution.
import psycopg2
import psycopg2.extras
import aiopg
import asyncio
import json
from urllib.parse import quote
import atexit
from psycopg2.extensions import AsIs
@bootrino
bootrino / gist:efd3d6adc291630472d13e1f42b24eed
Created August 29, 2018 21:05
untested code fragments for Postgres NOTIFY and LISTEN from nodejs
# untested code fragments for Postgres NOTIFY and LISTEN from nodejs
const {Pool, Client} = require('pg')
const dbUsername = 'dbusername'
const dbHost = '127.0.0.1'
const dbPort = '5432'
const dbPassword = 'supersecret'
const dbDatabasename = 'dbname'
const connectionString = `postgresql://${dbUsername}:${dbPassword}@${dbHost}:${dbPort}/${dbDatabasename}`
const pool = new Pool({connectionString})
@bootrino
bootrino / gist:1a7ba46276fb17fcd48ba1f4c0988445
Created August 30, 2018 05:13
nodejs buildgif fragment
async function buildGIF(frames: any) {
let firstFrame = new PNG(frames[0].dataBytes);
let width = firstFrame.width;
let height = firstFrame.height;
//console.log(frames.length + " frames at " + width + "x" + height);
let encoder = new GIFEncoder(width, height);
encoder.createReadStream().pipe(fS.createWriteStream('output.gif'));
encoder.start();
let framePromises = frames.map(async (frame: any) => {
@bootrino
bootrino / gist:7edfc6b2e5ee6142a786069d0ba2f72e
Created August 30, 2018 05:14
nodejs transform image with sharp
async function transformImage(dataBytes: any) {
//let convert = async(dataBytes: any) => sharp(dataBytes).background({r: 255, g: 255, b: 255, alpha: 0}).toFormat('png').toBuffer()
let convert = async(dataBytes: any) => sharp(dataBytes).toFormat('png').toBuffer()
dataBytes = await(convert(dataBytes))
return dataBytes
}
// this is a hack of:
// https://github.com/gtalusan/esp-idf/blob/master/examples/bluetooth/a2dp_source/main/main.c
// the idea is to be able to play an audio file from an esp32's flash memory directly to a bluetooth audio speaker
// refer to here for the notes on what you need to do to pull it all together
/*
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
@bootrino
bootrino / gist:1af80a7363f14c5c9ad9748b41f919f1
Created February 10, 2019 20:57
example of printing binary data in Arduino
source: https://github.com/earlephilhower/ESP8266Audio/blob/2f2898c49612f1cc1351b44ffe8541def5a26b23/src/AudioGeneratorMIDI.cpp#L71
void AudioGeneratorMIDI::midi_error(const char *msg, int curpos)
{
cb.st(curpos, msg);
#if 0
int ptr;
Serial.printf("---> MIDI file error at position %04X (%d): %s\n", (uint16_t) curpos, (uint16_t) curpos, msg);
/* print some bytes surrounding the error */
ptr = curpos - 16;
@bootrino
bootrino / gist:06b821fb65b7aaad020c3ba532097a4c
Created February 10, 2019 21:00
Print uint32_t as hex in Arduino
unsigned char bytes[4];
bytes[0] = (u32 >> 24) & 0xFF;
bytes[1] = (u32 >> 16) & 0xFF;
bytes[2] = (u32 >> 8) & 0xFF;
bytes[3] = u32 & 0xFF;
for(int i = 0; i < 4; i++)
{
if (i == 0) Serial.print("0x");
Serial.print(bytes[i], HEX);
if (i < 3) Serial.print(":");
@bootrino
bootrino / gist:3418f772a0ffe76c2759852ae66d177b
Created February 10, 2019 21:10
output a uint32_t or unit16_t in Arduino
Serial.printf("---> %04X : foo\n", (uint32_t) u32);
//Serial.printf("---> %04X (%d): \n", (uint32_t) u32, (uint16_t) curpos);
@bootrino
bootrino / gist:75a2f4f8fdaebd62861eb4cc83f2fcab
Created February 12, 2019 08:44
Print the data_out buffer
int x = 0;
for (int i = 0; i < buffSize; i++)
{
x = i % 32;
if (x == 0)
{
Serial.print("\n");
}
Serial.printf("%02X: ", data_out[i]);
Serial.flush();