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
import pygame as pg
import math
from pygame.locals import *
"""
thick_aaline(surface, color, point0, point1, width)
draw a anti-aliased line from point1 to point2 with given width
The algorithms computes the corners (a, b, c, and d)
that form the borders of the thick line and then draws a filled
@gerryjenkinslb
gerryjenkinslb / PointV.txt
Last active July 27, 2018 22:15
Showing dynamic Class/Object possibilites using object.__dict__ in Python 3.6+
Lessons in dynamic attributes for a class using self.__dict__
From python.org documents:
object.__dict__ :
A dictionary or other mapping object
used to store an object’s (writable) attributes.
Learn to object.__dict__ for:
1. Setting defaults for the classes/object attributes
from __future__ import division # we need floating division
from svg.path import Path, Line, Arc, CubicBezier, QuadraticBezier, parse_path
import pygame
""" demo of using a great python module svg.path by Lennart Regebro
see site: https://pypi.org/project/svg.path/
to draw svg in pygame
"""
from svg.path import Path, Line, Arc, CubicBezier, QuadraticBezier, parse_path
# This examples runs only in python 3.+ versions since Tkinter was changed
from svg.path import Path, Line, Arc, CubicBezier, QuadraticBezier, parse_path
from tkinter import Tk, Canvas, Frame, BOTH
""" demo of using a great python module svg.path by
Lennart Regebro see site: https://pypi.org/project/svg.path/
to draw svg in Tkinter
"""
from svg.path import Path, Line, Arc, CubicBezier, QuadraticBezier, parse_path
from __future__ import division # for running in 2.7+ python
from svg.path import Path, Line, Arc, CubicBezier, QuadraticBezier, parse_path
import turtle
""" demo of using a great python module svg.path by Lennart Regebro see site: https://pypi.org/project/svg.path/
to draw svg in Tkinter
"""
svgpath = """m 76,232.24998 c 81.57846,-49.53502 158.19366,-20.30271 216,27 61.26714,59.36905 79.86223,123.38417 9,156
-80.84947,31.72743 -125.19991,-53.11474 -118,-91 v 0 """
@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:
@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

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.
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)
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