Skip to content

Instantly share code, notes, and snippets.

View gerryjenkinslb's full-sized avatar

Gerry Jenkins gerryjenkinslb

  • Retired
  • Long Beach, CA
View GitHub Profile
@gerryjenkinslb
gerryjenkinslb / gist:71b35b2a36b1045767d2375c816d60d2
Last active March 2, 2021 22:19
Formula for Arch/Xcfe4 install in Virtualbox
# See Medium Article to go along with this gist at: https://gerry-jenkins.medium.com/installing-archlinux-in-virtualbox-beats-dual-boot-for-work-eb4c5cf2fed7 or at my site: http://gjenkinsedu.com/post/2021-01-13_installing-linux-in-virtualbox-best-dual-boot-for-real-work/
# ArchForVBFormula,
## VirtualBox Setup
- Arch Linux 64 bit
- Memory: 2G to recommended half of total
- Drive: VDI dynamic at least 30G for working system
- Processor cores: recommend half of total
- Display: max out the amount of display memory
@gerryjenkinslb
gerryjenkinslb / pygame_animate_spinning_line.py
Created July 30, 2020 06:34
Basic Animation Technique in PyGame shown in my video: https://youtu.be/gUa1j7gY0yY
import math
import pygame
# initial setups
pygame.init()
screen_size = 500
surface = pygame.display.set_mode((screen_size, screen_size)) # window size and pixels width/height
# animation state variables
angle_per_step = .05 # degrees
from inspect import getframeinfo, currentframe
import os
def line_at(style=None):
"""
returns string with caller filename function name and line number
style parameter (sample string):
'long': 'File /Home/user/xyz.py, in foo(), Line 233'
@gerryjenkinslb
gerryjenkinslb / game_thorns_checker.py
Created February 25, 2019 22:01
Balanced Structure Graph Test (Game of Thorns)
from collections import namedtuple
''' Linear time complete graph check for structural balance checker as per
https://www.reddit.com/r/dailyprogrammer/comments/aqwvxo/20190215_challenge_375_hard_graph_of_thrones/
Algorithm. Since it is a complete graph that has every possible edge between nodes. We don't need a graph.
As we read edges, store edge in dictionary with key as tuple of the two nodes names,
normalized so the first node in the tuple is less than second
# f-strings new in 3.6 and 3.7+
# f-string tutorial code for video: https://youtu.be/c46t7eIldaI
# multiple columns how do you align decimals (zeros should fill in)
# using field width to align columns of numbers
values = [1, 3, 5, 7, 10, 21]
# table of float(v1/v2) for all combinations
from bs4 import BeautifulSoup
import re
import requests
import csv
import time
import json
# version 1.1 added handling of youtube.com/channel/
# to already handling of youtube.com/user based channels
import inspect
""" var_dump('vars') module to dump variables (python 3.6+: uses f strings)"""
def var_dump(var_list_str):
""" print variables in callers scope indicated in space delimited string param"""
# retrieve information needed on callers frame
prev_frame = inspect.currentframe().f_back
frame_info = inspect.getframeinfo(prev_frame)

Python tuple detailed

A tuple is like a list - but safer, faster & smaller

A tuple is an array of object references
it is ordered, and indexed from zero
you cannot modify a tuple entry (immutable)

  • Note that entries in a tuple are references to an object,
    and you can't change which object the tuple points to for a given element.
@gerryjenkinslb
gerryjenkinslb / seemingly_simple_number_puzzle.py
Last active October 11, 2018 23:28
seemingly simple number puzzle solutions with speed improvements
# uses python3 features
from time import time
# Fast solution for problem from Tomasz Nurkiewicz blog:
# https://www.nurkiewicz.com/2018/09/brute-forcing-seemingly-simple-number.html?utm_source=programmingdigest&utm_medium=email&utm_campaign=featured
# heuristic to greatly speed up from discussion of knights tour problem at
# https://runestone.academy/runestone/static/pythonds/Graphs/KnightsTourAnalysis.html
# by Gerry Jenkins see my channel youtube.com/gjenkinslbcc
@gerryjenkinslb
gerryjenkinslb / bst.py
Last active September 5, 2018 19:56
Simple immutable Binary Search Tree with insertion, contains and inorder Generator. (not balanced) 'demo of yield from'
# bst.py immutable Binary search tree (not balanced)
# using 'yield from' new in python 3.3
# start with tree = None
# nodes are a list of [value, left_tree, right_tree]
# every node is a subtree, so tree argument is a tree or subtree
def insert(tree, value):
""" creates tree if tree is None, returns new tree"""
if not tree: