Skip to content

Instantly share code, notes, and snippets.

View slattery's full-sized avatar

Mike Slattery slattery

View GitHub Profile
// 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 / README.md
Created February 11, 2015 15:45
copy JSON obj in Chrome dev tools

wat do?

  1. Right-click the object and select "Store as global variable"
  2. The console will print the new variable's name, for example: temp1
  3. Type: copy(temp1)

The object is now available in your clipboard.

@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.

@slattery
slattery / README.md
Last active October 21, 2015 13:15
Git branch reporter for npm-linked actionhero plugins

#gitcheck.js This initializer checks plugin directories for git branches, and reports which branch is being loaded by the server.

I use npm link to serve up my plugins-in-progress for actionhero. I ask npm's preinstall hook to run npm link $PLUGIN so that the plugin will be in actionhero's node_modules dir when the main install happens.

It works very well for us, but when the gitflow is feverish I need to double check which branch I'm running in a given actionhero config.

I put this initializer at the projectRoot level, and it sweeps my plugins to report on git branches.

/******************************************************************************
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 / tsz_touch_parent_row.sql
Last active August 29, 2015 14:22
perform a lastmod stamp in a parent table by supplying all args or follow the fk
-- PROCEDURE tsz_touch_parent_row()
-- generic function to perform a lastmod in any parent table with a lastupdatestamp column.
-- get to it directly by supplying all args or follow fk
CREATE OR REPLACE FUNCTION tsz_touch_parent_row()
RETURNS TRIGGER AS $func$
DECLARE
-- _tsz needs to be preconfigured, it should be your standard
-- naming convention for the tsz mod column in every table
@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() {