Skip to content

Instantly share code, notes, and snippets.

@eblocha
eblocha / walk.ts
Created February 6, 2024 03:11
Walk A Directory Recursively Using an Async Generator
import * as fs from "fs/promises";
import * as path from "path";
export async function exists(path: string): Promise<boolean> {
return fs
.access(path, fs.constants.F_OK)
.then(() => true)
.catch(() => false);
}
@eblocha
eblocha / custom-fnm-env.zsh
Last active August 30, 2023 02:01
Custom fnm env
if type fnm > /dev/null; then
export FNM_MULTISHELL_ROOT="/run/user/$UID/fnm_multishells"
export FNM_LOGLEVEL="info"
export FNM_VERSION_FILE_STRATEGY="local"
export FNM_MULTISHELL_PATH="$FNM_MULTISHELL_ROOT/$$"
export FNM_COREPACK_ENABLED="false"
export FNM_DIR="$HOME/.local/share/fnm"
export FNM_ARCH="x64"
export FNM_RESOLVE_ENGINES="false"
export FNM_NODE_DIST_MIRROR="https://nodejs.org/dist"
@eblocha
eblocha / file_or_stdin.rs
Last active May 1, 2023 03:02
Rust function to generify a file or stdin for command line apps. If a path is provided, it will return a readable file handle, or stdin if no path is provided.
use std::{fs, io, path::Path};
fn file_or_stdin<P>(path: Option<P>) -> io::Result<Box<dyn io::Read + 'static>>
where
P: AsRef<Path>,
{
match path {
None => Ok(Box::new(io::BufReader::new(io::stdin()))),
Some(path) => match fs::File::open(path) {
Ok(file) => Ok(Box::new(io::BufReader::new(file))),
@eblocha
eblocha / custom-ls-colors.plugin.zsh
Last active August 23, 2022 23:45
Oh-My-ZSH themes and plugins
DIR_COLORS="$HOME/.dir_colors"
eval "`dircolors -b $DIR_COLORS`"
@eblocha
eblocha / .dir_colors
Created August 23, 2022 00:29
My custom DIR_COLORS config
# LS_COLORS
# Maintainers: Magnus Woldrich <m@japh.se>,
# Ryan Delaney <ryan.patrick.delaney@protonmail.com>
# URL: https://github.com/trapd00r/LS_COLORS
#
# This is a collection of extension:color mappings, suitable to use as your
# LS_COLORS environment variable. Most of them use the extended color map,
# described in the ECMA-48 document; in other words, you'll need a terminal
# with capabilities of displaying 256 colors.
#
@eblocha
eblocha / rwlock.test.ts
Created June 10, 2022 11:41
A keyed read-write lock intended to lock files and directories
import { RWLock, FileLock, withPermissions } from './rwlock';
describe('Base RW Lock', () => {
enum LockTypes {
READ = 'read',
WRITE = 'write',
}
type TestCase = {
locks: LockTypes[];
@eblocha
eblocha / color-log.py
Last active June 3, 2022 02:56
A python logging formatter that uses a different format per-level
import logging
import typing as t
from textwrap import indent
from pretty_traceback.formatting import exc_to_traceback_str
_ansi_colors = {
"black": 30,
"red": 31,
"green": 32,
@eblocha
eblocha / config.h
Last active April 22, 2022 11:55
GMMK Pro Custom QMK Settings
#pragma once
#define RGB_MATRIX_KEYPRESSES
// some kind of raindrop effect caused board to crash
#define DISABLE_RGB_MATRIX_RAINDROPS
#define DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
#define DISABLE_RGB_MATRIX_PIXEL_RAIN
#define DISABLE_RGB_MATRIX_PIXEL_FLOW
#define DISABLE_RGB_MATRIX_PIXEL_FRACTAL