Skip to content

Instantly share code, notes, and snippets.

View grab-a-byte's full-sized avatar

Adam Parker grab-a-byte

View GitHub Profile
@grab-a-byte
grab-a-byte / ParseInt.dart
Last active May 14, 2025 19:01
String to int in dart (using only chained methods)
const AsciiZero = 48;
const AsciiNine = 57;
int unsafeParseInt(String input) =>
input.codeUnits.map((x) => x - AsciiZero).fold(0, (a, b) => (a * 10) + b);
int? safeParseInt(String input) => input.codeUnits
.map((x) => (x < AsciiZero || x > AsciiNine) ? null : (x - AsciiZero))
.fold(0, (acc, value) => value == null ? null : (acc! * 10) + (value));
@grab-a-byte
grab-a-byte / ast.go
Last active January 21, 2025 17:16
Rust vs Go comparrison
package ast
import (
"bytes"
"fmt"
"monkey/token"
"strings"
)
@grab-a-byte
grab-a-byte / main.go
Created July 19, 2023 20:22
Calculate days from now until a date specified in end on specified days.
package main
import (
"fmt"
"time"
)
func main() {
d := time.Now()
end := time.Date(2024, 6, 1, 0, 0, 0, 0, d.Location())
@grab-a-byte
grab-a-byte / gitui-install-ubuntu.sh
Last active April 14, 2023 11:20
gitui install script ubuntu
curl -s curl -s https://api.github.com/repos/extrawurst/gitui/releases/latest | grep -wo "https.*linux.*gz" | wget -qi - # get the latest builds of gitui (they are archives)
tar xzvf gitui-linux-musl.tar.gz # extract the gitui executable from the musl build archive
sudo chown root:root gitui # set ownership and group ownership of the gitui executable to root
sudo chmod u=rwx,g=rx,o=rx gitui # set the permission of the gitui executable to reflect the usual permissions in /usr/local/bin/ (-rwxr-xr-x)
sudo mv gitui /usr/local/bin/ # move the gitui executable to /usr/local/bin/
rm gitui-linux-aarch64.tar.gz gitui-linux-arm.tar.gz gitui-linux-armv7.tar.gz gitui-linux-musl.tar.gz # remove downloaded archives
#r "nuget: FParsec, 2.0.0-beta2"
open System
open FParsec
open FParsec
open FParsec
type Value =
| Int of int
| Str of string
public abstract class OtherLogLevels : IEquatable<OtherLogLevels>, IStructuralEquatable, IComparable<OtherLogLevels>, IComparable, IStructuralComparable
{
public bool IsInfo { get; }
public bool IsWarning { get; }
public bool IsError { get; }
public int Tag { get; }
public static OtherLogLevels NewError(int item);
public static OtherLogLevels NewInfo(string item);
public static OtherLogLevels NewWarning((int, string) item);
type OtherLogLevels =
| Error of int
| Warning of struct(int * string)
| Info of string
public enum LogLevels
{
Error = 1,
Warning = 2,
Info = 3
}
type LogLevels =
| Error = 1
| Warning = 2
| Info = 3
var strLength = FunctionalParadigms.aFunction("Thing"); // Returns 5