Skip to content

Instantly share code, notes, and snippets.

@nherment
nherment / dht22.js
Created November 24, 2014 20:51
beaglebone temperature/humidity monitor with metrano
var exec = require('child_process').exec
var Metrano = require('metrano)
var metrano = new Metrano('http://ice:3000/')
///home/nherment/Adafruit_Python_DHT/examples/AdafruitDHT.py 22 P8_11
exec('/home/nherment/Adafruit_Python_DHT/examples/AdafruitDHT.py 22 P8_11', function(err, stdout, stderr) {
if(err) {
console.log(err);
@nherment
nherment / gist:0914065cd54e1720953d
Last active August 29, 2015 14:13
JS make objects serializable
function makeSerializable(obj, skipAttributes) {
if(_.isArray(obj)) {
var serializableArray = {}
for(var i = 0 ; i < obj.length ; i++) {
serializableArray[i] = makeSerializable(obj[i])
}
return serializableArray
} else if(obj instanceof Object) {
const readLine = require("readline");
const rl = readLine.createInterface({output: process.stdout, input:process.stdin});
const dgram = require('dgram');
const server = dgram.createSocket('udp4');
// This regex extracts everything after the first / in the requested URL that isn't
// part of a HTTP(S):// prefix.
const siteRegex = /"GET.*?[^\/]\/([^\/]\S+)/;
@nherment
nherment / init.d_node-app
Created May 11, 2017 12:39
init.d nodejs app script
#!/bin/sh
USER="nherment"
NODE_ENV="production"
PORT="5000"
APP_DIR="/opt/node-app/latest"
NODE_APP="server.js"
KWARGS=""
APP_NAME="node-app"
PID_DIR="/var/run"
@nherment
nherment / db_setup.sql
Last active April 18, 2024 07:26
Postgresql user setup
-- As postgres user:
CREATE DATABASE <DB_NAME>;
CREATE USER <USERNAME> WITH LOGIN ENCRYPTED PASSWORD '<PASSWORD>';
GRANT ALL PRIVILEGES ON DATABASE <DB_NAME> TO <USERNAME>;
ALTER DATABASE <DB_NAME> OWNER TO <USERNAME>;
-- grant read-only
GRANT CONNECT ON DATABASE <DB_NAME> TO <USERNAME>;
@nherment
nherment / time_off_request.md
Last active April 22, 2020 15:22
How to write a time off request

Time off requests: templates

All listed time off are inclusives of dates/half days.

Full days

Mention day of the week, month and date (number).

@nherment
nherment / update_minimum_transit_times.sql
Last active March 5, 2020 13:15
SOE weekly data quality
WITH sea_legs AS (
SELECT
v.class AS vessel_class,
pc.id AS arrival_port_call_id,
pc.un_locode AS arrival_port,
CASE WHEN pc.eta_is_actual THEN pc.eta ELSE NULL END actual_arrival_time,
LAG(pc.id) OVER w AS departure_port_call_id,
LAG(pc.un_locode) OVER w AS departure_port,
CASE WHEN LAG(pc.etd_is_actual) OVER w THEN LAG(pc.etd) OVER w ELSE NULL END actual_departure_time
FROM port_calls AS pc