Skip to content

Instantly share code, notes, and snippets.

View wasi0013's full-sized avatar
💤

Wasi wasi0013

💤
View GitHub Profile
from abc import ABC, abstractmethod
class Polygon(ABC):
@abstractmethod
def area(self):
pass
@abstractmethod
def perimeter(self):
@wasi0013
wasi0013 / keybase.md
Created March 14, 2019 14:42
keybase proof

Keybase proof

I hereby claim:

  • I am wasi0013 on github.
  • I am wasi0013 (https://keybase.io/wasi0013) on keybase.
  • I have a public key ASCAGYNlyVRTqJo6mqNbusXrz5U2eWcFuYYLhCB4EkhYfAo

To claim this, I am signing this object:

@wasi0013
wasi0013 / http_version.py
Created March 23, 2019 10:31
HTTP/2 Test using requests_html by parsing keycdn website https://tools.keycdn.com/http2-test
import requests_html
def http2_enabled(url):
"""
scrape https://tools.keycdn.com/http2-test to find http 2/0 support of the given domain url
"""
url = url.replace("https://", "").replace("http://", "")
session = requests_html.HTMLSession()
response = session.get("https://tools.keycdn.com/http2-test")
@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 = []
@wasi0013
wasi0013 / find_broken_links.py
Last active March 25, 2019 06:15
Find all the broken links from a website.
@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)
@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)
@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')
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)
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))