Skip to content

Instantly share code, notes, and snippets.

@piersy
piersy / even_test.go
Created October 23, 2023 08:11
Performance of modulo or bit operation in golang for checking even?
func BenchmarkCheckEven(b *testing.B) {
nums := make([]uint64, 10000)
for i := 0; i < len(nums); i++ {
bytes := make([]byte, 8)
_, err := rand.Read(bytes)
require.NoError(b, err)
val := binary.BigEndian.Uint64(bytes)
nums[i] = val
}
@piersy
piersy / setup.sh
Last active March 27, 2020 15:56
Setup dev machine
# need to generate a key for github at this point and add it to github. or do that before.
# ssh-keygen -o -a 100 -t ed25519
sudo apt update
sudo apt install git build-essentials zsh curl
# Install fd
mkdir -p bin
cd Download
wget https://github.com/sharkdp/fd/releases/download/v7.4.0/fd_7.4.0_amd64.deb
@piersy
piersy / main.go
Created July 16, 2019 17:23
Check if a tcp connection can connect back to the same host via it's public IP (hint, it can!)
package main
import (
"context"
"fmt"
"net"
"time"
)
func main() {
@piersy
piersy / set_brightness.sh
Created September 14, 2018 10:18
Easily set brightness of connected monitors via xrandr
#!/bin/bash
# Match 0.x-1
REGEX='^0.+([0-9]+)+$|1'
SCRIPT_NAME=`basename "$0"`
if ! [[ $1 =~ $REGEX ]] ; then
echo "Usage: ${0##*/} <brightness_value_0.x_to_1>" >&2; exit 1
fi
@piersy
piersy / .fonts.conf
Last active July 5, 2018 14:20
Smooth nice looking fonts in debian stretch - place at ~/.fonts.conf
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="font">
<edit mode="assign" name="rgba">
<const>rgb</const>
</edit>
</match>
<!--
Hinting makes terminal fonts look pretty shitty but makes browser fonts
@piersy
piersy / .zshrc
Last active October 28, 2019 20:01
Automatic gopath selection, and godoc web server execution with zshell
# List Custom gopaths
gopaths=('/home/piers/projects/ethdenver' '/home/piers/projects/test_gopath')
# Always available gopath
fallback_gopath=$HOME/go
# Used to detect when the gopath changes
previous_gopath=''
#setgopath sets the gopath based on the current working dierectory. If the
#current working dierectory is a gopath or a subdirectory of a gopath then
@piersy
piersy / rand_distribution.go
Last active February 21, 2018 10:45
Test evenness of random distribution (are all values from 0 to n equally likely) of golang rand.Intn() - (Result rand.Intn(n) does provide an even distribution)
package main
import (
"fmt"
"math/rand"
)
const (
ChunkSize = (1 << 16)
NumValues = 100
@piersy
piersy / recolor_pdf_text.sh
Created February 13, 2018 16:36
Re-colors text of pdf files that contain no color information. In it's current configuration it will turn text from black to grey. (requires pdftk)
pdftk $1 output - uncompress | perl -p -e 's/BT$/BT\n0.3 0.3 0.3 rg/' | pdftk - output - compress > $1
@piersy
piersy / main.go
Created February 9, 2018 11:56
Marshal JSON in Golang using lower-camel-case object key conventions
package main
import (
"encoding/json"
"fmt"
"regexp"
"time"
"unicode"
"unicode/utf8"
)
@piersy
piersy / bumpme
Last active August 2, 2017 20:03
Wed Aug 2 20:03:40 UTC 2017