Skip to content

Instantly share code, notes, and snippets.

View luvies's full-sized avatar
😤
on that mf grind

luvies

😤
on that mf grind
View GitHub Profile
@luvies
luvies / shim-definitions.d.ts
Created December 14, 2018 11:14
An example definition showing how to provide a definition file for a package without defining the entire thing.
declare module 'shim-definitions' { // This module name should match the package name.
/**
* This allows something like VSCode to auto-import with the name
* `shimDefinitions`. It could be any other name you want.
*/
const shimDefinitions: any;
/**
* Doing this allows you to import like so:
* ```ts
@luvies
luvies / node_prebuild.ts
Last active January 17, 2021 17:02
A deno script to transform TypeScript files that use .ts imports to not use them for node compatibility
#!/usr/bin/env deno run --allow-read --allow-write
import { parse } from "https://deno.land/[email protected]/flags/mod.ts";
import { relative, resolve } from "https://deno.land/[email protected]/path/mod.ts";
/*
Transforms the content all files in a directory to remove `.ts` from
the end of imports.
*/
const { args, exit, mkdir, readDir, readFile, remove, stat, writeFile } = Deno;
@luvies
luvies / anagram.ts
Created October 2, 2020 19:29
A Deno script for getting full and partial anagrams of words
#!/usr/bin/env deno run --allow-read --allow-hrtime
import { readLines } from "https://deno.land/[email protected]/io/mod.ts";
function intersection<T>(a: Set<T>, b: Set<T>): Set<T> {
// Quick optimisation by iterating the smaller set instead of the larger one.
const [small, large] = a.size > b.size ? [b, a] : [a, b];
const intersect = new Set<T>();
for (const item of small) {
if (large.has(item)) {