Skip to content

Instantly share code, notes, and snippets.

View mlbright's full-sized avatar

Martin-Louis Bright mlbright

  • Toronto
  • 07:17 (UTC -05:00)
View GitHub Profile
@mlbright
mlbright / settle-up.py
Created October 5, 2025 15:50
greedy algorithm for settling up
def minimize_transactions(balances):
"""
balances: dict of {person: net_balance}
Returns: list of (from, to, amount) transactions
"""
transactions = []
credits = {p: b for p, b in balances.items() if b > 0}
debts = {p: -b for p, b in balances.items() if b < 0}
while credits and debts:
package main
import (
"fmt"
"os"
"os/exec"
"strings"
"unicode"
"mvdan.cc/sh/v3/syntax"
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw{ say };
use Getopt::Long;
my $options = {};
GetOptions( $options, "--directory=s", "--start=s", "--finish=s" );
A BCDEFDG
AH I ECDDF
HDICJ
A BIKFDGLM
NODCAJDC
IHG GDMPQANDG
NOD CAEODQ
AH I HDICRS
EIJD
@mlbright
mlbright / perl-modules.pl
Created May 26, 2018 04:07
List all installed perl modules
#! /usr/bin/perl -l
use strict;
use warnings;
use File::Find;
my %seen;
for my $inc (@INC) {
next unless (-d $inc);
@mlbright
mlbright / filepath-examples.go
Created January 17, 2018 16:40
Compare golang's filepath.Split and filepath.Dir
package main
import (
"fmt"
"path/filepath"
)
func main() {
paths := []string{
"/home/arnie/amelia.jpg",
{
repository(name: "darksky", owner: "mlbright") {
ref(qualifiedName: "refs/heads/master") {
target {
... on Commit {
tree {
id
entries {
oid
name
{
repository(name: "darksky", owner: "mlbright") {
ref(qualifiedName: "master") {
target {
... on Commit {
id
history(first: 5) {
pageInfo {
hasNextPage
}
#!/usr/bin/perl
use strict;
use warnings;
my $days = 7;
my $nights = $days - 1;
my $bar = 2;
my $maid = 5;
my $alacarte = 5;
@mlbright
mlbright / search
Last active March 7, 2017 05:02
possible trees