Skip to content

Instantly share code, notes, and snippets.

@DrPaulBrewer
DrPaulBrewer / createStorageKey.js
Created October 4, 2017 21:35
create random AES-256 key in hex -- compatible with Google Cloud Storage
// Copyright 2017 Paul Brewer, Economic and Financial Technology Consulting LLC <drpaulbrewer@eaftc.com>
// License: The MIT License. See: https://opensource.org/licenses/MIT
// Google has an example using base64; hex is a little safer to copy/paste and recognize as incorect
// see https://cloud.google.com/storage/docs/using-encryption-keys
@DrPaulBrewer
DrPaulBrewer / setup-scala-sbt.sh
Last active October 25, 2017 07:08
Set up openjdk 8 and scala build tool sbt on bare ubuntu/debian machine
#!/bin/bash -e
apt-get --yes update
apt-get --yes install openjdk-8-jdk emacs-nox curl wget apt-transport-https
# modified from "Installing sbt on Linux" at http://www.scala-sbt.org/1.x/docs/Installing-sbt-on-Linux.html
echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823
@DrPaulBrewer
DrPaulBrewer / nginx-alert.sh
Last active March 20, 2019 03:40
git-hook for on-push nginx configuration, testing, and alerting
#!/bin/bash
# originally /root/nginx-alert.sh
APK='your-mailgun-key' # replace with mailgun key
FROM='Nginx Alert <mailgun@mg.econ1.net>'
TO='you@email' # replace with recipients
# SUBJECT, TEXT is exported from caller
curl -s --user $APK \
https://api.mailgun.net/v3/mg.econ1.net/messages \
-F from="$FROM" \
-F to="$TO" \
@DrPaulBrewer
DrPaulBrewer / RandomizedSniperFailureModel.py
Last active June 23, 2019 03:28
Randomized Model of Markets populated by Gode and Sunder (1993) ZI robots + Todd Kaplan's Snipers with Sniper Failure -- for section 3 of Brewer and Ratan (2018)
#!/usr/bin/env python3
# File: RandomizedSniperFailureModel.py
# Copyright 2018 Paul Brewer, Economic and Financial Technology Consulting LLC
# This code approximates allocation efficiency, source of efficiency losses, and
# Gini Coefficient for profits accumulated over many periods in a market populated
# by a mix of Gode and Sunder (1993) ZI robots and Todd Kaplan's Sniper robots.
# In this code, we only model the "failsafe" case where the snipers fail to find or
# act on exceptional prices or low bid-ask spread and so execute the end-of-period failsafe
# strategy of accepting any existing profitable bid/ask. Taking an average
# over random shuffling of Snipers imperfectly approximates the interactions over multiple
#!/bin/bash -e
# Copyright 2020 Paul Brewer, Economic and Financial Technology Consulting LLC
# Open Source License: The MIT License, see https://opensource.org/licenses/MIT
# rsyncs (read-only) all files in all accessible Google Cloud Storage Buckets to ~/gb/<bucketname>/
# Important: This script can use many gigabytes of Google Cloud outgoing bandwidth even in a short period of time.
# All fees for Google bandwidth are the responsibility of the user running this software.
mkdir -p ~/gb
cd ~/gb
BUCKETLIST=$(gsutil ls gs://)
for b in $BUCKETLIST
@DrPaulBrewer
DrPaulBrewer / GINISS
Last active May 4, 2020 04:19
GINISS Gini Coefficient Function for Google Sheets. Open Tools->Script Editor in Sheets and Copy/Paste.
/*
* GINISS and THEILT Copyright 2018- Paul Brewer, Economic and Financial Technology Consulting LLC <drpaulbrewer@eaftc.com>
* This file may be used or copied under the terms of the MIT License as explained below or at https://opensource.org/licenses/MIT
* The MIT License
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
@DrPaulBrewer
DrPaulBrewer / HamGridSquare.js
Last active December 12, 2020 17:18
find Maidenhead grid square from latitude and longitude
// HamGridSquare.js
// Copyright 2014 Paul Brewer KI6CQ
// License: MIT License http://opensource.org/licenses/MIT
//
// Javascript routines to convert from lat-lon to Maidenhead Grid Squares
// typically used in Ham Radio Satellite operations and VHF Contests
//
// Inspired in part by K6WRU Walter Underwood's python answer
// http://ham.stackexchange.com/a/244
// to this stack overflow question:
@DrPaulBrewer
DrPaulBrewer / UploaderForGoogleDrive.js
Last active December 17, 2022 09:49
Upload Browser Blobs to Files in Google Drive API v3
// upload.js, from https://github.com/googledrive/cors-upload-sample
// Contributors Steve Bazyl, Mike Procopio, Jeffrey Posnick, Renaud Sauvain
// License: Apache 2.0 http://www.apache.org/licenses/LICENSE-2.0
//
// Implements Resumable Upload for Google Drive as described by
// https://developers.google.com/drive/v3/web/resumable-upload
//
// Modified by Paul Brewer, Economic and Financial Technology Consulting LLC
// Nov. 1 2017
// 1. use Google Drive API V3 instead of V2
@DrPaulBrewer
DrPaulBrewer / rtlsdr-to-gqrx.c
Last active March 25, 2024 05:12
rtlsdr-to-gqrx SDR file format converter
#include <complex.h>
#include <stdio.h>
#include <stdlib.h>
// rtlsdr-to-gqrx Copyright 2014 Paul Brewer KI6CQ
// License: GNU GPL 3.0
//
// IQ file converter for Software Defined Radio Programs rtl_sdr, gqrx
// from rtl_sdr recording format -- interleaved unsigned char
// to gqrx/gnuradio .cfile playback format -- complex64