Skip to content

Instantly share code, notes, and snippets.

View slattery's full-sized avatar

Mike Slattery slattery

View GitHub Profile
CREATE OR REPLACE FUNCTION public.json_append(data json, insert_data json)
RETURNS json
LANGUAGE sql
AS $$
SELECT ('{'||string_agg(to_json(key)||':'||value, ',')||'}')::json
FROM (
SELECT * FROM json_each(data)
UNION ALL
SELECT * FROM json_each(insert_data)
) t;
// One way converter from E4X XML to JSON
// 1) turns <body><item>1</item><item>2</item></body> into
// body: {item: ["1", "2"]} so that lists are easier to work with
// 2) turns things like: <body a="a">whatever</body> into
// body: {_a: "a", _: "whatever"}
// however <body>whatever</body> becomes simply body: "whatever
// - attributes specified by ignored are ignored
function E4XtoJSON(xml, ignored) {
var r, children = xml.*, attributes = xml.@*, length = children.length();
if(length == 0) {
@slattery
slattery / nginx.conf
Last active August 29, 2015 14:16 — forked from plentz/nginx.conf
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@slattery
slattery / basic.sql
Last active August 29, 2015 14:17 — forked from nesquena/basic.sql
/* How to calculate postgreSQL database size in disk ? */
SELECT pg_size_pretty(pg_database_size('thedbname'));
/* Calculate size of a table including or excluding the index */
SELECT pg_size_pretty(pg_total_relation_size('big_table'));
SELECT pg_size_pretty(pg_relation_size('big_table')); /* without index */
/* See indexes on a table with `\d tablename` */
@slattery
slattery / README.md
Last active August 29, 2015 14:19 — forked from foosel/README.md

First experiments with NodeMCU to publish the current settings of my adjustable height working desk to MQTT.

NodeMCU can be found here: https://github.com/nodemcu/nodemcu-firmware

Note that you'll need a current version with support for floats (which the ultrasonic sensor library utilizes), I'm using 0.9.5 2015-03-18 with float support myself.

Support for the HC-SR04 sensor in NodeMCU can be found here: https://github.com/sza2/node_hcsr04

I provided my slightly adjusted version which makes measuring a non-blocking afair, allowing for callbacks when the measurement completes.

/******************************************************************************
How to load Javascript modules into postgres
******************************************************************************/
CREATE EXTENSION IF NOT EXISTS plv8
/******************************************************************************
First step is download the Javascript module file
Example with undescore-min and node-jpath
******************************************************************************/
@slattery
slattery / thesis-vm
Last active August 29, 2015 14:22 — forked from tonejito/thesis-vm
#!/bin/bash
# thesis-vm - Launches a serial console enabled VM and connects to ttyS0 with gnu screen
# Andres Hernandez - tonejito
# September 2013
RM=rm
TEE=tee
SED=sed
GREP=grep
ECHO=echo
#!/bin/bash
# This script can be used as wrapper for rsync in authorized_keys. It restricts rsync the following way:
# - restrict target directory to be under /backups/backup-rsync-push/${1}/target/ where $1 is an argument from authorized_keys
# - restrict target directory to be exactly 1 level below this directory
# - restrict flags
# - restrict arguments
# - force --fake-super argument
err() {
#!/bin/bash
# Execute as a bash file, so no copy-paste in your terminal please.
# clear meaningless config settings
git config --global --remove-section apply
# aliases for basic commands
git config --global alias.st status
git config --global alias.ci commit
Feature: Google Demo
Scenario: Google home page
When I open http://google.com
The the title should be Google