Skip to content

Instantly share code, notes, and snippets.

View lucaswinningham's full-sized avatar

Lucas Winningham lucaswinningham

View GitHub Profile
module Levenshtein
class << self
def call(a, b)
return cache["#{a}-#{b}"] if cache["#{a}-#{b}"]
cache["#{a}-#{b}"] = cache["#{b}-#{a}"] = -> {
return a.length if b.length.zero?
return b.length if a.length.zero?
a_head, a_tail = a.chars.then { |head, *tail| [head, tail.join] }
@lucaswinningham
lucaswinningham / search.rb
Last active October 11, 2023 14:47
Search in Ruby
module Search
class << self
def search(options = {}, &process_node)
process_node ||= proc {}
stop = options.fetch(:stop, nil)
queue = options.fetch(:queue) { raise QueueRequiredError }
until queue.empty?
current_node = queue.dequeue
@lucaswinningham
lucaswinningham / import.re
Created September 15, 2023 18:33
Search for imports in Node using regex
import\s*\{[\n\s]*(\w+\s*,\s*)*\bUploadSnackbar\b(\s*,\s*\w+\s*,*\s*|\s*,*)*[\n\s]*\}\s*from\s*('|")\s*.*\bMyComponent\b.*\s*('|")
@lucaswinningham
lucaswinningham / Expand.ts
Created September 15, 2023 18:31
VS Code expand props more
// https://stackoverflow.com/questions/57683303/how-can-i-see-the-full-expanded-contract-of-a-typescript-type
// expands object types one level deep
type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
// expands object types recursively
type ExpandRecursively<T> = T extends object
? T extends infer O ? { [K in keyof O]: ExpandRecursively<O[K]> } : never
: T;
@lucaswinningham
lucaswinningham / ComponentEventProps.ts
Created September 15, 2023 18:30
TypeScript React component events
type Indexable = string | symbol | number;
type PickByKeyName<Type, Name extends Indexable> = {
[Key in keyof Type as Key extends Name ? Key : never]: Type[Key];
};
type PickByKeyType<Type, KeyType> = Pick<Type, {
[Key in keyof Type]: Type[Key] extends KeyType ? Key : never
}[keyof Type]>;
# https://www.ascii-code.com/
# https://fontstruct.com/fontstructions/show/847768/5x7_dot_matrix
'
1 2 3 4 5 6 7 8 9 0
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
'
# 00 01 02 03 04
# 05 06 07 08 09
@lucaswinningham
lucaswinningham / character_displays.rb
Created August 7, 2023 12:35
5x7 matrix display of essential ascii characters.
# https://www.ascii-code.com/
# https://fontstruct.com/fontstructions/show/847768/5x7_dot_matrix
'
1 2 3 4 5 6 7 8 9 0
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
'
# 00 01 02 03 04
# 05 06 07 08 09
@lucaswinningham
lucaswinningham / entry.rb
Last active September 29, 2023 13:35
Simple Ruby Middleware Chain
# frozen_string_literal: true
module Middleware
class Entry
attr_reader :klass, :args, :kwargs, :block
def initialize(klass, *args, **kwargs, &block)
@klass = klass
@args = args
@kwargs = kwargs
@lucaswinningham
lucaswinningham / how_to.md
Created May 19, 2021 18:20
Recursively source bash files
#!/usr/bin/env bash

this_dir="${BASH_SOURCE%/*}"

# Recursively iterates over directories looking for .sh files sourcing them if they exist
for executable in $(find "$this_dir" -regex ".*\.sh"); do
  [ -f "$executable" ] && source "$executable"
done
@lucaswinningham
lucaswinningham / how_to.md
Created December 8, 2020 19:49
Semi-monthly iCalendar Recurring Event (Pay Day)

Create an ics file

$ touch pay_day.ics

pay_day.ics

BEGIN:VCALENDAR