- GitHub Staff
- https://tippybits.com
- @dtaivpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Courtesy of https://stackabuse.com/sorting-algorithms-in-python/ | |
def partition(nums, low, high): | |
# We select the middle element to be the pivot. Some implementations select | |
# the first element or the last element. Sometimes the median value becomes | |
# the pivot, or a random one. There are many more strategies that can be | |
# chosen or created. | |
pivot = nums[(low + high) // 2] | |
i = low - 1 | |
j = high + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Occurances will track each time an offensive bit of code is found | |
# Its format will be: | |
# File Path, Function, Num Occurances | |
occurances = [] | |
# Methods that need to be update | |
nogos = [ | |
".SetFocus(", | |
".IsValid(", | |
".Clear", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
walk_dir = 'C:\\Directory\\ForWalking\\' | |
# If the file path contains these we dont want them | |
# eg. C:\\Directory\\ForWalking\\node_modules will be ignored | |
exclusions = ["node_modules", "SolutionFiles", ".bin", "Test"] | |
# Array to store all our file paths | |
file_paths = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from time import time | |
random.seed(time()) | |
#### List Access Tests #### | |
times = {'colsAndRows': 0, 'rowsAndCols': 0} | |
def generateArray(size): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from time import time | |
random.seed(time()) | |
times = {'listComprehension': 0, 'append': 0, 'preAllocate': 0} | |
for i in range(0,100): | |
endRange = random.randint(100_000, 10_000_000) | |
startTime = time() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DiscordHandler(logging.Handler): | |
""" | |
Custom handler to send certain logs to Discord | |
""" | |
def __init__(self): | |
logging.Handler.__init__(self) | |
self.discordWebhook = DiscordWebhook(url=config.DISCORD_URL) | |
def emit(self, record): | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
posts = [ | |
{ | |
'Post': { | |
'title':'Other today post', | |
'date': 43750, | |
'claps': 200 | |
} | |
}, | |
{ | |
'Post': { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def memoize(f): | |
""" Memoization decorator for functions taking one or more arguments. """ | |
class memodict(dict): | |
def __init__(self, f): | |
self.f = f | |
def __call__(self, *args): | |
return self[args] | |
def __missing__(self, key): | |
ret = self[key] = self.f(*key) | |
return ret |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Initialization | |
list = ["Lists", "Is", "Pretty", "Sweet"] | |
# Assigning an index a new value | |
list[1] = "Are" | |
# Extending a list | |
list.append("Cool") | |
# Removeing from the end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Initialization | |
dictionary = {'string key': "string value", | |
('tuple', 'key'): {'dict': "value"}, | |
123: "Value for int key"} | |
# Assign a key a new value | |
dictionary[123] = "New Value" | |
# Retrieve all keys from a dictionary | |
keys = dictionary.keys() |