Skip to content

Instantly share code, notes, and snippets.

View ianfoo's full-sized avatar
💭
staring into the sun ☀️

Ian Molee ianfoo

💭
staring into the sun ☀️
  • Seattle WA
View GitHub Profile
@ianfoo
ianfoo / parallel.go
Created October 9, 2018 03:31
Run tasks in parallel with timeout
package main
import (
"context"
"fmt"
"log"
"math/rand"
"time"
)
@ianfoo
ianfoo / linelength.go
Created October 12, 2018 03:16
Bounded parallel execution example
package main
import (
"bufio"
"context"
"encoding/json"
"flag"
"io"
"log"
"os"
@ianfoo
ianfoo / godoc.func.sh
Created October 16, 2018 22:45
Start a godoc server in the "background."
godoc-server () {
declare -lr funcname=$0
declare -lr godoc=$(which godoc)
start_server () {
declare -lr nohup=$(which gnohup || which nohup)
declare -lr logfile="/tmp/godoc-server.log"
$nohup $godoc $@ >$logfile 2>&1 &
}
stop_server() {
pkill -fn 'godoc -http'
@ianfoo
ianfoo / retry.go
Created November 5, 2018 22:44
Truncated exponential backoff function example
package main
import (
crand "crypto/rand"
"errors"
"flag"
"fmt"
"math"
"math/big"
"math/rand"
@ianfoo
ianfoo / condition.go
Created November 16, 2018 00:31
How to use Go's sync.Condition
// How to use sync.Condition
// https://play.golang.org/p/IdIkQ6S5ZlV
package main
import (
"fmt"
"sync"
"time"
)
@ianfoo
ianfoo / gist:fc7e37b837de883159a258581785e71f
Created December 10, 2018 23:50
Gomock matcher for a set of arguments
package matchers
import (
"fmt"
"reflect"
)
// SetMatcher matches values from a set of options. When an option is matched,
// it is removed from the set of acceptable options and will not be matched
// again on following calls to Match. This matcher can be useful when a number
Accounting
Airlines/Aviation
Alternative Dispute Resolution
Alternative Medicine
Animation
Apparel & Fashion
Architecture & Planning
Arts and Crafts
Automotive
Aviation & Aerospace
@ianfoo
ianfoo / volume-mount.log
Created March 5, 2019 22:19
Example of volume mounting in Docker
[ian@ianbook docker] $ cat > Dockerfile
FROM alpine:latest
CMD cat /mounted-file.txt
[ian@ianbook docker] $ docker build -t voltest .
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM alpine:latest
---> caf27325b298
Step 2/2 : CMD cat /mounted-file.txt
---> Running in b0d00cf05b6f
Removing intermediate container b0d00cf05b6f
#!/usr/bin/env python3
def can_combine_for_a0(stock):
"""Determine if different sized sheets of paper can combine to an A0 sheet.
Given a tuple of A-format paper sizes (A0, A1, A2...), with each entry
representing the number of sheets for a given size (i.e., element 0 is
number of A0, element 1 is number of A1, etc), determine whether the
collection of sheets can be pieced together to produce at least one
@ianfoo
ianfoo / code_review.md
Created April 30, 2019 23:45
Thoughts on code review

I have finished the review. I review kind of more like a linter than looking for higher-level problems, which is inefficient, but it's just so natural for me. I think that my suggestions would lead to higher quality code which is more pleasant to work with, a factor that ought not to be dismissed. But because of this I spend a lot of time reviewing code, looking closely at it. I think most people probably don't spend enough time reviewing code: if it took someone a day or a week to write, what makes anyone think that looking at it for a half hour is adequate?

I think this is where a technique like XP pays dividends--not that I've ever actually done it--with its test-first mentality and pair programming. It's a review in real time. There's a temptation to say that you're getting one person's worth of productivity out of two people, but this is a lie. The production of a paired team will generally be much higher quality than the production of an individual, leading to fewer bugs released into the wild and lowe