Skip to content

Instantly share code, notes, and snippets.

View CodeDrome's full-sized avatar

Chris Webb CodeDrome

View GitHub Profile
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
@CodeDrome
CodeDrome / textjumbler.py
Created August 11, 2022 12:09
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.
@CodeDrome
CodeDrome / eratosthenes.py
Created May 9, 2022 15:36
eratosthenes.py
import degree
def main():
print("------------------------")
print("| codedrome.com |")
print("| Eratosthenes and the |")
print("| Size of Planet Earth |")
print("------------------------\n")
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()
@CodeDrome
CodeDrome / baconscipherdemo.py
Created April 27, 2022 13:30
baconscipherdemo.py
import baconscipher
def main():
print("------------------")
print("| codedrome.com |")
print("| Bacon's Cipher |")
print("------------------\n")
@CodeDrome
CodeDrome / baconscipher.py
Created April 27, 2022 13:28
baconscipher.py
def encipher(plaintext, target_text):
"""
Encipher plaintext to target text with binary 0
as lower case and binary 1 as upper case
"""
# remove all non-alphabetic characters
# from plaintext and convert to upper case
plaintext = ''.join([c for c in plaintext if c.isalpha()]).upper()
@CodeDrome
CodeDrome / quadrilateralareascoordinatesmain.py
Created March 30, 2022 14:50
quadrilateralareascoordinatesmain.py
import quadrilateralareascoordinates
def main():
print("-----------------------------------")
print("| codedrome.com |")
print("| Calculating Areas of |")
print("| Quadrilaterals from Coordinates |")
print("-----------------------------------\n")
@CodeDrome
CodeDrome / quadrilateralareascoordinates.py
Created March 30, 2022 14:48
quadrilateralareascoordinates.py
def calculate_area(c):
'''
Calculates the area of any quadrivaletral
from a list of x,y coordinates in the following format:
[[x1,y1],[x2,y2],[x3,y3],[x4,y4]]
'''
first = c[0][0]*c[1][1] + c[1][0]*c[2][1] + c[2][0]*c[3][1] + c[3][0]*c[0][1]
@CodeDrome
CodeDrome / bretschneidersformulamain.py
Created March 28, 2022 16:00
bretschneidersformula.py
import bretschneiderformula
def main():
print("---------------------------------------")
print("| codedrome.com |")
print("| Calculating Areas of Quadrilaterals |")
print("| With Bretschneider's Formula |")
print("---------------------------------------\n")
@CodeDrome
CodeDrome / bretschneidersformulamain.py
Created March 28, 2022 15:58
bretschneidersformulamain.py
from functools import reduce
import math
def calculate_area(sides, opposite_angles_degrees):
'''
Calculate the area of a quadrilateral using Bretschneider's Formula
from the lengths of the sides and either pair of OPPOSITE angles.
Arguments:-