Skip to content

Instantly share code, notes, and snippets.

View montanaflynn's full-sized avatar

Montana Flynn montanaflynn

View GitHub Profile
@montanaflynn
montanaflynn / github.css
Last active May 28, 2020 07:12 — forked from tuzz/github.css
Github Markdown Stylesheet
/*
Copyright (c) 2017 Chris Patuzzo
https://twitter.com/chrispatuzzo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@montanaflynn
montanaflynn / main.go
Last active October 19, 2023 23:54
Example of using Golang errgroup with context.WithTimeout()
package main
import (
"context"
"fmt"
"io"
"log"
"net/http"
"os"
"time"
@montanaflynn
montanaflynn / canadian-covid-19-choropleth-map.markdown
Created March 18, 2020 17:47
Canadian Covid 19 Choropleth Map
@montanaflynn
montanaflynn / callback-or-promise.js
Created January 3, 2020 14:53
Example of providing error-first callback mechanism by default but also a chained .promise() method
// Example from https://nickmeldrum.com/blog/intriguing-reason-node-not-promises-by-default
const doS3GetObject = params => {
if (someErrorHappens) {
throw new Error('uh oh, we borked')
}
else {
return 'we done good' // imagine we actually did the work!
}
}
@montanaflynn
montanaflynn / main.go
Created December 29, 2019 17:34
Example of using Golang Chi router with a shared redis dependency
package main
import (
"log"
"net/http"
"github.com/go-chi/chi"
"github.com/go-redis/redis"
)
package main
import (
"fmt"
)
func CopyChange(a int) {
a = 10
}
@montanaflynn
montanaflynn / main.go
Created April 7, 2019 10:23
Golang graceful restart with gin framework but pattern works for any http.Server
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"time"
@montanaflynn
montanaflynn / main.go
Last active October 19, 2023 15:27
Gin request timeout middleware and handler
package main
import (
"context"
"log"
"net/http"
"time"
"github.com/gin-gonic/gin"
)
@montanaflynn
montanaflynn / timer.go
Created April 5, 2019 11:21
A simple timer to use for logging time between actions
package timer
import (
"log"
"os"
"time"
)
type TimeLogger interface {
Printf(format string, v ...interface{})
@montanaflynn
montanaflynn / ml.go
Created January 16, 2019 09:33
Simple neural net with one hidden layer consisting of one neuron
// Found at https://play.golang.org/p/sR0vNRAQD1
// Inspired by https://medium.com/technology-invention-and-more/how-to-build-a-simple-neural-network-in-9-lines-of-python-code-cc8f23647ca1
package main
import (
"fmt"
"math/rand"
"math"
)