Skip to content

Instantly share code, notes, and snippets.

View trvswgnr's full-sized avatar
:octocat:
hardly workin'

Travis Wagner trvswgnr

:octocat:
hardly workin'
View GitHub Profile
@trvswgnr
trvswgnr / htmx-internal.d.ts
Last active December 7, 2023 03:39
htmx internal api type definitions + missing types
import type * as _htmx from "htmx.org";
declare global {
var htmx: typeof _htmx;
}
declare module "htmx.org" {
interface HtmxExtension {
init(apiRef: HtmxInternalApi): void;
}
@trvswgnr
trvswgnr / tw-dialog.html
Created November 13, 2023 08:30
no js dialog with tailwind
<label for="modal1">clicky boi</label>
<input id="modal1" class="peer" type="checkbox" hidden />
<label for="modal1" class="hidden peer-checked:block bg-black bg-opacity-25 fixed h-full w-full top-0 left-0"></label>
<dialog class="hidden peer-checked:block">
<p>lgtm ¯\_(ツ)_/¯</p>
<label for="modal1">close</label>
</dialog>
@trvswgnr
trvswgnr / hash.rs
Last active November 3, 2023 06:35
Fast hashing of file contents in CrabLang with xxHash
use std::{
hash::Hasher,
io::{self, BufReader, Read},
};
/// The size of the buffer used when reading the file.
const BUFFER_SIZE: usize = 8 * 1024; // 8 KB
/// Hashes the contents of the given readable object (e.g. a file).
#[inline]
@trvswgnr
trvswgnr / fearless.rs
Last active September 22, 2023 19:10
fearless concurrency macro
macro_rules! fearless {
($t:ty) => {
std::sync::Arc<std::sync::Mutex<$t>>
};
($e:expr) => {
std::sync::Arc::new(std::sync::Mutex::new($e))
};
(clone $e:expr) => {
std::sync::Arc::clone(&$e)
};
@trvswgnr
trvswgnr / 1-TripMap.ts
Last active September 21, 2023 16:41
triple key map, where the order of keys doesn't matter
export class TripMap<K, V> {
private map: Map<number, V>;
constructor() {
this.map = new Map<number, V>();
}
private generateKey(...items: any[]): number {
return [...new Set(items)]
.map((x) => this.hash(x))
@trvswgnr
trvswgnr / path.txt
Last active September 15, 2023 06:26
available cli commands, tools, and packages for chatgpt advanced data analysis
aclocal
aclocal-1.16
activate-global-python-argcomplete
acyclic
add-apt-repository
add-shell
addgnupghome
addgroup
addpart
addr2line
@trvswgnr
trvswgnr / type-bst.ts
Created September 2, 2023 05:50
type-level bst typescript
type TreeNode<V extends number = number, L = null, R = null> = {
value: V;
left: L;
right: R;
};
type BinarySearchTree<T = null> = {
root: T;
};
@trvswgnr
trvswgnr / prim.rs
Last active August 27, 2023 16:26
prim's algo in crab & ts
use std::cmp::Ordering;
use std::collections::BinaryHeap;
const INF: u32 = u32::MAX;
#[derive(Copy, Clone, Eq, PartialEq)]
struct Edge {
weight: u32,
vertex: usize,
}
@trvswgnr
trvswgnr / leftpad.java
Last active August 27, 2023 23:08
left-pad for enterprise
interface Logger {
void error(String message, Throwable t);
}
class ConsoleLogger implements Logger {
private final String className;
ConsoleLogger(String className) {
this.className = className;
}
@trvswgnr
trvswgnr / nosqlfiles.ts
Created August 25, 2023 21:22
nosql db with files
import { promises as fs } from 'fs';
import { v4 as uuidv4 } from 'uuid';
import { Mutex } from 'async-mutex';
interface Document {
[key: string]: any;
}
interface Index {
[key: string]: { [value: string]: string[] };