Skip to content

Instantly share code, notes, and snippets.

View jasonm23's full-sized avatar

Jason Milkins jasonm23

View GitHub Profile
jasonm23 /
Last active September 8, 2023 13:26
Learning Elixir

Learning Elixir

Elixir is a versatile programming language known for its unique features and capabilities. Here are some key areas where Elixir truly shines:

  1. Concurrency and Parallelism: Elixir's concurrency model is based on lightweight processes that are isolated and can run concurrently. These processes communicate through message passing, allowing developers to build highly concurrent and scalable systems.

  2. Fault Tolerance: Elixir is built on the Erlang virtual machine (BEAM), which is known for its robust fault tolerance features. Processes can crash independently without affecting the overall system, thanks to supervision trees and supervisors that automatically restart failed processes.

  3. Scalability: Elixir's processes are lightweight, making it easy to scale applications horizontally. This scalability is crucial for building systems that can handle a large number of concurrent connections, such as web servers and real-time applications.


Left truncate on long pathnames in an llvm-cov HTML report.

Usage: $0 report_root_path source_starts_at_dir

For example the absolute, root path to a file.


Will left truncate with a leading elipsis:

jasonm23 /
Last active August 26, 2023 04:04
Levenshtein Distance Algorithm in plain english

Levenshtein Distance Algorithm in plain English

Inputs: Two strings s and t.

Goal: Calculate the minimum number of single-character edits (insertions, deletions, or substitutions) required to transform string s into string t.

  1. Initialize the Matrix:
    • Create a matrix dp with dimensions (len(s) + 1) x (len(t) + 1).
    • Initialize the first row with values 0 to len(t) and the first column with values 0 to len(s).
jasonm23 /
Last active August 26, 2023 04:40
Dijkstra's A* Algorithm in plain english

Dijkstra's (A*) Algorithm in plain English

Inputs: A graph or grid where each node represents a location and has associated costs, and a start node and a goal node.

Goal: Find the shortest path from the start node to the goal node while considering the associated costs and heuristics.

  1. Initialize Open and Closed Sets:
    • Create an open set containing the start node. This set represents nodes to be evaluated.
    • Create an empty closed set. This set represents nodes that have already been evaluated.
jasonm23 /
Last active August 26, 2023 04:01
Myers Diff Algorithm in plain english

Myers DIFF Algorithm in plain English

Inputs: Two sequences, often represented as strings, let's call them A and B.

Goal: Find the shortest edit script that transforms sequence A into sequence B. An edit script is a sequence of operations like insertions, deletions, and substitutions.

  1. Initialize the Matrix:
    • Create a matrix with rows representing the characters of sequence A and columns representing the characters of sequence B.
    • The matrix will have dimensions (M+1) x (N+1), where M is the length of sequence A, and N is the length of sequence B.
jasonm23 / github-actions-mode.el
Created August 16, 2023 09:24
Emacs github-actions-mode
View github-actions-mode.el
;;; github-actions-mode --- Minor mode for github-actions
;;; Commentary:
;;; Used to add actionlint flycheck checker and github environment var names
;;; Code:
(require 'flycheck)
(require 'company-dabbrev)
jasonm23 /
Created August 13, 2023 07:00
macOS NSTextView / NSTextField action selectors

macOS NSTextView (and NSTextField) selectors

Selector Name Description
insertNewline: Insert a newline at the insertion point.
insertTab: Insert a tab at the insertion point.
jasonm23 /
Last active August 13, 2023 04:43
There's more than one way to TDD

More than one way to TDD

There isn't a one-size-fits-all approach to Test-Driven Development (TDD), and different developers and teams may find variations of the process that work best for them. The essence of TDD lies in the principles of writing tests before or alongside code to ensure better design, maintainability, and test coverage. However, the exact process and order of writing tests and code can vary based on individual preferences and project requirements.

One approach, where you first get a feel for the problem and write some code before diving into the test-code cycle, is a valid way of approaching TDD, especially if it helps you better understand the problem domain and the code you need to write. This can be particularly useful when starting a new project or dealing with complex scenarios. In XP that's called a spike, but it's not really a separate activity, the sooner you can figure out the "bit you don't get", then you jump into writing a test.

The "Red-Green-Refactor" cycle popularized by

jasonm23 / pointdist
Last active August 11, 2023 03:32
Distance and angle between two cartesian points
View pointdist
#!/usr/bin/env python3
import math
import sys
def calculate_distance(x1, y1, x2, y2):
angle = calculate_angle(x1, y1, x2, y2)
return abs(y2 - y1) / math.sin(math.radians(angle))
def calculate_angle(x1, y1, x2, y2):
jasonm23 /
Last active July 5, 2023 15:52
A simple autocomplete GUI in TKinter, Suggestions read from stdin or an input file. Title can also be set. Python 3.11 + tkinter required.
import tkinter as tk
from tkinter import END
import os
import sys
import re
import argparse
# --- Event Handler functions
def select_handler(w):
widget = w.widget