Skip to content

Instantly share code, notes, and snippets.

@MasonM
MasonM / inject_naver.js
Created June 19, 2019 20:28
Sandboxing Naver pixel
// POC code for injecting the Naver wcslog.js tag inside an iframe sandbox
var iframe = document.createElement('iframe');
iframe.sandbox = 'allow-scripts';
iframe.srcdoc = '<script src="https://wcs.naver.net/wcslog.js" type="text/javascript"><\/script>';
document.body.appendChild(iframe);
@MasonM
MasonM / inject_demandbase.js
Last active June 12, 2019 23:53
Sandboxing Demandbase tag
// POC code for injecting Demandbase inside an iframe sandbox
var iframe = document.createElement('iframe');
iframe.sandbox = 'allow-scripts';
// note: the actual production version of this will probably have a separate HTML file instead of
// "srcdoc" because of browser support issues. This is just for POC purposes.
iframe.srcdoc = '<script src="https://scripts.demandbase.com/qQQxkRp0.min.js" type="text/javascript"><\/script>';
document.body.appendChild(iframe);
@MasonM
MasonM / test_plugin.js
Created April 17, 2019 01:45
Example plugin to override index page
module.exports = {
name() { return 'test_plugin' },
open(context) { this.make = context.messageMaker('test_plugin').make },
processMessage(message, queue) {
if (message.type === 'sitespeedio.setup') {
queue.postMessage(this.make('html.pug', {
id: 'index',
name: 'Overridden index',
pug: "html\n body\n h1 Hello!",
type: 'summary',
@MasonM
MasonM / bucketpolicypermissions.json
Created July 7, 2018 19:54
A Cloud guru missing resource
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
#!/bin/bash
yum install httpd php php-mysql -y
yum update -y
chkconfig httpd on
service httpd start
echo "<?php phpinfo(); ?>" > /var/www/html/index.php
cd /var/www/html
wget https://s3.eu-west-2.amazonaws.com/acloudguru-example/connect.php
@MasonM
MasonM / depends.sql
Created March 28, 2018 06:16
depends.sql
SELECT
pg_catalog.pg_get_constraintdef(source_constraint.oid),
source_constraint.conkey,
source_table.relname AS source_table,
source_attribute.attname AS source_attribute,
related_table.relname AS related_table,
related_attribute.attname AS related_attribute
FROM pg_catalog.pg_namespace AS namespace
INNER JOIN pg_catalog.pg_class AS source_table ON (source_table.relnamespace = namespace.oid)
INNER JOIN pg_catalog.pg_attribute AS source_attribute ON (source_attribute.attrelid = source_table.oid)
@MasonM
MasonM / wiremock-admin-api.json
Created February 26, 2018 05:50
Wiremock API spec in OpenAPI 3.0 format
{
"info": {
"title": "WireMock",
"version": "2.15.0"
},
"paths": {
"/__admin/mappings": {
"delete": {
"responses": {
"200": {
@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