Skip to content

Instantly share code, notes, and snippets.

#!/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 / 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 <[email protected]>'
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
@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 <[email protected]>
* 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 / 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 / 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 <[email protected]>
// 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 / zcash-miner-Dockerfile
Last active July 8, 2017 04:29
Dockerfile and run script to mine zcash with EWBF and Dwarfpool. Pre-requisite: download and unzip EWBF into ./zec/miner
# Working as of Dec 2016
FROM ubuntu:14.04
MAINTAINER [email protected]
RUN apt-get update && apt-get --yes upgrade && apt-get --yes install iputils-ping less emacs24-nox git curl wget build-essential screen python-pip software-properties-common
RUN echo deb http://us.archive.ubuntu.com/ubuntu/ xenial multiverse >>/etc/apt/sources.list && \
echo deb-src http://us.archive.ubuntu.com/ubuntu/ xenial multiverse >>/etc/apt/sources.list && \
echo deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates multiverse >>/etc/apt/sources.list && \
echo deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates multiverse >>/etc/apt/sources.list
RUN apt-get update && apt-get --yes --no-install-recommends install nvidia-cuda-dev nvidia-cuda-doc
RUN apt-get --no-install-recommends --yes install nvidia-367; exit 0
@DrPaulBrewer
DrPaulBrewer / gcloud-discounted-VM-with-disk-and-startup-script.sh
Last active March 9, 2016 08:06
gcloud-discounted-VM-with-disk-and-startup-script.sh
!/bin/bash
# Do NOT use this as-is
# you probably need to change a few lines (disk, subnet, script)
# The google compute engine web UI may provide you
# with an equivalent command line for a specific configuration built in the web UI
gcloud compute instances create "my-spark-notebook" \
--description "docker spark jupyter-notebook analysis platform" \
--zone "us-east1-c" \
--machine-type "n1-highcpu-32" \
--subnet "default-754f8fec2c9e9fe2" \
@DrPaulBrewer
DrPaulBrewer / env2json.py
Created January 8, 2016 15:25
environment vars to JSON
#!/usr/bin/env python
import json
import os
print json.dumps(dict(os.environ))