Skip to content

Instantly share code, notes, and snippets.

module Main (main) where
minOrZero lst = if null lst then 0 else minimum lst
coins 0 _ = 0
coins v ds = (1 + minOrZero [coins (v - d) ds | d <- ds, (v - d) >= 0])
main = do print "start"
print (coins 57 [1, 5, 10, 25])
print (coins 15 [1, 6, 9, 10])
module Main (main) where
col :: Int -> [Int] -> [Int]
col 1 acc = acc
col n acc | n `mod` 2 == 0 = col (n `div` 2) (n:acc)
| otherwise = col (3 * n + 1) (n:acc)
opts :: Int -> [(Int, Int)]
opts n = [(length(col x []), x) | x <- [1..n]]
@lethain
lethain / refactor.rb
Created January 29, 2018 14:59
Example of refactoring Ruby into better Ruby.
# using ruby_parser from https://github.com/seattlerb/ruby_parser
# also ruby2ruby for convert sexps to ruby code: sudo gem install ruby2ruby
require 'ruby_parser'
require 'ruby2ruby'
def load
txt = ''
while line = gets
txt += line
end
@lethain
lethain / gist:e29eb62c44795ccbb6a9767a3d13068d
Last active June 30, 2019 15:27
Headcount by year for some internet companies
# Caveat that picking "year one" is kind of arbitrary, and that these
# are just random numbers from the internet, not meant as canonical sources
Year Google Facebook Twitter Uber
1 11 7 8
2 60 15 29
3 284 150 130 60
4 682 450 350 170
5 1628 850 833 1000
6 3021 1218 2712
@lethain
lethain / gist:851a7ac92643681d254684448fc3905c
Last active January 25, 2020 17:59
CFP for "Migrations: the only scalable approach to technical debt"

Description

Migrations are both essential and frustratingly frequent as your codebase ages and your business grows: most tools and processes only support about one order of magnitude of growth before becoming ineffective, so rapid growth makes them a way of life.

Two of Stripe’s most important migrations have been typing our Ruby codebase and migrating our metrics and dashboard stack. This talk will explore why migrations are the only mechanism to effectively manage technical debt as your company and code grows, what makes running them so hard, and a repeatable approach to running them effectively:

@lethain
lethain / lc.markdown
Last active January 26, 2020 18:16
CFP submission for "Service Mesh in Kubernetes: it’s not that easy"

Successful CFP submission by Lita Cho, included in this list

Service Mesh in Kubernetes: it’s not that easy

KubeCon 2019

In this talk, presenters will share lessons from several years of experience running Envoy in production at scale. They will explore practical techniques for triaging issues in a service mesh, along with the intuition behind them. The presenters will cover a broad range of topics including traffic capture, issues specific to GRPC, health checks, and techniques useful during incident mitigation. The talk will end with a deep dive into Envoy stats and their use in resolving issues.

Envoy 2019

@lethain
lethain / gist:be56483063be9d76f75aa0ab9401d938
Last active January 29, 2020 14:23
CFP for "How Stripe invests in infrastructure"

Short description

Learn how Stripe has evolved their approach to prioritizing infrastructure as they grew from two founders to 1,300+ employees and millions of users.

Long description

Deciding what to work on is always difficult, and is especially treacherous for folks working as infrastructure engineers and leaders. Infrastructure teams that solve the right problems subtlety shift their company's trajectory upwards. Poor approaches lead toward a morass of