Skip to content

Instantly share code, notes, and snippets.

:shipit:
codez

Blixt blixt

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
View useIO.ts
import { useEffect, useRef, useState } from "react"
interface IO<T> {
setters: ((value: T) => void)[]
update: (value: T) => void
value: T | undefined
}
const store: { [name: string]: IO<any> | undefined } = {}
@blixt
blixt / modifyresponse_test.go
Created Jan 9, 2019
Testing ModifyResponse with ReverseProxy and web sockets
View modifyresponse_test.go
package main
import (
"bufio"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
@blixt
blixt / transform-class.ts
Created Nov 22, 2018
Did you know TypeScript's type system is Turing complete?
View transform-class.ts
// Return a type with only the methods of T that return R.
type MethodsWithReturnType<T, R> = {
[P in keyof T]: T[P] extends () => infer RR ? (RR extends R ? P : never) : never
}[keyof T]
// Filter away all keys except methods that return void and
// return a new type with those methods returning booleans.
type VoidMethodsToBoolMethods<T> = { [P in MethodsWithReturnType<T, void>]: () => boolean }
// Our test input class:
@blixt
blixt / progress.py
Last active Jul 5, 2018
Simple progress indicator copy/paste function for Python scripts
View progress.py
# -*- coding: utf-8 -*-
import sys
_last_status = None
_last_status_permille = 0
def print_status(status=None, fraction=0):
global _last_status, _last_status_permille
permille = int(fraction * 1000)
if status != _last_status:
@blixt
blixt / docker-antics.bash
Last active Jun 11, 2018
Workaround for copying files in same directory in separate layers (without specifying individual files)
View docker-antics.bash
# First, outside the Dockerfile:
tar --exclude ./static-large --exclude-from=.dockerignore -czf non-large.tar.gz ./*
# Then, in the Dockerfile:
COPY static-large $WORKDIR_PATH/static-large/
ADD non-large.tar.gz $WORKDIR_PATH/
View gist:586b6f530410fd5e8775d468be80202c
Verifying my Blockstack ID is secured with the address 1B9f1ZMCJzGfG4yzy3gyshA87whqkQTRj https://explorer.blockstack.org/address/1B9f1ZMCJzGfG4yzy3gyshA87whqkQTRj
@blixt
blixt / shutdown.go
Last active Oct 30, 2017
Minimal code needed to implement graceful shutdown of HTTP server in Go 1.8 and up.
View shutdown.go
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
View gist:f9d4ee62da2bf57e5563a20dd27f3015
Verifying that "blixt.id" is my Blockstack ID. https://onename.com/blixt
@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"
You can’t perform that action at this time.