Skip to content

Instantly share code, notes, and snippets.

:shipit:
codez

Blixt blixt

:shipit:
codez
Block or report user

Report or block blixt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@blixt
blixt / middleware.go
Created May 5, 2017
A couple of middleware http.Handler functions for Go
View middleware.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)
View yarnlock.diff
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 Jan 16, 2017
Inconsistent yarn upgrade
View attempt1.diff
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 Sep 14, 2019
Logger middleware for Go HTTP servers which logs every request with response status code in the Apache format.
View logger_middleware.go
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
"time"
)
View Promise-Problem.swift
@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 Apr 25, 2016
Non-blocking reader for Go. Probably a bad idea.
View nonblocking.go
package nonblocking
import (
"io"
"time"
)
type NonBlockingReader struct {
ch chan []byte
rd io.Reader
@blixt
blixt / multipart.go
Created Apr 24, 2016
The multipart reader hangs instead of returning the available parts.
View multipart.go
package main
import (
"fmt"
"io"
"math"
"math/rand"
"mime/multipart"
"time"
)
@blixt
blixt / LocalizeLists.swift
Created Apr 7, 2016
Localized lists in Swift
View LocalizeLists.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 {
@blixt
blixt / Segfault.swift
Last active Feb 2, 2016
Swift segfaulting
View Segfault.swift
struct Participant {
let identifiers: [(label: String?, value: String)]
}
// This segfaults. Combining the two maps or changing "" to nil works.
let participants = ["a", "b", "c"]
.map { ("", $0) }
.map { Participant(identifiers: [$0]) }
// Update: Here's an error from a later build of Swift which explains the error.
@blixt
blixt / flatMap.swift
Last active Dec 16, 2015
Using flatMap to convert a list of mixed nils and values into a list of non-optional values
View flatMap.swift
let numbers = [
"one",
"2",
"0x3",
"42",
]
// This will run the function on all values and only keep the ones that are not nil:
let parsedNumbers = numbers.flatMap { Int($0, radix: 10) }
// [2, 42]
You can’t perform that action at this time.