Skip to content

Instantly share code, notes, and snippets.

View cartercanedy's full-sized avatar
🚀
Thinking about the next rice for my nvim cfg

cartercanedy

🚀
Thinking about the next rice for my nvim cfg
View GitHub Profile
@cartercanedy
cartercanedy / DefaultDeleter.h
Last active April 12, 2025 17:47
Reference classes that emulate types from the <memory> header of the standard library
#pragma once
#ifndef __cplusplus_cli
# error "Not for use in native C++ compilations"
#endif
namespace NativeMemory {
template <class T>
value struct DefaultDeleter {
auto operator()(T *t) {
@cartercanedy
cartercanedy / typed_vector.h
Created February 21, 2025 20:41
A macro for generating and using strongly-typed dynamic arrays in C
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdio.h>
#include <stdlib.h>
#define VECTOR_INIT_CAPACITY 4
// Macro for non-pointer types.
@cartercanedy
cartercanedy / SelectWhere.cs
Created February 4, 2025 20:13
Combination of Select((T) => U) & Where((T) => bool) for better ergonomics
using System.Collections.Generic;
public static class SelectWhereExtension {
delegate bool SelectWherePredicate<T, U>(T input, out U output);
public static IEnumerable<U> SelectWhere<T, U>(this IEnumerable<T> iter, SelectWherePredicate<T, U> predicate) {
var enumerator = iter.GetEnumerator();
while (enumerator.MoveNext()) {
if (predicate(enumerator.Current, out U product)) {
yield return product;
@cartercanedy
cartercanedy / tgz.sh
Last active August 27, 2024 21:32
A shell command to get a progress bar while creating a tarball
#!/usr/bin/env bash
function error() {
# $1 err code
# $2 err msg
echo -e "error: $1: $2"
}
function tgz() {
local longopts="help,output:,force"
@cartercanedy
cartercanedy / Result.cs
Last active March 27, 2025 23:21
C# Result<TOk, TErr> to simulate a basic discriminated union until they get here :)
global using static Results.Result;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace Results;
/// <summary>
@cartercanedy
cartercanedy / .prompt_fmt.sh
Last active March 9, 2024 19:14
bash prompt
GREEN=""
RED=""
NO_COLOR=""
BLUE=""
if [ "$color_prompt" = yes ]; then
GREEN='\033[01;32m'
RED='\033[01;31m'
NO_COLOR='\033[00m'
BLUE='\033[34m'
@cartercanedy
cartercanedy / query.py
Last active November 1, 2023 21:58
Pure Python sequence query functions using Python 3.12+ generic type syntax
from typing import (
Sequence,
Iterable,
Callable
)
type Predicate[ T ] = Callable[ [ T ] , bool ]
type Converter[ TIn , TOut ] = Callable[ [ TIn ] , TOut ]
class QueryException( Exception ):