Skip to content

Instantly share code, notes, and snippets.

View josharian's full-sized avatar

Josh Bleecher Snyder josharian

View GitHub Profile
func checksumNoFoldTwoAccum(b []byte, initial uint64) uint64 {
ac := initial
var bc, bcarr uint64
var carry uint64
for len(b) >= 128 {
// add in chunks of eight up to 128
ac, carry = bits.Add64(ac, binary.BigEndian.Uint64(b[:8]), carry)
bc, bcarr = bits.Add64(bc, binary.BigEndian.Uint64(b[8:16]), bcarr)
ac, carry = bits.Add64(ac, binary.BigEndian.Uint64(b[16:24]), carry)
bc, bcarr = bits.Add64(bc, binary.BigEndian.Uint64(b[24:32]), bcarr)
func checksumNoFoldBy8s(b []byte, initial uint64) uint64 {
ac := initial
var carry uint64
for len(b) >= 128 {
// add in chunks of eight up to 128
ac, carry = bits.Add64(ac, binary.BigEndian.Uint64(b[:8]), carry)
ac, carry = bits.Add64(ac, binary.BigEndian.Uint64(b[8:16]), carry)
ac, carry = bits.Add64(ac, binary.BigEndian.Uint64(b[16:24]), carry)
ac, carry = bits.Add64(ac, binary.BigEndian.Uint64(b[24:32]), carry)
// ...
// Start Tailscale.
tssrv := &tsnet.Server{
// Silence logs completely.
// They're really verbose, and we don't have anywhere good to put them.
// This will leave us blind if/when we have Tailscale-specific issues,
// but in that case, we'll restore the logs temporarily to debug.
Logf: func(string, ...any) {},
Store: &tsDBStateStore{Q: srv.DB.Q},
AuthKey: os.Getenv("TS_AUTHKEY"),
@josharian
josharian / x.go
Created January 6, 2023 17:52
slow to compile with -race
package p
type T struct {
F float64
}
var A = [100000]*T{
2: TAKMS,
6: TAKGD,
7: TAKMS,
as a theme hint, could squeeze TRAFFIC into the fill, with all its letters circled, for "traffic circle"
diff --git a/device/device.go b/device/device.go
index 5644c8a..db017b6 100644
--- a/device/device.go
+++ b/device/device.go
@@ -44,6 +44,7 @@ type Device struct {
netlinkCancel *rwcancel.RWCancel
port uint16 // listening port
fwmark uint32 // mark value (0 = disabled)
+ brokenRoaming AtomicBool
}
package main
import (
"log"
"os"
"strings"
"github.com/goccy/go-graphviz"
"github.com/goccy/go-graphviz/cgraph"
"github.com/tailscale/hujson"
@josharian
josharian / md5block.go
Created November 3, 2021 23:52
rewrite of generic md5 go code to be friendlier to the register allocator
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Code generated by go run gen.go -output md5block.go; DO NOT EDIT.
package md5
import (
// "encoding/binary"
@josharian
josharian / iossize.go
Last active February 19, 2023 14:21
calculate dirty data pages for macho binary
// Command iossize predicts the impact
// on memory usage of changes to the binary.
//
// This implementation uses dyldinfo to determine
// exactly how much memory the dynamic linker will dirty
// as part of launching the executable.
//
// It is not perfect. There are multiple sources of dirty pages:
//
// 1. dynamic loader rebase/relocs due to our code
@josharian
josharian / lldb_out.txt
Created April 13, 2021 16:20
v8 lldb output
(lldb) bt
* thread #14, stop reason = EXC_BAD_ACCESS (code=2, address=0x70000228b000)
* frame #0: 0x0000000004b88761 bug.report.test`Builtins_CallVarargs + 97
frame #1: 0x0000000004b8fb81 bug.report.test`Builtins_InterpreterEntryTrampoline + 225
frame #2: 0x000007740009a3e2
frame #3: 0x0000000004b8fb81 bug.report.test`Builtins_InterpreterEntryTrampoline + 225
frame #4: 0x0000000004b8fb81 bug.report.test`Builtins_InterpreterEntryTrampoline + 225
frame #5: 0x0000000004b8fb81 bug.report.test`Builtins_InterpreterEntryTrampoline + 225
frame #6: 0x0000000004b8fb81 bug.report.test`Builtins_InterpreterEntryTrampoline + 225
frame #7: 0x0000000004b8fb81 bug.report.test`Builtins_InterpreterEntryTrampoline + 225