Skip to content

Instantly share code, notes, and snippets.

Avatar
🤖

Wasi Mohammed Abdullah wasi0013

🤖
View GitHub Profile
View rumps_royal_pain.ex
# 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))
View download_pdf_using_js_print_pdf_with_chromedriver_selenium.py
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))
View download_file_with_authentication.py
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 Oct 4, 2019
How to download a file that requires custom headers and cookies
View download_file_using_python.py
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_large_file.py
Created Oct 4, 2019
how to download large file using python, requests without exhausting device ram.
View download_large_file.py
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_tiny_file.py
Last active Oct 4, 2019
how to download tiny files using python requests
View download_tiny_file.py
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 / find_broken_links.py
Last active Mar 25, 2019
Find all the broken links from a website.
View find_broken_links.py
@wasi0013
wasi0013 / optimized_image_check.py
Created Mar 23, 2019
Find un-optimized images of a webpage using requests_html python
View optimized_image_check.py
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 / http_version.py
Created Mar 23, 2019
HTTP/2 Test using requests_html by parsing keycdn website https://tools.keycdn.com/http2-test
View http_version.py
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")
View keybase.md

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: