This file contains 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
"""Utilities for Counting and Testing Prime Numbers. | |
A significant portion of the material here is thanks to Al Sweigart and their | |
incredible explanations on prime number sieves from their book, "Cracking Codes | |
With Python." | |
You can read the book online here: | |
* https://inventwithpython.com/cracking/chapter0.html | |
You can also purchase a paper copy here: |
This file contains 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
"""Functions to generate prime numbers efficiently. | |
Source: | |
* https://eli.thegreenplace.net/2023/my-favorite-prime-number-generator | |
""" | |
def gen_primes(): | |
"""Generate an infinite sequence of prime numbers.""" | |
D = {} | |
q = 2 |
This file contains 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
#!/bin/bash | |
# | |
# Calculate the number of NUMA nodes on the current host. | |
# | |
# iabwi8:~# number-of-numa-nodes | |
# 4 | |
# | |
function number-of-numa-nodes() { | |
ls --directory /sys/devices/system/node/node* | wc --lines | |
} |
This file contains 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
#!/bin/bash | |
# | |
# Get the number of hugepages currently configured on the system. | |
# | |
# Sample output: | |
# Hugepages: | |
# Total: 0 (0) | |
# Free: 0 (0) | |
# Surplus: 0 (0) | |
# |
This file contains 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
"""Overview of Plotting in Python Using Matplotlib and Seaborn. | |
python3 -m pip install --upgrade pip wheel setuptools packaging | |
python3 -m pip install --upgrade numpy scipy matplotlib seaborn | |
This script also needs FFMPEG on Windows to be able to render animations | |
as MP4 files (maybe on Linux too, I don't know). | |
""" | |
from collections import Counter |
This file contains 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/bash | |
# | |
# Remove color control sequences from terminal output. | |
sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g" |
This file contains 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
"""LeetCode Problem 14 - Longest Common Prefix""" | |
from typing import List, Optional, Text | |
from absl import app | |
from absl import flags | |
from absl import logging | |
from absl.testing import absltest | |
def inputs_are_valid(strings: List[Text]) -> bool: |
This file contains 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
"""LeetCode Problem 2 - Add Two Numbers | |
This file requires the Abseil python library, absl-py. | |
""" | |
from typing import List, Optional, Text | |
from absl import app | |
from absl import flags | |
from absl import logging |
This file contains 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/bash | |
# | |
# This function is meant to be defined or included in a file automatically | |
# sourced by the shell on startup, such as the ~/.bashrc file. | |
# | |
# Once this function is sourced, it can be called like any other bash function, | |
# and the output looks something like the following. | |
# | |
# 2023-05-24-18:03:09.368078818 | |
# |
This file contains 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/bash | |
# | |
# This script takes every integer passed to it and prints it to standard output | |
# as an integer formatted according to US English convention. That is, numbers | |
# with more than three digits are printed with every three digits from the right | |
# separated by a comma. | |
# | |
# This command was run via the command-line, not as an actual shell script. This | |
# gist is just a way for me to remember how I did it. | |
# |
NewerOlder