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
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 | |
''' |
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
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") |
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
// 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 ++) { |
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
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 |
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/bash | |
clear | |
me=$( basename "$0" ) | |
echo "~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ " | |
echo "Running script $me" | |
echo "~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ " | |
# Reference: | |
# https://github.com/freeCodeCamp/chapter |
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/bash | |
# file: my-versions.sh | |
# quick display the versions | |
# to avoid retyping | |
# setup: | |
# chmod 744 my-versions.sh | |
# command prompt usage: |
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
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)) |
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
# 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 = [] | |
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
# 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. | |
""" |
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
# 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 |
NewerOlder