Skip to content

Instantly share code, notes, and snippets.

@mrw34
mrw34 / file.sh
Created October 2, 2020 14:51
CSV to JSON using Python 2
python -c "import csv,json,fileinput;print(json.dumps(list(csv.DictReader(fileinput.input()))))" file.csv
@mrw34
mrw34 / INSTALL.sh
Created March 17, 2018 15:26
Install "go read" on App Engine using Google Cloud Shell
# open https://console.cloud.google.com/home/dashboard?cloudshell=true
PROJECT_ID=go-read-123456
gcloud projects create $PROJECT_ID
gcloud app create --project=$PROJECT_ID
goapp get -d github.com/mjibson/goread
cd ~/gopath/src/github.com/mjibson/goread/app/
sed s/go-read/$PROJECT_ID/ app.sample.yaml >app.yaml
cp ../settings.go.dist ../settings.go
goapp deploy
@mrw34
mrw34 / postgres.sh
Last active December 12, 2024 17:54
Enabling SSL for PostgreSQL in Docker
#!/bin/bash
set -euo pipefail
openssl req -new -text -passout pass:abcd -subj /CN=localhost -out server.req -keyout privkey.pem
openssl rsa -in privkey.pem -passin pass:abcd -out server.key
openssl req -x509 -in server.req -text -key server.key -out server.crt
chmod 600 server.key
test $(uname -s) = Linux && chown 70 server.key
docker run -d --name postgres -e POSTGRES_HOST_AUTH_METHOD=trust -v "$(pwd)/server.crt:/var/lib/postgresql/server.crt:ro" -v "$(pwd)/server.key:/var/lib/postgresql/server.key:ro" postgres:12-alpine -c ssl=on -c ssl_cert_file=/var/lib/postgresql/server.crt -c ssl_key_file=/var/lib/postgresql/server.key
@mrw34
mrw34 / package.json
Created April 6, 2016 16:45
Mixpanel export
{
"dependencies": {
"moment": "^2.12.0",
"request": "^2.70.0",
"underscore": "^1.8.3"
}
}
@mrw34
mrw34 / mailx.sh
Last active February 29, 2016 10:00
A primitive mailx emulator using bash, curl and Mailgun
#!/bin/bash
set -eu -o pipefail
cmd="curl -s --user 'api:$MAILGUN_API_KEY' https://api.mailgun.net/v2/$MAILGUN_DOMAIN/messages"
while getopts "r:c:b:s:a:E" opt; do
case $opt in
r)
cmd+=" -F from='$OPTARG'"
;;
@mrw34
mrw34 / package.json
Created December 14, 2015 20:06
West London Xmas Hack Night
{
"dependencies": {
"underscore": "^1.8.3",
"vorpal": "^1.4.0",
"ws": "^0.8.1"
}
}
@mrw34
mrw34 / gist:b12531d1a8df25f6c170
Last active May 21, 2024 10:47
Trello JSON to CSV conversion using jq
jq -r '["List", "Card"], ((reduce .lists[] as $list ({}; .[$list.id] = $list.name)) as $lists | .cards[] | select(.closed != true) | [$lists[.idList],.name]) | @csv' <nw3RUeLl.json
@mrw34
mrw34 / index.js
Last active April 11, 2016 20:13
Stable JavaScript Object hash function for Node.js
function hash(object, algorithm, encoding) {
var h = require('crypto').createHash(algorithm || 'md5');
(function update(v, k) {
if (k !== undefined) {
h.update(JSON.stringify(k));
}
if (v && v.constructor === Array) {
v.forEach(function(value) {
update(h, value);
});
@mrw34
mrw34 / blog.xml
Created May 26, 2014 19:51
Minimal Jekyll Atom feed template
---
---
<feed xmlns="http://www.w3.org/2005/Atom">
<title>{{site.title}}</title>
<id>http://{{site.domain}}/</id>
<updated>{{site.time | date_to_xmlschema}}</updated>
<link href="http://{{site.domain}}/blog.xml" rel="self"/>
{% for post in site.posts %}