Skip to content

Instantly share code, notes, and snippets.

View jaz303's full-sized avatar

Jason Frame jaz303

View GitHub Profile
@jaz303
jaz303 / tutorial.md
Last active April 25, 2023 08:47
Openport tunnel example

Prerequisites

Instructions

NB: server and client can be the same machine.
NB: on first Openport run it's necessary to visit a URL before traffic will be forwarded

@jaz303
jaz303 / test.sql
Created February 1, 2022 15:42
json mutate
DROP TABLE IF EXISTS student;
CREATE TABLE student (
id SERIAL PRIMARY KEY,
name VARCHAR(255),
state JSONB
);
INSERT INTO student (name, state) VALUES ('Bob', '{"completed": []}');
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int do_sub(const char *key, size_t key_len, char *buffer, size_t buffer_len) {
if (strncmp("HWVERSION", key, key_len) == 0) {
return snprintf(buffer, buffer_len, "%d.%d.%d", 1, 2, 3);
} else if (strncmp("xyzzy", key, key_len) == 0) {
return snprintf(buffer, buffer_len, "%s", "quux");
} else {
database(:db, adapter: :pg, host: '127.0.0.1', port: 5432) do
# reset logic here?
end
http_endpoint(:api, '127.0.0.1', 8000) do |addr, port|
working_dir ".."
run "build/api-server"
env LISTEN: "#{addr}:#{port}"
end
ACTION=="add", SUBSYSTEM=="backlight", RUN+="/bin/chgrp video /sys/class/backlight/%k/brightness"
ACTION=="add", SUBSYSTEM=="backlight", RUN+="/bin/chmod g+w /sys/class/backlight/%k/brightness"
template <HardwareSerial* T>
class SerialWriter
{
public:
void writeMessage(unsigned char *message, int length);
};
template <HardwareSerial* T>
void SerialWriter<T>::writeMessage(unsigned char *message, int length) {
T->write(SafeSerial::MESSAGE_START);
module.exports = function(cb) {
let state = 'idle', cancel = null, pending = null;
function submit(promise) {
let cancelled = false;
promise.then((res) => {
if (!cancelled) {
cb(res);
oncomplete();
}
function createTransport({fps, reset, update, draw}) {
const [UNKNOWN, READY, RUNNING] = enumeration('UNKNOWN', 'READY', 'RUNNING');
const frameLength = Math.floor(1000 / fps);
const clock = {dt: null};
let state = UNKNOWN, timer = null, lastFrame = null, nextFrame = null;
function _start() {
if (state === RUNNING) return;
if (state === UNKNOWN) _reset();
@jaz303
jaz303 / enums.js
Last active January 19, 2023 04:46
Concise enums via ES6 destructuring
function enumeration() {
const out = [];
for (let ix = 0; ix < arguments.length; ++ix) {
let val = {};
Object.defineProperty(val, 'name', {
value: arguments[ix],
writable: false,
configurable: false
});
out.push(val);