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
''' comparing speed of new dataclass
with standard class attributes and slots,
running in 3.7.0b1'''
# subscribe to me: https://www.youtube.com/user/gjenkinslbcc?sub_confirmation=1
# I recommend reading PEP557: https://www.python.org/dev/peps/pep-0557/
# this code at gist: http://bit.ly/slotsVdatclass
from dataclasses import dataclass
from timeit import timeit
@gerryjenkinslb
gerryjenkinslb / seq_gen.py
Created March 10, 2018 20:18
convert sequences in string simular to "1,4,8-12,14" to generator of sequence 1,4,8,9,10,11,12,14
# gen sequence i.e. "1,3,5-7,9" > [1,3,5,6,7,9]
def seq_gen(s):
for item in s.split(','):
if '-' in item:
a, b = map(int, item.split('-'))
for i in range(a,b+1):
yield i
else:
if len(item):
yield int(item)
@gerryjenkinslb
gerryjenkinslb / hexgame.py
Last active March 9, 2018 23:27
A CLI game in python 2.7 or 3+ to learn binary to hexidecimal. Also example of code to run across versions of python.
# hexgame.py: to learn the hex digits for binary patterns
# written to run in python 2.7 and 3+
# Subscribe: https://www.youtube.com/user/gjenkinslbcc?sub_confirmation=1
from __future__ import division, print_function
from random import randrange
from time import time
import sys
hex_digits = '0123456789ABCDEF'
@gerryjenkinslb
gerryjenkinslb / elapsed.py
Last active March 6, 2018 22:29
Python3 elapsed time implementations in Class, Generator, and Functions for discussion and education
# elapsed timer: as generator
# Youtube subscribe link: https://goo.gl/ZgZrZ5
# Gerry Jenkins
import time
class ElapsedTime():
def __init__(self):
# store only start time
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.