Skip to content

Instantly share code, notes, and snippets.

@tphummel
tphummel / Dockerfile
Last active Jul 22, 2020
Http server binary in a scratch container
View Dockerfile
FROM scratch
COPY ./http /bin/app
ENTRYPOINT ["/bin/app"]
@tphummel
tphummel / README.md
Last active Jun 7, 2020
Metacritic Review Scrape
View README.md

Scrape Reviews from Metacritic

  1. Browse a metacritic page of results like: All-Time Nintendo DS Reviews
  2. Open developer tools > Console
  3. Paste the javascript into the console prompt
  4. Execute the javascript
  5. the exported json is now in your clipboard. paste the json into a file and save.

Notes:

  • You can get 100 results per page so it isn't too bad doing it this way.
@tphummel
tphummel / git-to-csv.sh
Created Feb 9, 2020
convert master branch git log to csv
View git-to-csv.sh
#!/usr/bin/env bash
set -o nounset
set -o errexit
set -o pipefail
set -x
IFS=$'\n\t'
main(){
for d in *; do
View dedupe-array.js
const assert = require('assert').strict
function dedupe (input) {
return Object.keys(input.reduce((memo, num) => {
memo[num] = true
return memo
}, {})).map((numStr) => {
return parseInt(numStr, 10)
})
}
@tphummel
tphummel / README.md
Last active Sep 1, 2019
craps simulator
View README.md

craps toy/simulator

usage

➜  node craps-toy.js
┌─────────┬──────┬──────┬─────┬─────────────┐
│ (index) │ die1 │ die2 │ sum │   result    │
├─────────┼──────┼──────┼─────┼─────────────┤
│    0    │  1   │  4   │  5  │ 'point set' │
@tphummel
tphummel / Vagrantfile
Last active May 29, 2019
Vagrantfile to install nginx, configure javascript custom modules, and a hello world example
View Vagrantfile
# vagrant box add --name ol76 --checksum cfb58aaa12f56702afd739966273df63cd3ff3362e6a5a3fa6fa9ffcec4762e3 --checksum-type sha256 https://yum.oracle.com/boxes/oraclelinux/ol76/ol76.box
# https://nginx.org/en/docs/njs/examples.html#subrequest
Vagrant.configure("2") do |config|
config.vm.box = "ol76"
config.vm.network "forwarded_port", guest: 80, host: 8111, host_ip: "127.0.0.1"
config.vm.synced_folder ".", "/vagrant_data"
config.vm.provision "shell", inline: <<-SHELL
sudo cat > /etc/yum.repos.d/nginx.repo <<EOF
@tphummel
tphummel / lanes.js
Created Feb 13, 2019
compute total distance by lane of a running track
View lanes.js
let laneWidthMeters = 1.22
function getLanes({laneOneMeters, aRadMeters, bRadMeters, numLanes}) {
let turnMeters = 2 * Math.PI * aRadMeters
let straightMeters = laneOneMeters - turnMeters
let lanes = [
['#', 'distance (m)', 'turn (m)', 'straight (m)'],
]
lanes.push([
@tphummel
tphummel / README.md
Last active Oct 31, 2018
Eat Club Analytics
View README.md

Eat Club Analytics

  1. log in and browse: https://www.eatclub.com/orders/past
  2. scroll to the bottom of the page and keep clicking more until your entire history is shown on the page.
  3. open chrome web console (or comparable)
  4. open javascript console
  5. run the following command
copy(Array.prototype.slice.call(document.querySelectorAll("div.item-cont.row")).map((r)=>{ return Array.prototype.slice.call(r.querySelectorAll("div.column")).map((c)=>{ return c.innerText.split("\n") }) }).map((o)=>{ return {date: o[0][0], location: o[0][1], dish: o[1][0], type: o[2][0]} }))
@tphummel
tphummel / http-to-s3.js
Created Feb 25, 2018
pipe the content of a webpage to a file in s3
View http-to-s3.js
var http = require('http')
var path = require('path')
var AWS = require('aws-sdk')
function httpToS3 (event, context, callback) {
var s3 = new AWS.S3()
var now = (new Date()).toISOString()
http.request({
protocol: 'http:',
@tphummel
tphummel / sparse-streaks.md
Last active Jan 16, 2018
Find Streaks in Daily Data with Sparse/Missing Days
View sparse-streaks.md

install libraries

brew update
brew install tphummel/util/date-range
brew install tphummel/util/streak
brew install jq
brew install csvkit
You can’t perform that action at this time.