Skip to content

Instantly share code, notes, and snippets.

@taylorza
taylorza / GO-Fillslice.md
Last active January 28, 2025 11:37
Golang - Fill slice/array with a pattern

Filling an array or slice with a repeated pattern

Looking for an efficient pure GO approach to copy repeating patterns into a slice, for a toy project, I ran a few tests and discovered a neat approach to significantly improve performance. For the toy project, I am using this to fill a background buffer with a specific RGB color pattern, so improving this performance significantly improved my acheivable framerate.

All the test were run with a buffer of 73437 bytes, allocated as follows

var bigSlice = make([]byte, 73437, 73437)

Fill the slice with the value 65 by looping through each element and setting the value

@taylorza
taylorza / router.go
Created March 14, 2019 02:10
Trie matching paths
package router
import "strings"
type trie struct {
root trieNode
}
func newTrie() *trie {
return &trie{
@taylorza
taylorza / urlrewriter.go
Last active October 10, 2018 04:25
Matches URL for a particular scheme and domain and replaces them with a new URL
package main
import (
"net/url"
"regexp"
"strings"
)
// URLRewriter rewrites URL
type URLRewriter struct {
@taylorza
taylorza / PCBIOS.ASM
Created June 10, 2018 17:37
Old PC BIOS Assembly Language Listing
TITLE (ROM BIOS FOR IBM PERSONAL COMPUTER)
.MODEL COMPACT
OPTION M510
;-------------------
;EQUATES
;-------------------
PORT_A EQU 60H ;8255 PORT A ADDR
PORT_B EQU 61H ;8255 PORT B ADDR
PORT_C EQU 62H ;8255 PORT C ADDR