Skip to content

Instantly share code, notes, and snippets.

👾
Life is just metadata in aggregate

Beth Anderson betandr

👾
Life is just metadata in aggregate
Block or report user

Report or block betandr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@betandr
betandr / sort.go
Created Mar 1, 2019
sort.Interface sort by title, artist
View sort.go
type byTitleArtist []*Track
func (t byTitleArtist) Len() int { return len(t) }
func (t byTitleArtist) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t byTitleArtist) Less(i, j int) bool {
if toL(t[i].Title) < toL(t[j].Title) {
return true
}
if toL(t[i].Title) > toL(t[j].Title) {
return false
@betandr
betandr / tracks.go
Created Feb 27, 2019
A Go tracks slice containing Go tracks.
View tracks.go
var tracks = []*Track{
{Title: "Ready To Go", Artist: "Republica", Album: "Republica", Year: 1996, Length: length("5m01s")},
{Title: "Go", Artist: "Lizzo", Album: "Lizzobangers", Year: 2014, Length: length("3m45s")},
{Title: "Go Get It", Artist: "Slowdive", Album: "Slowdive", Year: 2017, Length: length("6m09s")},
{Title: "You Gotta Go!", Artist: "The Mighty Mighty Bosstones", Album: "A Jackknife to a Swan", Year: 2002, Length: length("2m43s")},
{Title: "Go Out", Artist: "Blur", Album: "The Magic Whip", Year: 2015, Length: length("4m41s")},
{Title: "Just Let Go", Artist: "Fischerspooner", Album: "Odyssey", Year: 2005, Length: length("4m15s")},
{Title: "Go It Alone", Artist: "Beck", Album: "Guero", Year: 2005, Length: length("4m09s")},
{Title: "I Let Go", Artist: "Eighteen Visions", Album: "Obsession", Year: 2004, Length: length("3m23s")},
@betandr
betandr / grab.sh
Created Feb 27, 2019
Generate curl requests containing floats
View grab.sh
#!/bin/bash
count=1.414
limit=1000
while : ;
do
out=$(bc -l<<< "$count<$limit")
[[ $out == 0 ]] && { echo "done" ; exit 0; }
printf -v index "%020d" ${count//./}
@betandr
betandr / git-filter-branch.sh
Last active Mar 7, 2019
Fix commits by incorrect username/email
View git-filter-branch.sh
#!/bin/sh
# USE:
# git update-ref -d refs/original/refs/heads/master
# ...or:
# git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
# If you see:
# Cannot create a new backup.
# A previous backup already exists in refs/original/
# Force overwriting the backup with -f
@betandr
betandr / junk.go
Created Feb 25, 2019
A custom command line flag `-junk`
View junk.go
package junk
import (
"flag"
"fmt"
"strconv"
)
type Junk int64
@betandr
betandr / main.go
Created Feb 14, 2019
Writer helper to handle errors
View main.go
package main
import (
"fmt"
"io"
"os"
)
func main() {
@betandr
betandr / main.go
Last active Feb 8, 2019
Split a 1D slice into 2D slice (triples)
View main.go
package main
import "fmt"
func main() {
s := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
fmt.Println(split(s, 3))
}
func split(s []int, width int) [][]int {
View bitvec.go
// bitvec is a bit vector (also known as bit array, bit map, bit set, or bit string) compactly stores bits.
// It can be used to implement a simple set data structure. A bit array is effective at exploiting bit-level
// parallelism in hardware to perform operations quickly. A typical bit array stores kw bits, where w is the
// number of bits in the unit of storage, such as a byte or word, and k is some nonnegative integer. If w
// does not divide the number of bits to be stored, some space is wasted due to internal fragmentation.
package bitvec
import (
"fmt"
"strings"
@betandr
betandr / pointer_vs_named_receivers.go
Last active Feb 5, 2019
Pointer vs Named Receivers
View pointer_vs_named_receivers.go
package main
import "fmt"
type SomeThing struct {
Msg string
}
func (t SomeThing) SomeNamedReciever(msg string) {
t.Msg = msg
@betandr
betandr / main.go
Last active Feb 5, 2019
Unnamed Struct Type Method
View main.go
package main
import (
"fmt"
"sync"
)
var cache = struct {
sync.Mutex // Mutex is embedded so its methods are promoted to the unnamed struct type
mapping map[string]string
You can’t perform that action at this time.