Skip to content

Instantly share code, notes, and snippets.

@dmmulroy
dmmulroy / shell_benchmark.md
Created January 16, 2024 05:41
Profiling my shells startup time

Shell Benchmarking

Initial

$SHELL -i -c exit  0.42s user 0.10s system 63% cpu 0.821 total
$SHELL -i -c exit 0.42s user 0.10s system 65% cpu 0.792 total
$SHELL -i -c exit  0.42s user 0.10s system 60% cpu 0.861 total
$SHELL -i -c exit 0.42s user 0.10s system 65% cpu 0.795 total
$SHELL -i -c exit  0.42s user 0.09s system 61% cpu 0.838 total
@dmmulroy
dmmulroy / melange-ffi.d.ts
Created January 5, 2024 16:43
Melange ffi js ideas
export as namespace melange_js_ffi;
export namespace Brand {
const BRAND: unique symbol;
type t<_T, B> = { [BRAND]: B };
}
export function curry(fn: Function): Function;
export namespace Option {
@dmmulroy
dmmulroy / readme.md
Created January 4, 2024 18:53
cma readme sample

Your project layout

{{name}}
├── src
│   │   // This is a React Component and the entry point to your application
│   ├── App.re
│   │
│   │   // This is an example of how you can create additional React Components
│   ├── Configuration.re
module Template = struct
let root_dir = "templates"
let base_dir = Node.Path.join [| root_dir; "base" |]
let extensions_dir = Node.Path.join [| root_dir; "extensions" |]
let dir_to_string = function `Base -> "./" | `Extension dir -> dir
module type S = sig
type t
val name : string
@dmmulroy
dmmulroy / wrong-ts-inference.ts
Last active November 11, 2023 23:05
Incorrect TS inference
type RoleName = "admin" | "member";
type AdminPermission = "add-member" | "ban-member" | "delete-any-post";
type MemberPermission = "add-post" | "read-post" | "edit-post" | "delete-post";
type Permission = AdminPermission | MemberPermission;
type RoleToPermissions = {
admin: readonly AdminPermission[];
member: readonly MemberPermission[];
};
@dmmulroy
dmmulroy / compiled.js
Created November 2, 2023 17:35
Compiling ReasonML to JS w/ Melange
// Generated by Melange
import * as Stdlib__List from "melange/list.js";
import * as Stdlib__String from "melange/string.js";
import * as JsxRuntime from "react/jsx-runtime";
var base_classes = {
hd: "text-slate-600",
tl: {
hd: "dark:text-slate-400",
declare const BRAND: unique symbol
/**
* Creates a new branded type by intersecting a given type with an object
* containing a unique brand symbol.
*/
export type Brand<T, B> = T & { [BRAND]: B }
/** Creates a new branded type by intersecting a given type with an object containing a unique brand symbol. */
export function toBrandedType<T, B>(value: T, _brand: B): Brand<T, B> {
type Duration = {
years?: number
months?: number
weeks?: number
days?: number
hours?: number
minutes?: number
seconds?: number
}
@dmmulroy
dmmulroy / SwrLruCache.ts
Created April 7, 2023 18:01
SwrLruCache.ts
import { Cache, Key, State } from 'swr'
/**
* SwrLruCache is a Least Recently Used (LRU) cache implementing the SWR {@link Cache}
* interface. It manages fetched data and errors while limiting the number of
* stored items. This optimizes memory usage by evicting the least accessed
* items when capacity is reached.
*/
export class SwrLruCache<Data = unknown, Error = unknown>
implements Cache<Data>
@dmmulroy
dmmulroy / rotate_windows.lua
Last active February 12, 2023 23:07
Neovim Rotate Windows command
vim.api.nvim_create_user_command("RotateWindows", function()
local ignored_filetypes = { "NvimTree", "fidget", "Outline" }
local window_numbers = vim.api.nvim_tabpage_list_wins(0)
local windows_to_rotate = {}
for _, window_number in ipairs(window_numbers) do
local buffer_number = vim.api.nvim_win_get_buf(window_number)
local filetype = vim.bo[buffer_number].filetype
if not vim.tbl_contains(ignored_filetypes, filetype) then