Skip to content

Instantly share code, notes, and snippets.

@klauspost
klauspost / dictionary-sorted.txt
Last active August 25, 2024 23:18
Brotli dictionary - printed escaped
" </div>"
" })();\r\n"
" && "
" &amp; "
" &nbsp;"
" ''The "
" (&quot;"
" (199"
" (200"
" (e.g."
@klauspost
klauspost / hashtag.go
Created October 13, 2015 09:16
Hashtag identifier & splitter.
// Match tags in notes, etc.
// Group 1: Must start with whitespace OR start of string
// - : Must start with hash sign #
// Group 2: Match everything, until we reach a whitespace, '#' '.' ',' '!' ')'.
// Must be end of string
var matchTags = regexp.MustCompile(`[^\S]|^#([^\s#.,!)]+)$`)
// tagsSplitter returns true if the current rune is a tag ending
// Tags MUST end with whitespace, '.' ',' '!' or ')'
func tagsSplitter(c rune) bool {
@klauspost
klauspost / main.go
Last active August 10, 2023 07:49
Simple dict builder
package main
import (
"encoding/binary"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"

NG byte aligned compression

Intro

This is trying to combine the lessons learned from LZ4, Snappy, S2 and friends.

  • LZ4: Allow matches > 65536. More efficient long matches. More efficient short offsets.
  • Snappy: Improve the max match length. More efficient longer match offsets.
  • S2: More efficient repeat storage, relative offsets. Add 24 bits copy lengths.
package floats
import (
"fmt"
"math"
"math/bits"
"github.com/klauspost/compress/fse"
)
@klauspost
klauspost / rngbuffer.go
Created February 27, 2023 13:08
Buffered Intn.
type rngBuffer struct {
bitsLeft int
buffer [32]byte
}
// Intn returns, as an int, a non-negative random number in the half-open interval [0,n).
// It panics if n <= 0.
func (r *rngBuffer) Intn(n int) int {
if n <= 0 {
panic("invalid argument to Intn")
package main_test
import (
"crypto/sha1"
"math/rand"
"testing"
"github.com/zeebo/xxh3"
)
@klauspost
klauspost / main.go
Created October 20, 2022 14:38
css-reorder-experiment
package main
import (
"bytes"
"fmt"
"math"
"os"
"github.com/klauspost/compress/gzip"
"github.com/klauspost/compress/zstd"
//go:build ignore
// +build ignore
package main
// Adapted from : https://gist.github.com/arnehormann/65421048f56ac108f6b5
import (
"bufio"
"bytes"
//go:build amd64 && !appengine && !noasm && gc
// +build amd64,!appengine,!noasm,gc
// This file contains the specialisation of Decoder.Decompress4X
// that uses an asm implementation of its main loop.
package huff0
import (
"errors"
"fmt"