Skip to content

Instantly share code, notes, and snippets.

View erikcorry's full-sized avatar
🏠
Working from home

Erik Corry erikcorry

🏠
Working from home
View GitHub Profile
@erikcorry
erikcorry / aliasing-slices.go
Created March 24, 2021 09:43
Golang slices sometimes alias their underlying array, and sometimes don't.
// Prints false, false, false, true, false, true, true, false, true.
package main
func main() {
for i := 0; i < 10; i++ {
println(doesItAlias(i))
}
}

Signed overflow detection on anti-80

Motivation

Rust would like to enable overflow checks (and does in debug mode) but many CPUs don't have great support. JS and many other languages need overflow checking.

For adding or subtracting a constant the overflow check is already fairly simple, but it's a bit longwinded for adding

@erikcorry
erikcorry / mbedtls-errors.txt
Created October 23, 2020 14:35
Mbed TLS error codes
High level error codes
0x1080 PEM - No PEM header or footer found
0x1100 PEM - PEM string is not as expected
0x1180 PEM - Failed to allocate memory
0x1200 PEM - RSA IV is not in hex-format
0x1280 PEM - Unsupported key encryption algorithm
0x1300 PEM - Private key password can't be empty
0x1380 PEM - Given private key password does not allow for correct decryption
0x1400 PEM - Unavailable feature, e.g. hashing/encryption combination
" Looks at the character to the left, and does a shell-style autocomplete
" (ctrl-P) if we are in the middle of a word. If there is white-space
" or beginning-of-line, it does two spaces to indent.
function! CleverTab()
if strpart( getline('.'), col('.')-2, 1) =~ '^\s*$'
return " "
else
return "\<C-P>"
endfunction
inoremap <Tab> <C-R>=CleverTab()<CR>
@erikcorry
erikcorry / test.v
Created January 24, 2018 06:42
Chained FSM
module stage(clock, reset, in, out);
input wire clock;
input wire reset;
input wire in;
output reg out;
always @(posedge clock) begin
if (reset) begin
out <= 1;
end else begin
out <= !in;
" Tab completion in vim using the tab key.
" Turns into two spaces if there is no alphanumerics on the left of the cursor.
function! CleverTab()
if strpart( getline('.'), col('.')-2, 1) =~ '^\s*$'
return " "
else
return "\<C-P>"
endfunction
inoremap <Tab> <C-R>=CleverTab()<CR>