Skip to content

Instantly share code, notes, and snippets.

@MasonM
MasonM / pg_dump_filter_and_separate.sh
Last active January 7, 2018 06:03
pg_dump_filter_and_separate.sh
#!/bin/bash
pg_dump --column-inserts | php -B '$dir = "sql"; $cur_table = null;' -R '
if (preg_match("/^(INSERT INTO (\w+) \([^)]*\) VALUES )(.*);$/", $argn, $matches)) {
$str = ($cur_table !== $matches[2]) ? $matches[1] : ",";
$cur_table = $matches[2];
file_put_contents("$dir/$cur_table.sql", "{$str}\n\t{$matches[3]}", FILE_APPEND);
}' -E 'foreach(glob("$dir/*.sql") as $f) file_put_contents($f, ";", FILE_APPEND);'
@MasonM
MasonM / pg_dump_filter.php
Created January 7, 2018 05:07
pg_dump multi-row insert cleanup
<?php
$current_table_insert = null;
while ($line = fgets(STDIN)) {
if (strpos($line, 'SET ') === 0) {
echo $line;
} elseif (strpos($line, 'INSERT INTO') === 0) {
preg_match('/^(INSERT INTO (\w+) \([^)]*\) VALUES )(.*);$/', $line, $matches);
if ($current_table_insert !== null) {
echo ($current_table_insert === $matches[1]) ? ',' : ';';
@MasonM
MasonM / pgst_install.sql
Last active January 2, 2018 04:17
PostgreSQL selected row tracking
BEGIN;
CREATE OR REPLACE FUNCTION pgst_suffix_table_name(table_name TEXT, suffix TEXT) RETURNS TEXT AS
$$
SELECT TEXT (table_name || '_pgst_' || suffix);
$$
LANGUAGE sql IMMUTABLE;
CREATE OR REPLACE FUNCTION pgst_start_for_table(table_name TEXT) RETURNS void AS
@MasonM
MasonM / xpath.sh
Created March 11, 2017 02:56
Search confluence XML export using Nokogir
#!/bin/bash
nokogiri entities.xml -e '
# Based on https://github.com/locationtech/udig-platform/blob/4b926e7bd35d4c95ee2b7a4d1c3294cc3c2729a7/docs/src/main/java/docs/ConfluencePage.java#L103
current_pages=%{
//object[
@class="Page"
and property[@name="contentStatus" and .="current"]
and (
collection[@name="historicalVersions"]
@MasonM
MasonM / gist:6c8bd9ee9115967cbd9aeafb8bcb59f8
Created February 8, 2017 21:54
Command to dump *.adobe.com cookies for OS X
sqlite3 "$HOME/Library/Application Support/Google/Chrome/Default/Cookies" 'select creation_utc, host_key, name, length(encrypted_value) AS value_length, has_expires from cookies where host_key like "%.adobe.com"' > $HOME/Desktop/adobecookies.txt
mmalone@docker> stock.phpunit
OK
PHPUnit 5.7.4 by Sebastian Bergmann and contributors.
............................................................. 61 / 1841 ( 3%)
............................................................. 122 / 1841 ( 6%)
............................................................. 183 / 1841 ( 9%)
............................................................. 244 / 1841 ( 13%)
............................................................. 305 / 1841 ( 16%)
............................................................. 366 / 1841 ( 19%)
#!/usr/bin/env python3
import random
import collections
import re
class MinesweeperGrid:
def __init__(self, size, num_bombs):
self.size = size
self.num_bombs = num_bombs
@MasonM
MasonM / scopus_api_response.json
Created April 20, 2016 20:04
Scopus EID change
{"@_fa":"true","link":[{"@_fa":"true","@ref":"self","@href":"http://api.elsevier.com/content/abstract/scopus_id/84951299285"},{"@_fa":"true","@ref":"author-affiliation","@href":"http://api.elsevier.com/content/abstract/scopus_id/84951299285?field=author,affiliation"},{"@_fa":"true","@ref":"scopus","@href":"http://www.scopus.com/inward/record.url?partnerID=HzOxMe3b\u0026scp=84951299285\u0026origin=inward"},{"@_fa":"true","@ref":"scopus-citedby","@href":"http://www.scopus.com/inward/citedby.url?partnerID=HzOxMe3b\u0026scp=84951299285\u0026origin=inward"},{"@_fa":"true","@ref":"full-text","@href":"http://api.elsevier.com/content/article/eid/1-s2.0-S2221169115002191"}],"prism:url":"http://api.elsevier.com/content/abstract/scopus_id/84951299285","dc:identifier":"SCOPUS_ID:84951299285","eid":"2-s2.0-84951299285","dc:title":"Combined treatment of 3-hydroxypyridine-4-one derivatives and green tea extract to induce hepcidin expression in iron-overloaded \u03b2-thalassemic mice","dc:creator":"Upanan S.","prism:publicat
#!/bin/sh
curl -d @- https://ws.isiknowledge.com/cps/xrpc << END
<?xml version="1.0" encoding="UTF-8" ?>
<request xmlns="http://www.isinet.com/xrpc42"
src="app.id=PartnerApp,env.id=PartnerAppEnv,partner.email=EmailAddress">
<fn name="LinksAMR.retrieve">
<list>
<!-- WHO'S REQUESTING -->
<map>
@MasonM
MasonM / bug.applescript
Last active August 29, 2015 14:02
reproduce indesign 5.5 applescript bug
script GetElementsRule
property name : "GetElementsRule"
property xpath : "//foo"
property elements : {}
on apply(xml_element, rule_processor)
set elements to elements & xml_element
return false
end apply