Skip to content

Instantly share code, notes, and snippets.

View betandr's full-sized avatar
🦄
Vague, but exciting...

Beth Anderson betandr

🦄
Vague, but exciting...
View GitHub Profile
@betandr
betandr / grab.sh
Created February 27, 2019 11:27
Generate curl requests containing floats
#!/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 March 7, 2019 10:34
Fix commits by incorrect username/email
#!/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 February 25, 2019 13:15
A custom command line flag `-junk`
package junk
import (
"flag"
"fmt"
"strconv"
)
type Junk int64
@betandr
betandr / main.go
Created February 14, 2019 14:28
Writer helper to handle errors
package main
import (
"fmt"
"io"
"os"
)
func main() {
@betandr
betandr / main.go
Last active February 8, 2019 17:45
Split a 1D slice into 2D slice (triples)
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 {
@betandr
betandr / bitvec.go
Created February 5, 2019 17:03
Go Bit Vector
// 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 February 5, 2019 17:03
Pointer vs Named Receivers
package main
import "fmt"
type SomeThing struct {
Msg string
}
func (t SomeThing) SomeNamedReciever(msg string) {
t.Msg = msg
@betandr
betandr / main.go
Last active February 5, 2019 17:04
Unnamed Struct Type Method
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
@betandr
betandr / sum_int_ll.go
Last active February 5, 2019 17:04
Summing Integer Linked List
package main
import "fmt"
type IntList struct {
Value int
Next *IntList
}
// A nil `IntList` represents the empty list
@betandr
betandr / pointer_receivers.go
Last active February 5, 2019 17:04
Pointer Receivers
package main
import (
"fmt"
"math"
)
type Point struct {
X, Y float64
}