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 flip(string): | |
"""Flips text upside down. | |
>>> flip("Hello World.") | |
'˙pןɹoM oןןǝH' | |
""" | |
d = {'a': 'ɐ', 'b': 'q', 'c': 'ɔ', 'd': 'p', 'e': 'ǝ', 'f': 'ɟ', 'g': 'ƃ', 'h': 'ɥ', 'i': 'ı', 'j': 'ɾ', 'k': 'ʞ', 'l': 'ן', 'm': 'ɯ', 'n': 'u', 'o': 'o', 'p': 'd', 'q': 'b', 'r': 'ɹ', 's': 's', 't': 'ʇ', 'u': 'n', 'v': 'ʌ', 'w': 'ʍ', 'x': 'x', 'y': 'ʎ', 'z': 'z', 'A': '∀', 'B': '𐐒', 'C': 'Ɔ', 'D': '◖', 'E': 'Ǝ', 'F': 'Ⅎ', 'G': '⅁', 'H': 'H', 'I': 'I', 'J': 'ſ', 'K': '⋊', 'L': '˥', 'M': 'W', 'N': 'N', 'O': 'O', 'P': 'Ԁ', 'Q': 'Ό', 'R': 'ᴚ', 'S': 'S', 'T': '⊥', 'U': '∩', 'V': 'Λ', 'W': 'M', 'X': 'X', 'Y': '⅄', 'Z': 'Z', '0': '0', '1': 'Ɩ', '2': 'ᄅ', '3': 'Ɛ', '4': 'ㄣ', '5': 'ϛ', '6': '9', '7': 'ㄥ', '8': '8', '9': '6', '.': '˙', ' ': ' ', '\n': '\n', '\t': '\t'} | |
return "".join(map(d.__getitem__, string))[::-1] | |
def unflip(string): |
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
defmodule Solution do | |
def run, do: get_input() |> part2() | |
def part1([child | [meta | data]]), do: calculate(data, child, meta, 0) | |
def calculate([], _child, _meta, sum), do: sum | |
def calculate(data, 0, 0, sum), do: {data, sum} | |
def calculate([hd | data], 0, meta, sum), do: calculate(data, 0, meta - 1, sum + hd) | |
def calculate([child, meta | data], pchild, pmeta, sum) do |
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
defmodule Solution do | |
def run, do: get_input() |> solve_part2() | |
def solve_part1(data), | |
do: data |> clean_ignored |> clean_garbage |> clean_comma |> count_score(1) | |
def count_score("", _depth), do: 0 | |
def count_score(<<?{>> <> rest, depth), do: depth + count_score(rest, depth + 1) | |
def count_score(<<?}>> <> rest, depth), do: count_score(rest, depth - 1) | |
def clean_ignored(data), do: Regex.replace(~r/!./, data, "") |
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
# Compute 333.75y6 + x2(11x2y2 – y6 – 121y4 – 2) + 5.5y8 + x/(2y) where x = 77617, y = 33096 | |
defmodule Pow do | |
# https://stackoverflow.com/a/32030190/3083094 | |
require Integer | |
def pow(_, 0), do: 1 | |
def pow(x, n) when Integer.is_odd(n), do: x * pow(x, n - 1) | |
def pow(x, n) do | |
result = pow(x, div(n, 2)) |
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 | |
import time | |
from pyvirtualdisplay import Display | |
from selenium import webdriver | |
document_url = "https://www.adobe.com/content/dam/acom/en/accessibility/products/acrobat/pdfs/acrobat-x-accessibility-checker.pdf" | |
download_dir = "/path/to/dir/" | |
# setup a virtual display using pyvirtualdisplay | |
display = Display(visible=0, size=(1768, 1368)) |
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 selenium import webdriver | |
import requests | |
username = "Your Username" | |
password = "Your Password" | |
driver = webdriver.Chrome() | |
# authenticate using username, password | |
login_url = "https://your.target_website.com/login/" | |
driver.get(login_url) |
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 requests | |
chunk_size = 4096 | |
filename = "logo.png" | |
document_url = "https://wasi0013.files.wordpress.com/2018/11/my_website_logo_half_circle_green-e1546027650125.png" | |
headers = { | |
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36", | |
"Connection": "keep-alive", | |
} | |
s = requests.Session() | |
cookie = requests.cookies.create_cookie('COOKIE_NAME','COOKIE_VALUE') |
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 requests | |
chunk_size = 4096 | |
filename = "logo.png" | |
document_url = "https://wasi0013.files.wordpress.com/2018/11/my_website_logo_half_circle_green-e1546027650125.png" | |
with requests.get(document_url, stream=True) as r: | |
with open(filename, 'wb') as f: | |
for chunk in r.iter_content(chunk_size): | |
if chunk: | |
f.write(chunk) |
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 requests | |
filename = "logo.png" | |
document_url = "https://wasi0013.files.wordpress.com/2018/11/my_website_logo_half_circle_green-e1546027650125.png" | |
with open(filename, 'wb') as f: | |
f.write(requests.get(document_url).content) |
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 requests_html | |
def crawl(base_url): | |
broken_links = [] | |
session = requests_html.HTMLSession() | |
try: | |
r = session.get(base_url) | |
except: | |
broken_links = [base_url] | |
return broken_links |
NewerOlder