Skip to content

Instantly share code, notes, and snippets.

View shawnsmithdev's full-sized avatar

Shawn Smith shawnsmithdev

  • Seattle Area
View GitHub Profile
@shawnsmithdev
shawnsmithdev / whereami.go
Created September 12, 2022 19:51
Where am i? What is going on?
package main
import "fmt"
import "runtime"
func main() {
fmt.Printf("OS: %s\n", runtime.GOOS)
fmt.Printf("Architecture: %s\n", runtime.GOARCH)
fmt.Printf("Go: %s\n", runtime.Version())
}

Keybase proof

I hereby claim:

  • I am shawnsmithdev on github.
  • I am shawnsmithdev (https://keybase.io/shawnsmithdev) on keybase.
  • I have a public key ASAcfXEnovS0YyBoAZGfsXsWBX5IV2V6M6Flv6kL2ejiHwo

To claim this, I am signing this object:

@shawnsmithdev
shawnsmithdev / qrsqrt.go
Created January 1, 2021 00:46
Go port of Quake III Fast Approx Inverse Square Root algorithm
// This is the Quake III Q_rsqrt Fast Approx Inverse Square Root algorithm
package main
import (
"fmt"
"math"
)
const threehalfs float32 = 1.5
@shawnsmithdev
shawnsmithdev / base85.go
Last active July 16, 2020 03:26
Base85 encoding
package main
import (
"encoding/binary"
"fmt"
)
var (
bases = []uint32{1, 85, 85 * 85, 85 * 85 * 85, 85 * 85 * 85 * 85}
)
@shawnsmithdev
shawnsmithdev / flac_md5.go
Created January 20, 2019 23:44
Extract the MD5 field from a FLAC file
package main
import (
"encoding/binary"
"encoding/hex"
"log"
"os"
)
const (
@shawnsmithdev
shawnsmithdev / slices.rs
Created August 10, 2017 05:18
Rust slices
// https://stackoverflow.com/questions/28219231/how-to-idiomatically-copy-a-slice
fn copy_slice<T: Copy>(src: &[T], dst: &mut [T]) -> usize {
let mut c = 0;
for (d, s) in dst.iter_mut().zip(src.iter()) {
*d = *s;
c += 1;
}
c
}
@shawnsmithdev
shawnsmithdev / sha256sum.go
Last active July 16, 2017 09:11
sha256 CLI tool
package main
import (
"crypto/sha256"
"fmt"
"hash"
"io/ioutil"
"os"
)
@shawnsmithdev
shawnsmithdev / head.go
Last active July 16, 2017 06:59
CLI tool that prints the HTTP HEAD response for an url
package main
import (
"fmt"
"net/http"
"net/http/httputil"
"os"
)
const defaultUrl = "https://example.com"
@shawnsmithdev
shawnsmithdev / y.go
Created May 28, 2016 06:33
A Y Combinator in go
package main
import (
"fmt"
)
// A Y Combinator (Only for func(int) int, so not *the* y combinator)
func Y(f func(func(int) int) func(int) int) func(int) int {
return f(func(x int) int {
return Y(f)(x)
@shawnsmithdev
shawnsmithdev / simpsons.go
Created May 24, 2016 20:00
Numerical Integration
package main
import (
"fmt"
"math"
)
// Simpson's Rule for numerical integration of f from a to b using n steps
// Port of python code: http://stackoverflow.com/questions/16001157/simpsons-rule-in-python
func simpsons(f func(float64) float64, a, b float64, n int) float64 {