Skip to content

Instantly share code, notes, and snippets.

Avatar

Patrick McKenzie patio11

View GitHub Profile
@patio11
patio11 / monte-carlo-that-perl.rb
Created Oct 28, 2019
monte carlo simulation for perl random line generator
View monte-carlo-that-perl.rb
NUMBER_OF_BUCKETS = 100
EXPECTED_BUCKET_SIZE = 100
file = "1-to-#{NUMBER_OF_BUCKETS}.txt"
f = File.open(file, "w")
contents = (1..NUMBER_OF_BUCKETS).to_a.map(&:to_s).join("\n")
f.write(contents)
f.close()
command = "cat #{file} | perl -e 'while(<>){$x=$_ if rand()<=(1/$.)}print $x'"
@patio11
patio11 / bitfinex-03152019.md
Created Apr 26, 2019
`shasum bitfinex-03152019.md` is 938d939059a23aa84ce493db0c4d542748f849a7
View bitfinex-03152019.md

Prediction as of 3/15/2019 JST:

  • Bitfinex is insolvent, for the Bitcoin economy's usual quixotic definition of insolvent.
  • This happened as a result of collateralizing Tether with BTC and other cryptocurrencies during the run-up.
  • Bitfinex / Tether treat whether Bitfinex held the collateral or Tether held the collateral as a material distinction, but that's ridiculous due to common control. The important fact: in 2018, ground truth diverged from "There is $1 in a bank account for every tether outstanding" to "There is $1 in a bank account and/or $1 worth of Bitcoin at prevailing prices available to Bitfinex for every tether outstanding."
  • This makes Tether synthetically long Bitcoin, via a receivable from Bitfinex. Bitfinex took the newly issued Tether and then, since this accounting shellgame appears to balance its books and leave it with surplus Bitcoin, either sold or lent the Bitcoin to short sellers during the run-up.
  • If Bitfinex simply sold the Bitcoin, they're doing relatively well for themselve
@patio11
patio11 / app_controllers_slack_controller.rb
Created Nov 26, 2015
Implementing a /healthcheck endpoint in Slack to read out consul status in a human-readable fashion
View app_controllers_slack_controller.rb
class SlackController < ApplicationController
skip_before_action :verify_authenticity_token
@@slack_security_tokens =
["copy-paste-the-token-you-get-from-Slack-when-configuring-the-integration-here"]
before_filter :bounce_access_not_from_slack
def healthcheck
services = SystemStatus.list_services
@patio11
patio11 / borked.html
Created Nov 23, 2015
Minimal repro case of stylesheets not loading on Firefox with wrong MIME specified
View borked.html
<!DOCTYPE html>
<html lang='en'>
<head>
<link rel="stylesheet" type="css/text" href="https://dwpnibhogf8y5.cloudfront.net/static/css/bootstrap.min-f04b517b.css" />
<body>
<div class="alert alert-danger">This text should be styled.</div>
</body>
</html>
@patio11
patio11 / samples.js
Last active Oct 30, 2015
Starfighter REST API request and response JSON samples
View samples.js
//JSON to POST to /venues/FOOEX/stocks/BAR/orders
{
“symbol”: “BAR”,
“venue”: “FOOEX”,
“direction”: “buy”,
“qty”: 20,
“price”: 5100,
“type”: “limit”,
“account” : “OGB12345”, // your trading account (game gives you this)
View untrusted-lvl13-solution.js
/*
* robotMaze.js
*
* The blue key is inside a labyrinth, and extracting
* it will not be easy.
*
* It's a good thing that you're a AI expert, or
* we would have to leave empty-handed.
*/
@patio11
patio11 / ansible-snippet.yaml
Created Jul 9, 2015
Create an account on every box using the list of employees; initialize with their Github SSH keys
View ansible-snippet.yaml
vars:
starfighters:
- username: patrick
github: patio11
name: "Patrick McKenzie"
- username: thomas
github: tqbf
name: "Thomas Ptacek"
- username: erin
github: boboTjones
@patio11
patio11 / react-flummox-reduce-boilerplate.js
Created Jun 26, 2015
Got tired of all the boilerplate with hooking up Stores/Actions so...
View react-flummox-reduce-boilerplate.js
// When I was working on our React/Flummox app I got to the point where, per the docs, I had ~100 lines of code
// which were substantially predictable boilerplate, so I used some JS metaprogramming to condense them by 80%.
// Flummox docs: http://acdlite.github.io/flummox
// I use underscore.js below for utility but you can also just do a for loop.
class AppFlux extends Flux {
constructor() {
@patio11
patio11 / example.go
Created Jun 22, 2015
An easy way to shoot yourself in the foot with go
View example.go
// The wrong way to do things:
for {
switch {
case <- channelA:
doSomething()
case <- channelB:
doSomethingElse()
default:
// Do nothing.
@patio11
patio11 / gist:fe0abc1c18d09149e6c9
Created Jun 17, 2015
Quick sample of Golang and Ruby for string manipulation
View gist:fe0abc1c18d09149e6c9
#The task is replacing the port number in the URL string
//in golang
import "fmt"
import "strings"
func main() {
url := "http://localhost:8080/foo/bar"
fmt.Println(strings.Replace(url, "8080", "8181", -1))
}
You can’t perform that action at this time.