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 / 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)) {
@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 / 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
#!/usr/bin/env node
'use strict';
/*
A Node.js implementation of
https://github.com/connorworley/dotfiles/blob/master/.bin/brew-autoremove
*/
const child = require('child_process');
const util = require('util');
@luvies
luvies / jake-helpers.js
Last active August 25, 2018 23:01
Some helpers to aid in Jakefiles
/**
* Provides various helpers for running a Jakefile
* Source: https://devspri.me/jake-helpers
* @module jake-helpers
*/
const { promisify } = require('util');
// create promise version of exec
jake.exec.promise = promisify(jake.exec);
@luvies
luvies / remote-test.csx
Created June 17, 2018 11:09
Test gist for remote dotnet-script loading
#! /usr/bin/env dotnet script -c Release
public string RemoteTest() => "Hello world";
@luvies
luvies / monty-hall.py
Created April 24, 2018 19:35
Python version of the Monty Hall problem
#! /usr/bin/env python3
from random import randint, shuffle
TIMES = 10_000_000
def get_dict():
return {
"wins": 0,
"losses": 0
@luvies
luvies / LiftoffManager.cs
Last active January 12, 2018 21:05
Liftoff Manager ingame script for Space Engineers
/*-*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sandbox.Common;
using Sandbox.Common.ObjectBuilders;
using Sandbox.Definitions;
using Sandbox.Engine;
@luvies
luvies / daemon_link.py
Last active October 3, 2017 11:27
Allows for a daemon to have a separate client command to control it. The DaemonClient simply passes all arguments to the DaemonServer in place (excluding the first executable argument) and while the server is processing the arguments, the client receives all the output & send all the input.
@luvies
luvies / clean-drive.py
Created August 25, 2017 17:55
Removes all .DS_Store and ._* files from the current folder and all sub-folders.
#! /usr/bin/env python3
import os
import re
def get_items(dir):
dirs = []
files = []
with os.scandir(dir) as scan:
for entry in scan: