Skip to content

Instantly share code, notes, and snippets.

View jflopezfernandez's full-sized avatar
🏈
Merry Start of the Football Season Eve!!!

Jose Fernando Lopez Fernandez jflopezfernandez

🏈
Merry Start of the Football Season Eve!!!
View GitHub Profile
@jflopezfernandez
jflopezfernandez / count_primes.py
Last active January 20, 2024 21:25
Solution to LeetCode Problem 204: Count Primes
"""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:
"""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
@jflopezfernandez
jflopezfernandez / numa-nodes.sh
Created October 17, 2023 12:43
Calculate number of NUMA nodes on the current host.
#!/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
}
@jflopezfernandez
jflopezfernandez / hugepages.sh
Created October 17, 2023 12:30
View hugepages information about the current system.
#!/bin/bash
#
# Get the number of hugepages currently configured on the system.
#
# Sample output:
# Hugepages:
# Total: 0 (0)
# Free: 0 (0)
# Surplus: 0 (0)
#
"""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
#!/usr/bin/bash
#
# Remove color control sequences from terminal output.
sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g"
"""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:
"""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
@jflopezfernandez
jflopezfernandez / timestamp.sh
Created May 24, 2023 23:08
This bash script outputs a timestamp of the current time useful for time-dependent filenames, logging statements. etc.
#!/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
#
@jflopezfernandez
jflopezfernandez / print-formatted-integers.sh
Last active May 25, 2023 00:26
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.
#!/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.
#