Skip to content

Instantly share code, notes, and snippets.

@harryscholes
harryscholes / terra_core_apple_silicon.sh
Created July 19, 2021 15:34
Install terra core on Apple Silicon
# On an Apple Silicon computer, install Rosetta 2 and the amd64 version of Go, then
arch -x86_64 make install
@harryscholes
harryscholes / length.rs
Last active June 8, 2021 20:37
Length traits in Rust
use std::ops::{Add, AddAssign, Mul};
#[derive(Debug)]
struct Millimeters<T>(T);
struct Centimeters<T>(Millimeters<T>);
struct Meters<T>(Millimeters<T>);
/// Length represents a length in millimeters
use std::{collections::HashMap, hash::Hash};
#[derive(Debug)]
struct Set<T> {
m: HashMap<T, ()>,
}
impl<T> Set<T>
where
T: Eq + Hash + Copy,
package ringbuffer
import (
"errors"
"fmt"
)
type RingBuffer struct {
buf []interface{}
len int
quicksort!(A::AbstractArray) = _quicksort!(A, 1, length(A))
function _quicksort!(A::AbstractArray, low::Integer, high::Integer)
if low < high
pivot_index = partition!(A, low, high)
_quicksort!(A, low, pivot_index)
_quicksort!(A, pivot_index+1, high)
end
return A
@harryscholes
harryscholes / logging.go
Created April 29, 2021 13:32
Go logging packages
err := errors.New("seems we have an error here")
// zerolog
log.Error().
Err(err).
Str("foo", "foo").
Str("bar", "bar").
Msg("Something happened")
// logrus
@harryscholes
harryscholes / main.py
Last active March 8, 2021 14:40
Remap keyboard keys in macOS
def convert(val):
int_val = int(val, 16)
int_ref = 0x700000000
return hex(int_ref | int_val)
print(convert('0x65'))
print(convert('0xe6'))
### Keybase proof
I hereby claim:
* I am harryscholes on github.
* I am harryscholes (https://keybase.io/harryscholes) on keybase.
* I have a public key whose fingerprint is 37C2 8515 CDEB 6C90 9D69 34C9 BA1D 64EE D2E0 616C
To claim this, I am signing this object:
@harryscholes
harryscholes / pgp.sh
Last active January 21, 2022 20:19
PGP keys
gpg --full-generate-key --expert
# (9) ECC and ECC
# (5) NIST P-521
# Get key ID
gpg --list-secret-keys --keyid-format LONG
# Export public key
gpg --armor --export <KEY ID>
@harryscholes
harryscholes / semaphore.go
Last active December 15, 2020 10:43
Go semaphore
package main
import (
"fmt"
"time"
)
type semaphore struct {
c chan struct{}
}