Skip to content

Instantly share code, notes, and snippets.

@GregWWalters
GregWWalters / bitflag.js
Created May 10, 2023 19:44
BitFlag generator class in JS
/* eslint-disable no-bitwise,no-plusplus,no-underscore-dangle */
/* eslint-disable no-func-assign,no-return-assign */
const util = require('../authorization/util');
// TODO: move utils
const MAX_BIT = Math.log2(Number.MAX_SAFE_INTEGER);
/**
* Get the value of the next bit in the series and increment the next bit
* value. If the maximum safe bit has already been claimed, it will throw
@GregWWalters
GregWWalters / explanation.md
Created April 21, 2021 17:31
References to Slices in Go

In most situations, a reference to a slice in Go is unnecessary. The slice itself contains a pointer to the underlying array, so slices passed as arguments to functions or variables set to slices that are properties of structs can modify the elements of the original slice.

However, if you need to add new elements to the slice, the slice is replaced. By using a reference to the slice, structs and out-of-scope slices can be grown.

For a more complete explanation of why references to slices aren't pointless,

@GregWWalters
GregWWalters / diff.go
Created August 13, 2020 16:14
An exploration of Go's reflect package and utility for finding the difference between any two arbitrary values
package testutils
import (
"encoding/json"
"errors"
"fmt"
"reflect"
)
// MARK: Public Functions