Skip to content

Instantly share code, notes, and snippets.

Avatar

Yves Richard whyvez

View GitHub Profile
@whyvez
whyvez / csvjson.awk
Last active Oct 1, 2020
Simple awk csv to ndjson converter.
View csvjson.awk
BEGIN {
FPAT = "([^,]*)|(\"[^\"]+\")"
}
NR == 1 {
split($0, header, ",")
}
NR > 1 {
@whyvez
whyvez / firebase_pre-request_script.js
Created Sep 3, 2020 — forked from moneal/firebase_pre-request_script.js
Postman pre-request script to create a Firebase authentication JWT header.
View firebase_pre-request_script.js
/**
* This script expects the global variables 'refresh_token' and 'firebase_api_key' to be set. 'firebase_api_key' can be found
* in the Firebase console under project settings then 'Web API Key'.
* 'refresh_token' as to be gathered from watching the network requests to https://securetoken.googleapis.com/v1/token from
* your Firebase app, look for the formdata values
*
* If all the data is found it makes a request to get a new token and sets a 'auth_jwt' environment variable and updates the
* global 'refresh_token'.
*
* Requests that need authentication should have a header with a key of 'Authentication' and value of '{{auth_jwt}}'
@whyvez
whyvez / README.md
Last active Jul 22, 2020
OSM Planet PBF to PostgreSQL loader on GCP
View README.md

osm-loader

Small utility that loads OSM planet data into PosgresSQL.

Utility does the following:

  • Creates GCP instance with 4 SSD (1.5TB)
  • Bootstraps instance with dependencies (src/install.sh)
  • Copies src/load.sh to instance.

Usage:

@whyvez
whyvez / index.js
Last active Jun 5, 2020
Gable board calculator.
View index.js
#!/usr/bin/env node
const gabbleWidth = 22*12;
const boardCoverage = 6.375;
const boardLength = 144;
const nBoards = Math.ceil(gabbleWidth/boardCoverage);
const narray = (n, v) => {
let arr = [...Array(Math.ceil(n+1)).keys()];
arr.shift();
@whyvez
whyvez / delete-all-stacks.sh
Last active Aug 29, 2018
Deletes all AWS CloudFormation stacks - USE WITH CAUTION!
View delete-all-stacks.sh
#!/bin/bash
aws cloudformation list-stacks | jq -r '.[][].StackName' | while read -r stack_name; do
aws cloudformation delete-stack --stack-name "${stack_name}"
echo "deleted stack ${stack_name}"
done
View bashstyle.md

progrium/bashstyle

Bash is the JavaScript of systems programming. Although in some cases it's better to use a systems language like C or Go, Bash is an ideal systems language for smaller POSIX-oriented or command line tasks. Here's three quick reasons why:

  • It's everywhere. Like JavaScript for the web, Bash is already there ready for systems programming.
  • It's neutral. Unlike Ruby, Python, JavaScript, or PHP, Bash offends equally across all communities. ;)
  • It's made to be glue. Write complex parts in C or Go (or whatever!), and glue them together with Bash.

This document is how I write Bash and how I'd like collaborators to write Bash with me in my open source projects. It's based on a lot of experience and time collecting best practices. Most of them come from these two articles, but here integrated, slightly modified, and focusing on the most bang for buck items. Plus some ne

@whyvez
whyvez / split.sh
Created May 31, 2018
maps each layer in input file into separate GeoJSON file
View split.sh
#!/usr/bin/env bash
# desc: maps each layer in input file into separate GeoJSON file
# usage: ./split human_footprint.gdb
# dep: gdal, awk, parallel
input="$1"
ogrinfo "$input" \
| awk '{if (NR > 2) print $2}' \
@whyvez
whyvez / deploy.sh
Last active Nov 18, 2017
CircleCi ElasticBeanstalk deploy
View deploy.sh
#!/usr/bin/env bash
# USAGE:
# DEPLOYMENT_BUCKET=your-deployement-bucket APPLICATION_NAME=your-application-name ENVIRONMENT_NAME=your-environment-name bash ./deploy.sh
commit_sha=$(git rev-parse HEAD)
bundle_name=${commit_sha}.zip
zip -r -x=*node_modules* -x=*.git* $bundle_name * .[^.]*
@whyvez
whyvez / jtf.js
Created Oct 21, 2017
Simple example of a JavaScript based Terraform pre-processor using tagged template literal
View jtf.js
function resource (literals, func) {
console.log(`resource ${literals[0]} ${func()} ${literals[1]}`);
}
function ip_set_descriptors (literals, func) {
return `ip_set_descriptors ${literals[0]} ${func()} ${literals[1]}`;
}
const ips = ['209.171.43.251', '54.55.73.82'];
@whyvez
whyvez / nginx-proxy.sh
Created Oct 6, 2017
Install NGINX as proxy
View nginx-proxy.sh
#!/usr/bin/env bash
url=$1
sudo yum update -y
sudo yum install nginx -y
sudo bash -c "cat >/etc/nginx/nginx.conf" <<EOF
user nginx;
worker_processes 1;