Skip to content

Instantly share code, notes, and snippets.

View blixt's full-sized avatar

Blixt blixt

View GitHub Profile
@blixt
blixt / shutdown.go
Last active October 30, 2017 19:28
Minimal code needed to implement graceful shutdown of HTTP server in Go 1.8 and up.
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
Verifying that "blixt.id" is my Blockstack ID. https://onename.com/blixt
@blixt
blixt / middleware.go
Created May 5, 2017 16:36
A couple of middleware http.Handler functions for Go
// A couple of middleware http.Handler functions (scroll down).
// EXAMPLE USAGE:
http.HandleFunc("/", RequestHome)
http.Handle("/s/", Cacher(168*time.Hour, http.StripPrefix("/s/", http.FileServer(http.Dir("static")))))
http.Handle("/favicon.ico", FileWithCache("static/favicon.ico", 168*time.Hour))
if err := http.ListenAndServe(":8080", Logger(http.DefaultServeMux)); err != nil {
log.Fatalf("http.ListenAndServe: %v", err)
diff --git a/yarn.lock b/yarn.lock
index 2e5918c..b54dd76 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -39,42 +39,18 @@ asn1@0.1.11:
version "0.1.11"
resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.1.11.tgz#559be18376d08a4ec4dbe80877d27818639b2df7"
-asn1@~0.2.3:
- version "0.2.3"
@blixt
blixt / attempt1.diff
Created January 16, 2017 16:04
Inconsistent yarn upgrade
diff --git a/yarn.lock b/yarn.lock
index 4ad8aa0..86e8f3a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -39,42 +39,18 @@ asn1@0.1.11:
version "0.1.11"
resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.1.11.tgz#559be18376d08a4ec4dbe80877d27818639b2df7"
-asn1@~0.2.3:
- version "0.2.3"
@blixt
blixt / logger_middleware.go
Last active April 2, 2024 18:52
Logger middleware for Go HTTP servers which logs every request with response status code in the Apache format.
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
"time"
)
@discardableResult
public func then<U>(_ onFulfilled: @escaping (T) throws -> U) -> Promise<U> {
return self.thenImpl(onFulfilled, { throw $0 })
}
@discardableResult
public func then<U>(_ onFulfilled: @escaping (T) throws -> U, _ onRejected: @escaping (Error) throws -> U) -> Promise<U> {
return self.thenImpl(onFulfilled, onRejected)
}
@discardableResult
@blixt
blixt / nonblocking.go
Last active April 25, 2016 03:58
Non-blocking reader for Go. Probably a bad idea.
package nonblocking
import (
"io"
"time"
)
type NonBlockingReader struct {
ch chan []byte
rd io.Reader
@blixt
blixt / multipart.go
Created April 24, 2016 03:49
The multipart reader hangs instead of returning the available parts.
package main
import (
"fmt"
"io"
"math"
"math/rand"
"mime/multipart"
"time"
)
@blixt
blixt / LocalizeLists.swift
Created April 7, 2016 22:40
Localized lists in Swift
extension SequenceType where Generator.Element == String {
func localizedJoin() -> String {
var g = self.generate()
guard let first = g.next() else {
return ""
}
guard let second = g.next() else {
return first
}
guard var last = g.next() else {