Skip to content

Instantly share code, notes, and snippets.

View slattery's full-sized avatar

Mike Slattery slattery

View GitHub Profile
@slattery
slattery / README.md
Last active November 14, 2016 14:07 — forked from rgdonohue/README.md
Dynamic Legends in CartoDB
@slattery
slattery / remove-docker-containers.md
Created October 24, 2016 20:38 — forked from ngpestelos/remove-docker-containers.md
How to remove unused Docker containers and images
  1. Delete all containers

     $ docker ps -q -a | xargs docker rm
    

-q prints only the container IDs -a prints all containers

Notice that it uses xargs to issue a remove container command for each container ID

  1. Delete all untagged images
@slattery
slattery / leader-election.md
Created October 6, 2016 13:22 — forked from andrewle/leader-election.md
Leader Election With Ruby & PostgreSQL

Leader Election With Ruby & PostgreSQL

The Problem

I have a table with millions of rows that needs processing. The type of processing is not really important for this article. We simply need to process some data with Ruby --or any other user-space programming language.

A Solution

// Handy plv8 console object (debugging)
var console = (function(){
var columns = 100;
function logString(level, str) {
var chunk = str.substring(0, columns);
var overflow = str.substring(columns);
plv8.elog(level, chunk);
if (overflow.length) logString(level, " | "+overflow);
};
@slattery
slattery / apply.sql
Created October 6, 2016 13:14 — forked from audreyt/apply.sql
plv8 SQL for the |> and <| operators (aka LiveScript application): SELECT '{"hello": [1,2,3]}' |> 'this.hello[0]'; SELECT 'this.hello[0]' <| '{"hello": [1,2,3]}';
CREATE OR REPLACE FUNCTION plv8x.json_eval(code text) RETURNS plv8x.json AS $$
return JSON.stringify(
eval("(function(){return #code})").apply(this)
);
$$ LANGUAGE plls IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION plv8x.json_eval(data plv8x.json, code text) RETURNS plv8x.json AS $$
return JSON.stringify(
eval("(function(){return #code})").apply(JSON.parse(data))
);
$$ LANGUAGE plls IMMUTABLE STRICT;
@slattery
slattery / perSchema_plv8_init.js.sql
Created October 6, 2016 13:11 — forked from bitifet/perSchema_plv8_init.js.sql
Allow per-schema plv8_init functions.
/* public.plv8_startup()
*
* Allow to have multiple per-schema plv8_init functions.
*
* USAGE:
*
* 1. Add the following line to the end of your postgresql.conf file:
*
* plv8.start_proc = 'public.plv8_startup'
*
@slattery
slattery / plv8js.md
Created October 6, 2016 13:08
plv8 doc

PL/v8

PL/v8 is a trusted procedural language that is safe to use, fast to run and easy to develop, powered by V8 JavaScript Engine.

Contents

Implemented features are as follows.

@slattery
slattery / plv8-modules.sh
Created October 6, 2016 13:07 — forked from daviddahl/plv8-modules.sh
plv8-modules
#! /bin/bash
sudo apt-get install npm
cd /var/django
npm install moment moment-timezone
sudo -u postgres psql -d template1 -c "create extension plv8;"
sudo -u postgres psql -d template1 << EOF

Listen / Notify for automatic object updates - pattern in postgreSQL Presented at the San Francsico PostgreSQL User Group Meetup 8/17/15

by Eric Eslinger [email protected] github.com/ericeslinger

This example uses listen/notify calls in PostgreSQL that trigger on row update to pass events from the database to a listening node.js web application that in turn uses socket.io to pass events