Thanks to visit codestin.com
Credit goes to gist.github.com

Skip to content

Instantly share code, notes, and snippets.

View NorthDecoder's full-sized avatar

Joe Devlin NorthDecoder

View GitHub Profile
@NorthDecoder
NorthDecoder / is_python_module_installed.py
Last active May 19, 2025 15:24
Check pip list to see if a python module is installed
def is_module_installed(module_name):
'''
Input: module_name -> string
Output: True or False -> boolean
If the input module_name is
* in `pip list` returns True
* NOT in `pip list` returns False
'''
@NorthDecoder
NorthDecoder / mp_check.py
Created March 24, 2025 19:57
Multiprocessing requires more than one cpu - check
import logging
logging.basicConfig(level=logging.INFO)
import multiprocessing as mp
def mp_check():
# multiprocessing requires more than one cpu
cpu_count = mp.cpu_count()
if cpu_count > 1 :
# count ok
logging.info("OK: cpu_count: " + str(cpu_count) + ", is greater than 1")
@NorthDecoder
NorthDecoder / cpp_modulo_example.cpp
Created December 19, 2022 20:28
An example c++ modulo calculator with results in a table
// example tested at https://tio.run/#cpp-gcc
// make a table with modulo calculations
#include<iostream>
using std::cout;
int main() {
int dmax = 7;
int nmax = 5;
cout << "D->";
for (int denominator = 1; denominator < dmax; denominator ++) {
@NorthDecoder
NorthDecoder / openSession
Last active February 5, 2022 09:19
A bash script for opening a Tmux session with multiple predefined autopopulated panes
openSession () {
# start-tmux-with-several-panes-open-at-the-same-time
# input from the command line
# usage:
# openSession /my_project_directory/name_here my_tmux_session_name
# Reference:
# https://askubuntu.com/questions/830484/how-to-start-tmux-with-several-panes-open-at-the-same-time#answer-1351351
@NorthDecoder
NorthDecoder / resurrect-chapter.sh
Last active April 29, 2021 22:32
A helper script for manual testing Chapter
#!/usr/bin/bash
clear
me=$( basename "$0" )
echo "~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "
echo "Running script $me"
echo "~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "
# Reference:
# https://github.com/freeCodeCamp/chapter
@NorthDecoder
NorthDecoder / my-versions.sh
Created October 16, 2020 20:44
Quick echo versions to display for nvm, node, npm, docker, tmux, vim, nano, ansible, and python
#!/usr/bin/bash
# file: my-versions.sh
# quick display the versions
# to avoid retyping
# setup:
# chmod 744 my-versions.sh
# command prompt usage:
@NorthDecoder
NorthDecoder / luhn.py
Created September 22, 2020 16:44
Luhn algorithm for validating credit card numbers
def luhn(card_number):
def digits_of(n):
return [int(d) for d in str(n)]
digits = digits_of(card_number)
odd_digits = digits[-1::-2]
even_digits = digits[-2::-2]
checksum = 0
checksum += sum(odd_digits)
for d in even_digits:
checksum += sum(digits_of(d*2))
@NorthDecoder
NorthDecoder / is_cc_valid_01.py
Last active September 22, 2020 16:29
Validate credit card number with Luhn algorithm
# file: is_cc_valid.py
# LUHN Algorithm
# Validate credit card number with Luhn algorithm
def is_cc_valid(cc_number, given_checksum):
# ref: https://en.wikipedia.org/wiki/Luhn_algorithm
double_every_other = []
sum_digits = []
minus_nine = []
@NorthDecoder
NorthDecoder / list-installed-python-modules.py
Last active May 25, 2021 19:38
Print a list of installed python modules
# list installed python modules
# > sorted alphabetically
import sys
import os
def list_dict_keys(a_dictionary, list_heading_text):
"""
Print a heading and a list of dictionary keys
to the command line.
"""
@NorthDecoder
NorthDecoder / customize-bashrc-command-prompt
Last active February 14, 2025 16:45
bashrc customized command prompt
# Add a custom command line prompt with color and git branch name
# > On linux adds newline for more room to type
# add the following to the bottom of the ~/.bashrc file
# prerequisite:
# bash function __git_ps1 must be found and sourced in order for the
# git branch to be shown.
# __git_ps1 Reference:
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh