Skip to content

Instantly share code, notes, and snippets.

View jakecoffman's full-sized avatar
:dependabot:

Jake Coffman jakecoffman

:dependabot:
View GitHub Profile
@jakecoffman
jakecoffman / trickle.go
Created May 3, 2022 18:34
trickle server
package main
import (
"log"
"net/http"
"time"
)
func main() {
log.SetFlags(log.Lshortfile)
@jakecoffman
jakecoffman / authors.go
Last active December 3, 2021 14:43
Example author REST endpoint spec
crud.Spec{
Method: "PATCH",
Path: "/authors/{id}",
Summary: "Patch an author",
Tags: tags,
Handler: PatchAuthor,
Validate: crud.Validate{
Path: crud.Object(map[string]crud.Field{
"id": crud.Integer().Required(),
}),
@jakecoffman
jakecoffman / intigriti-1121.md
Last active November 22, 2021 11:51
Intigriti challenge 1121
@jakecoffman
jakecoffman / stress.groovy
Created May 18, 2020 13:20
codingame.com Spring Challenge 2020 stress tester
import com.codingame.gameengine.runner.MultiplayerGameRunner
import com.codingame.gameengine.runner.dto.GameResult
import groovy.time.TimeCategory
import groovyx.gpars.GParsPool
class Simulator {
static final champion = "config/champion.exe"
static final challenger = "config/challenger.exe"
static void main(String[] args) {
@jakecoffman
jakecoffman / method_bench.go
Created December 9, 2017 19:59
Go benchmark: concrete method call vs call through an interface
package bench
import "testing"
func Benchmark_InterfaceMethods(b *testing.B) {
s := &Struct{}
for n := 0; n < b.N; n++ {
s.Method()
}
@jakecoffman
jakecoffman / text.md
Last active July 5, 2017 18:55
node good bad ugly

Bad

  1. can't trace uncaught rejections back to the calling code
  2. dependency hell, immature dependencies, forks on forks
  3. inconsistent use of promises, e.g. mongoose you need to remember .exec and it doesn't throw but returns null
  4. debugging is rough, end up console logging most of the time
  5. promises are confusing, you can avoid them for a while with async/await or co but eventually they will bite you

Good

@jakecoffman
jakecoffman / tree.go
Last active June 20, 2016 22:40
simple binary tree implementation and printer for those pesky interview problems
package main
import (
"fmt"
"strings"
)
type BinaryTree struct {
Node int // or whatever
Left *BinaryTree
// Main
IElement element = getElement()
printer(element)
// Classes
IElement getElement() {
// simulate not knowing the type of element at runtime
if (new Random().nextInt() % 2 == 0) {
return new Element1(var1: "hello")
} else {
def randomElement
// simulate user input, for instance
if (new Random().nextInt() % 2 == 0) {
randomElement = new Element1()
} else {
randomElement = new Element2()
}
printer(randomElement)
@jakecoffman
jakecoffman / novisitor.groovy
Last active September 15, 2015 01:51
same as visitor.groovy without the confusing class explosion
def printer(Element1 element) {
println "${element.name} ${element.element1Specific}"
}
def printer(Element2 element) {
println "${element.name} ${element.element2Specific}"
}