This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Turns out JS can be fast. Generators are just slow. :( | |
| // A fairer comparison with | |
| // https://gist.github.com/bsidhom/32162a78e602d2f620dc8ab07c71ef97 | |
| const main = () => { | |
| let i = 0; | |
| partitionsInternal(100, (_p) => { | |
| i++; | |
| if (i % 1000000 == 0) { | |
| console.log(i); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Compare to https://gist.github.com/bsidhom/224b1c343bc18e4c351f3ba6a3655dba, which uses external | |
| // iterators. This is _substantially_ faster than the JavaScript variant (unsurprisingly): | |
| // https://gist.github.com/bsidhom/53b13d54f0059086d9b6c4e20fd8d42a | |
| fn main() { | |
| let mut n = 0; | |
| partitions(100, |_p| { | |
| n += 1; | |
| if n % 1000000 == 0 { | |
| println!("{n}"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Translation of https://gist.github.com/bsidhom/c136b6bd26dcff64d9ca443a5bd022a3 into JS for use in the browser. | |
| const main = () => { | |
| const n = 10; | |
| for (const partition of genPartitions(n)) { | |
| console.log(partition); | |
| } | |
| }; | |
| const genPartitions = function* (n) { | |
| const prefix = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This naively computes partitions of a _multiset_ by first creating a unique | |
| // set of indices (into that multiset) and generating all partitions of those | |
| // (necessarily unique) indices. Finally, multi-partitions are canonicalized, | |
| // deduplicated, and then printed. This only works for very small multisets | |
| // since the set of all partitions must fit into memory. It is essentially only | |
| // useful for verifying that the final algorithm does what it's supposed to do. | |
| // | |
| // My tentative strategy for the memory-friendly version is to build all | |
| // partitions in _lexicographic_ order, recursively (top-down). The general idea | |
| // is to specify the initial set in lexicographical order. Starting at the end, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // NOTE: Building this up en route to a hopefully-clean _multiset_ partition generator. | |
| const main = () => { | |
| const set = [1, 2, 3, 4]; | |
| for (const partition of genPartitions(set)) { | |
| console.log(partition); | |
| } | |
| }; | |
| // Generate all partitions of the given set (given as an array of unique items). | |
| // If the items are given in _ascending_ order, then the generator will yield |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # On macOS, certain directories such as /tmp are specially linked and must be referenced by canonical paths under volume mounts. | |
| podman run --rm -i --user "$(id -u):$(id -g)" --userns keep-id --workdir /data -v "$(readlink -f $(pwd)):/data" jbarlow83/ocrmypdf-alpine <args> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import decimal | |
| import math | |
| from decimal import Decimal | |
| from fractions import Fraction | |
| # In response to https://www.reddit.com/r/mildlyinteresting/comments/1hcb9ce/not_a_single_person_at_my_2000_student_high/ | |
| # and, in particular, some sloppy math in https://www.reddit.com/r/mildlyinteresting/comments/1hcb9ce/comment/m1mzfgh/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Main where | |
| main :: IO () | |
| main = do | |
| mapM_ print xs where | |
| xs = powerset [(1 :: Integer)..24] | |
| powerset :: [a] -> [[a]] | |
| powerset = pset [] where | |
| pset :: [a] -> [a] -> [[a]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # This tool operates on CSV files as created (and read) by the FitCSVTool.jar | |
| # tool included in the FIT SDK. Input is always read from stdin, and output is | |
| # written to stdout. | |
| # | |
| # Example usage: | |
| # java -jar FitCSVTool.jar -b original_activity.fit original_activity.csv | |
| # ./fixfit.py detect <original_activity.csv | |
| # ./fixfit.py strip --field=accumulated_power --field=avg_power --field=functional_threshold_power --field=max_power --field=normalized_power --field=power --field=power_zone_high_boundary --field=threshold_power --field=time_in_power_zone <original_activity.csv >fixed_activity.csv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| function main() { | |
| if [[ $# -ne 1 ]] ; then | |
| echo "usage: $0 <router ip>" >&2 | |
| exit 2 | |
| fi | |
| local router_ip="$1" |
NewerOlder