Skip to content

Instantly share code, notes, and snippets.

//-----------------------------------------------------------------------------------------------------------------------
/*
* Create a lambda function handler for a graphQL typeName.fieldName
*/
//-----------------------------------------------------------------------------------------------------------------------
const createAppSyncLambdaHandler = function (stack: cdk.Stack, api: appsync.GraphQLApi, recipe: {
name: string, // XXX autogenerate frome type.field the name root of the name for the handler and data source
environment: { [key: string]: string }, // @see https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html
permissions: { obj: any, func: any }, // the currently singleton permissions for the handler to e.g. talk to dynamoDB
description: string, // text description attached to various created objects (can be undefined)
@pszabop
pszabop / Dockerfile
Last active August 2, 2020 00:32
All these go in a deploy directory. The CDK is under the deploy directory which isn't the prettiest thing but neither is docker pretty
FROM node:12.16.1
RUN npm update -g aws-cdk@1.51.0
RUN npm install -g aws-cdk@1.51.0
@pszabop
pszabop / gun-load-hang.js
Last active January 28, 2020 07:35
Show that a load of a non-existant key hangs gun database, but a get does not.
'use strict'
const tape = require('tape')
const _test = require('tape-promise').default // <---- notice 'default'
const test = _test(tape) // decorate tape
const Gun = require('gun');
const GunLoad = require('gun/lib/load.js');
const mkdirp = require('mkdirp');
const { Random } = require('random-js');
const random = new Random();
const _ = require('underscore');
@pszabop
pszabop / GunShareExample
Created January 16, 2020 20:32
Example of using Gun to share a secret with another user. Includes unit tests.
// alas this generates the warning `user.pair() IS DEPRECATED AND WILL BE DELETED!!!`
//
// put a value shared between two users
// user and this user (classic public key encryption, except that a session
// key is used instead of encrypting the data with the public key.
// analagous to `openssl pkeyutl -derive -inkey key.pem -peerkey pubkey.pem -out secret`
//
// @param: key - the key where the value is stored
// @param: value - the value to store at index key
// @param: otherUser - the info or public key of the other user to share the value with
'use strict'
const tape = require('tape')
const _test = require('tape-promise').default // <---- notice 'default'
const test = _test(tape) // decorate tape
const Gun = require('gun');
const GunThen = require('gun/lib/then.js')
const GunPromise = require('gun/lib/promise.js')
const mkdirp = require('mkdirp');
const { Random } = require('random-js');
const random = new Random();
//
// o.id o.__version, and o.__lastUpdate have special meaning or are reserved
//
graphdb.upsertVertexVersioned = async function(type, o) {
const g = traversal().withRemote(this.connection);
let oldVersion;
// don't modify original in case of exceptions
// return the new object and let user decide to reassign or not
o = Object.assign({}, o);

Cloudflare S3 bucket permissions

The logic is convoluted for S3 bucket ACLs. You have to use double negative logic...

Copy and paste this example, keeping cloudflare IP addresses as you need. The following website is helpful: cloudflare IP addresses

{
@pszabop
pszabop / gist:f2fc9fad4bd87ede757c05dd30741a1d
Last active March 17, 2017 21:02
snippet of upload code for a signed POST URL with minio
--------------SUMMARY -----------------
// Uploading a multimedia resource file is a 3-step process:
//
// 1. Acquire an "upload ticket"
// 2. Use the upload ticket to upload the file
// 3. Acquire a "perma link" to the uploaded file
//
-------------- SERVER SIDE ----------------------
picture.initiate = function(current, original) {