Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Webb CodeDrome

View GitHub Profile
View squarerootestimates.py
import numpy as np
def _nparray_to_sci_not(radicands):
exponents = np.log10(radicands).astype(int)
significands = radicands / 10**exponents
return {"significands": significands, "exponents": exponents}
View siunits.py
import sibaseunit as sibu
def main():
print("----------------------")
print("| codedrome.com |")
print("| SI Units in Python |")
print("| Part 1: Base Units |")
print("----------------------\n")
View sibaseunit.py
from types import MappingProxyType
class SIBaseUnit(object):
"""
The SIBaseUnit class provides properties for
representing values of the 7 SI base units,
multiplier prefixes such as kilo and nano,
methods for string representation,
View setdemo.py
import setutilities as su
def main():
print("-----------------")
print("| codedrome.com |")
print("| Set Demo |")
print("-----------------\n")
View setutilities.py
from types import MappingProxyType
symbols = MappingProxyType({ "emptySet": "∅",
"union": "∪",
"intersection": "∩",
"is_element_of": "∈",
"is_not_element_of": "∉",
"is_subset_of": "⊆",
"is_proper_subset_of": "⊂",
View jumbledtextdemo.py
import textjumbler
def main():
print("------------------")
print("| codedrome.com |")
print("| Jumbled Text |")
print("------------------\n")
View xor.py
a = 45 # 00101101 = 45
b = 99 # 01100011 = 99
a = a ^ b # 01001110 = 78 (irrelevant intermediate value)
b = a ^ b # 00101101 = 45
a = a ^ b # 01100011 = 99
View textjumbler.py
import random
from datetime import datetime
def jumble(text, amount):
"""
Jumbles the letters (except first and last) of the words
in text. Amount is a decimal between 0.0 and 1.0 and
specifies the amount of jumbling to be carried out.
View eratosthenes.py
import degree
def main():
print("------------------------")
print("| codedrome.com |")
print("| Eratosthenes and the |")
print("| Size of Planet Earth |")
print("------------------------\n")
View degree.py
class Degree(object):
def __init__(self, degrees = 0, minutes = 0, seconds = 0):
self._seconds = self._seconds_from_dms(degrees, minutes, seconds)
def __str__(self):
dms = self.get()