Skip to content

Instantly share code, notes, and snippets.

View wasi0013's full-sized avatar
💤

Wasi wasi0013

💤
View GitHub Profile
@wasi0013
wasi0013 / convert_ascii_to_upside_down.py
Created January 10, 2024 02:07
Convert ASCII texts to upside down text.
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):
@wasi0013
wasi0013 / download_large_file.py
Created October 4, 2019 13:35
how to download large file using python, requests without exhausting device ram.
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)
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
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, "")
@wasi0013
wasi0013 / optimized_image_check.py
Created March 23, 2019 10:51
Find un-optimized images of a webpage using requests_html python
import requests_html
def unoptimized_images(url):
"""
find unoptimized images in a webpage
:param url: webpage_url
:return : tuple of image_count in int, images list of dict
"""
session = requests_html.HTMLSession()
response = session.get(url)
images = []
# 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))
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))
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)
@wasi0013
wasi0013 / download_file_using_python.py
Created October 4, 2019 13:59
How to download a file that requires custom headers and cookies
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')
@wasi0013
wasi0013 / download_tiny_file.py
Last active October 4, 2019 13:26
how to download tiny files using python requests
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)