Skip to content

Instantly share code, notes, and snippets.

View plindberg's full-sized avatar

Peter Lindberg plindberg

View GitHub Profile
@plindberg
plindberg / README.md
Last active July 4, 2018 07:39
Dump PostgreSQL table with JSONB column, qualifying by some JSON value, formatting for presentation using Heroku Dataclips

A while back, I wrote [a script to do daily dumps of a PostgreSQL table with a JSONB column][old one]. This was something an intern did daily for a client.

However, as summer came, we needed to automate this. The simplest and quickest solution turned out to do this using Heroku Dataclips.

I wasn’t aware of the [JSON functions and operators][json ops] of PostgreSQL, allowing you to both SELECT stuff from inside the JSON, and use in WHERE predicates. (It appears that you can even set up indexes on JSON values.)

@plindberg
plindberg / README.md
Last active June 27, 2018 15:05
Dump PostgreSQL table with JSONB column as TSV file, pasteable into Google Sheets

This script is one I wrote to dump a PostgreSQL table with a JSONB column into TSV put on your pasteboard (on macOS) such that you can just paste it into a Google Sheet.

I needed this for a client and it was a bit of work, so I thought it might be useful to someone out there.

@plindberg
plindberg / git-foreach-remote-show-latest-commit.sh
Last active May 21, 2018 12:57
Show most recent commit of each Git remote
git remote | \
xargs -n1 -I{} \
git log --oneline -1 --pretty=format:"%C(red)%h%d%C(reset) %s /%an, %ar" {}/master
Verifying my Blockstack ID is secured with the address 1KV2ZFAsWsPWLx7NVadUNSwAPpQtw3jsxw https://explorer.blockstack.org/address/1KV2ZFAsWsPWLx7NVadUNSwAPpQtw3jsxw
@plindberg
plindberg / README.md
Created August 5, 2017 16:46
How to set up an AWS Lambda function for returning S3 pre-signed URLs for uploading files.

README

Granted, this is little more than an obfuscated way of having a publicly writable S3 bucket, but if you don’t have a server which can pre-sign URLs for you, this might be an acceptable solution.

For this to work, you take the following steps:

  1. Create a Lambda func, along with a new IAM role, keeping the default code.
  2. Create an API in the API Gateway.

Rich Hickey on becoming a better developer

Sorry, I have to disagree with the entire premise here.

A wide variety of experiences might lead to well-roundedness, but not to greatness, nor even goodness. By constantly switching from one thing to another you are always reaching above your comfort zone, yes, but doing so by resetting your skill and knowledge level to zero.

Mastery comes from a combination of at least several of the following:

  • Knowledge
  • Focus
Verifying that +plindberg is my blockchain ID. https://onename.com/plindberg
@plindberg
plindberg / dump-watson-dialog-conversation-history.sh
Last active June 21, 2016 17:26
Quick and dirty dump of Watson Dialog conversation history (using httpie and jq)
http -b -a ${WATSON_DIALOG_USERNAME}:${WATSON_DIALOG_PASSWORD} \
https://gateway.watsonplatform.net/dialog/api/v1/dialogs/${WATSON_DIALOG_ID}/conversation\
\?date_from='2016-01-27 00:00:00'\&date_to='2016-06-22 00:00:00' \
|jq '
.conversations[] | .messages |
[
.[] |
if .from_client == "true" then
"> \(.text)"
else
'use strict';
const co = require('co');
// Like `reduce()` but accepting a generator function, such that it can be used asynchronously
// within a generator function invoked by `co()`.
function* reduceg(arr, genfn, initial) {
let acc = initial;
for (let x of arr) {
acc = yield genfn(acc, x);
@plindberg
plindberg / ibm-watson-dialog-with-inline-javascript-function.xml
Last active June 22, 2016 14:41
A minimal example of a Watson Dialog XML script with an inline Javascript function.
<?xml version="1.0" encoding="UTF-8" ?>
<dialog xsi:noNamespaceSchemaLocation="WatsonDialogDocument_1.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<flow>
<folder label="Main">
<output id="start">
<prompt>
<item>Write stuff and I’ll SHOUT it back to you.</item>
</prompt>