Skip to content

Instantly share code, notes, and snippets.

@quillaja
quillaja / arena.go
Created March 31, 2021 06:18
go memory arena
package arena
// #include <malloc.h>
import "C"
import (
"runtime"
"unsafe"
)
// Arena memory allocator gets a large chunk of memory from the system at once
@quillaja
quillaja / bresenham.go
Last active January 26, 2020 05:51
Go version of Bresenham's line algorithm.
// plotline draws a simple line on img from (x0,y0) to (x1,y1).
//
// This is basically a copy of a version of Bresenham's line algorithm
// from https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm.
func plotline(img draw.Image, c color.Color, x0, y0, x1, y1 int) {
dx := abs(x1 - x0)
sx := -1
if x0 < x1 {
sx = 1
}
@quillaja
quillaja / servehere.go
Created July 10, 2018 14:35
Very simple http fileserver for serving locally while testing web apps, etc.
// Package main implements a simple http file server mainly for use in
// serving files locally when testing web apps.
package main
import (
"flag"
"log"
"net/http"
)
@quillaja
quillaja / pcg.go
Created June 24, 2018 09:26
PCG psudo random number generator (minimal)
// port of C source: http://www.pcg-random.org/download.html
type PCG32 struct {
state, seq uint64
}
func NewPCG32(stateSeed, seq uint64) *PCG32 {
return &PCG32{
state: stateSeed,
inc: seq }
@quillaja
quillaja / xraydl.fish
Last active December 7, 2020 01:24
fish shell script to download archived xray.fm shows
#! /usr/bin/fish
#==============
# This is a fish shell script to download archived mp3 files of shows
# from the radio station XRAY (krxy).
#==============
# get show numbers given show title (in url style)
# curl -s https://xray.fm/shows/home-of-space-paranoid | grep -Poe '(?<=title"\>\<a href="\/broadcasts\/)\d*?(?=")'
cameraOrigin := pixel.ZV.Add(win.Bounds().Center())
scale := 1.0
dragOrigin := pixel.V(0, 0)
second := time.Tick(time.Second)
viewMatrix := pixel.IM
frames := 0
for !win.Closed() {
if win.MouseScroll().Y != 0 {
factor := math.Pow(1.2, win.MouseScroll().Y)
zoomDeltaStart := viewMatrix.Unproject(win.MousePosition())
@quillaja
quillaja / camera.go
Created February 16, 2018 07:27
Camera for Pixel graphics library
package main
import (
"math"
"github.com/faiface/pixel"
"github.com/faiface/pixel/pixelgl"
)
// An interal type to store 2 related numbers, a low and high bound.
@quillaja
quillaja / walker.go
Last active February 8, 2018 10:33
A little random walker experiment.
package main
import (
"flag"
"fmt"
"image"
"image/color"
"image/draw"
"image/jpeg"
"math/rand"
@quillaja
quillaja / base62.py
Created November 6, 2017 04:10
Sample creation of base64 strings not as hashes.
import random
import argparse
def get_key(length: int = 8) -> str:
b62_alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$+"
key = random.choices(b62_alphabet, k=length)
return ''.join(key)
@quillaja
quillaja / game_of_life.go
Last active October 18, 2017 00:40
Conway's game of life in go.
package main
import (
"flag"
"fmt"
"time"
)
// Board is a set of points that are 'alive'
type Board map[Point]bool