Skip to content

Instantly share code, notes, and snippets.

View as's full-sized avatar

as

View GitHub Profile
@as
as / hello.go
Created August 19, 2018 08:58
hello world in go...ast
package main
import (
. "go/ast"
"go/format"
"go/token"
"os"
)
func main() {
package main
import (
"fmt"
)
func main() {
ε := 0.1
if ε == -1+ε+1 {
panic("ε")
@as
as / mean.txt
Created November 2, 2018 00:57
Don't Re-add the Elements: The Arithmetic Mean in a Running Average Should Be Efficient
Don't Re-add all the Elements: The Arithmetic Mean in a Running Average Can Be Efficient
----------------------------------------------------------------------------------------
The arithmetic mean of a set is the sum of the set's elements, divided by the set's cardinality.
We observe this definition as a formula: A = 1/n * (a1 + a2 + ... + an), where n is the number of elements.
To demonstrate, we compute the arithmetic mean of the set (1, 2):
A(1, 2) = 1/2 * (1 + 2)
package main
import (
"fmt"
"math/bits"
"math/rand"
)
type spool struct {
*rand.Rand
@as
as / parse.go
Created January 9, 2019 09:59
ParseFlagsOrEnv
// ParseFlagsOrEnv: Order of priority (Flag, Env, Default)
func ParseFlagsOrEnv() {
flag.VisitAll(func(fl *flag.Flag) {
if env, set := os.LookupEnv(fl.Name); set {
fl.DefValue = env
flag.Set(fl.Name, env)
}
})
flag.Parse()
@as
as / bgcd.go
Last active January 25, 2019 12:55
binary greatest common divisor
package main
import (
"fmt"
"math/bits"
)
func main() {
fmt.Println(bgcd(6, 36))
fmt.Println(bgcd(2, 36))
package main
import (
"fmt"
"math/rand"
)
func main() {
t := 0
i := 0
Christian [03/12/2019 13:31]
I think I see what they’re alluding to though
A “stream” would be the octets corresponding to one single HTTP/2 message
And there can be multiple streams over the same connection
All interwoven and beautiful af
as [03/12/2019 13:32]
it's not a message, it's a connectionette
@as
as / cancel.go
Created March 16, 2019 21:08
Cancellation Done Right
// TODO(as): find a production foss program where this issue exists
//
// This trivial program generates integers and prints them to
// standard output until it reaches 1000 or the context is done.
//
// It contains a fix for a difficult-to-find bug caused in many
// Go programs written by authors at all experience levels.
package main
import (
@as
as / noface.sh
Created September 6, 2019 18:56
block facebook, instagram, et. al,
# as 2019.09.06
# generate a list of iptables commands to block
# all ip addresses assigned to facebook via the
# organization's autonomous system number.
whois -h whois.radb.net '!gAS32934' | egrep / | tr ' ' '\n' | awk '{ printf "iptables -I OUTPUT -d %s -j REJECT\n",$1 }'