This file contains 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
from struct import pack, unpack | |
def inv_sqrt(n: float) -> float: | |
n_half = n / 2 | |
n_hex = hex(unpack('>l', pack('>f', n))[0]) | |
magic_num = '0x5f3759df' | |
guess_int = int(magic_num, 16) - (int(n_hex, 16) >> 1) | |
guess_float = unpack('>f', pack('>l', guess_int))[0] | |
better_guess = guess_float*(1.5 - n_half*guess_float**2) | |
return better_guess |
This file contains 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 calkin_wilf_sequence(number): | |
def fractions(): | |
from fractions import Fraction | |
i = Fraction(1/1) | |
while True: | |
yield [i.numerator, i.denominator] | |
i = Fraction(1 / (2*int(i) - i + 1)) | |
gen = fractions() | |
res = 0 |
This file contains 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
from itertools import permutations, dropwhile | |
def n_queens(n: int) -> list: | |
"""An adaptation of the eight queens puzzle for any positive integer n > 3. | |
:param - n: a positive integer representing the number of rows, columns, and queens to solve for. | |
:return - queen_squares: a list of 2-tuples representing the (0-based) squares to place the queens on, such that no | |
queen is attacked / guarded by another.""" | |
if n < 4: | |
return ["Do it yourself."] |
This file contains 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 timing(f): | |
from time import time | |
def timed(*args, **kwargs): | |
start = time() | |
r = f(*args, **kwargs) | |
end = time() | |
print("Time elapsed: {} seconds".format(end-start)) | |
return r | |
return timed |
This file contains 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
from xml.parsers.expat import ParserCreate, ExpatError, errors | |
from functools import partial | |
def start_element(name, attrs, out, depth): | |
depth.append(1) | |
if out.get(name, None) == None: | |
out[name] = {} | |
out[name]["attributes"] = set() | |
out[name]["loc"] = len(out) - 1 | |
out[name]["depth"] = sum(depth) |
This file contains 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 json | |
from collections import OrderedDict | |
def replace_values(d): | |
for k in d: | |
if isinstance(d[k], dict): | |
d[k] = replace_values(d[k]) | |
elif isinstance(d[k], float): | |
d[k] = int() | |
else: |
This file contains 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
from collections import OrderedDict | |
def parse_directory_paths(calls): | |
calls_dict = OrderedDict() | |
paths = [] | |
for c in calls: | |
s = c.split("/")[1:] | |
paths.append(s) | |
for p in paths: | |
if p[0] not in calls_dict: | |
calls_dict[p[0]] = {} |
This file contains 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
2020-08-28 17:01:28:921 - [HTTP] --> POST /wd/hub/session {"desiredCapabilities":{"automationName":"UiAutomator2","deviceName":"Android","platformName":"Android","appiumVersion":"1.17.0","newCommandTimeout":0,"orientation":"PORTRAIT","browserstack.is_hub_canary":"false","acceptSslCert":false,"detected_language":"appium/ruby_lib_core/3.11.0 (selenium/3.142.7 (ruby macosx))","new_bucketing":true,"device":"samsung galaxy s9","sessionName":"Android Event Type Location Details: Physical location appears in location section of Event Type details","buildName":"August 2020 Test Development","projectName":"Test Project","platform":"ANDROID","os_version":"8.0","chromeOptions":{"w3c":false},"browserstack.minOSVersion":"6.0","appPackage":"com.calendly.app.dev","appActivity":"com.calendly.app.splash.SplashActivity","bundleID":"com.calendly.app.dev","bundleId":"com.calendly.app.dev","nativeWebScreenshot":true,"version":"","mobile":{"browser":"mobile","version":"Samsung Galaxy S9-8.0"},"browserstack.appDownloadTimeout":"90" |