Skip to content

Instantly share code, notes, and snippets.

View uluQulu's full-sized avatar
🚙
Coding ...

Şəhriyar Cəfər Qulu uluQulu

🚙
Coding ...
  • Azərbaycan
View GitHub Profile
@uluQulu
uluQulu / TamahkarAxtarış_alqoritmi (tam)
Last active October 24, 2022 20:12
Tam işlək Tamahkar Axtarış alqoritmi (yol məsələləri üçün)
"""
Tamahkar Alqoritma ilə yol məsələsini həll edək.
- Qarşıda 2 üsul var:
1. Node-lar open node listine gore secilir, yuksek heuristici olan secilir.
2. Node-lar ancaq qarsidaki yola gore secilir, meselen bu misalda, elaqesi olmayan node-a kecmek mumken deyil
- Məs., E-dən D-yə keçmək olmaz, çünki yol yoxdur-qonşuluq yoxdur).
3. Normal Greedy axtarış aparılsın, open node-lar işlədilsin; Hər open node-un heuristic məsafəsi yadda saxlanılsın.
- Buna görə də node-swithcing algorithm işlədiyi müddətcə path-per-path aparılacaq. Cavab isə insan yeriyəbiləcəyi tam path olacaq.
- Seçilən node-un (switched) tam path-i qeyddə qalır.
@uluQulu
uluQulu / tamahkar_alqo
Last active October 22, 2022 20:24
Tamahkar axtarışın alqoritmasinin "Yol Məsələsinə" tətbiqi
"""
Tamahkar Alqoritma ilə yol məsələsini həll edək.
- Qarşıda 2 üsul var:
1. Node-lar open node listine gore secilir, yuksek heuristici olan secilir.
2. Node-lar ancaq qarsidaki yola gore secilir, meselen bu misalda, elaqesi olmayan node-a kecmek mumken deyil
- Məs., E-dən D-yə keçmək olmaz, çünki yol yoxdur-qonşuluq yoxdur).
"""
import concurrent.futures
@uluQulu
uluQulu / customized_geckodriverdownloader.py
Created September 1, 2019 22:37
Subclass GeckoDriverDownloader in order to fix a bug in arch level detection.
class CustomizedGeckoDriverDownloader(GeckoDriverDownloader):
"""
Subclass GeckoDriverDownloader in order to fix finding accurate arch.
"""
def get_download_url(self, version="latest"):
"""
Default of this method finds arch of the python interpreter rather than OS.
To view the original source of this method, go to:
@uluQulu
uluQulu / github.css
Created February 1, 2019 21:50 — forked from andyferra/github.css
Github Markdown CSS - for Markdown Editor Preview
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
body > *:first-child {
@uluQulu
uluQulu / implicit_vs_explicit.md
Created December 23, 2018 20:52
Clash: implicit wait ⚔ explicit wait

There are some points to be taken into account:

1-) implicit wait has the highest priority
It currently is being controlled with page_delay parameter with the default value of 25

  • page_delay parameter is customizable by user
  • User can give it 1 seconds if likes

2-) What is implicit wait?

  • implicit wait sets the [max] time it can wait while finding elements

3-) What is explicit wait?

@uluQulu
uluQulu / truncate_float.py
Last active November 4, 2018 17:18
Truncate (shorten) a floating point value at given precision.
def truncate_float(number, precision, round=False):
""" Truncate (shorten) a floating point value at given precision """
# don't allow a negative precision [by mistake?]
precision = abs(precision)
if round:
# python 2.7+ supported method [recommended]
short_float = round(number, precision)
@uluQulu
uluQulu / explicit_wait.py
Last active October 29, 2018 19:44
Generic explicit wait function for InstaPy to be used with selenium webdriver
def explicit_wait(browser, track, ec_params, logger, timeout=35, notify=True):
"""
Explicitly wait until expected condition validates
:param browser: webdriver instance
:param track: short name of the expected condition
:param ec_params: expected condition specific parameters - [param1, param2]
:param logger: the logger instance
"""
# list of available tracks:
@uluQulu
uluQulu / new_tab.py
Last active September 1, 2018 16:49
Open a new tab; Do stuff in it; Close it
@contextmanager
def new_tab(browser):
""" USE once a host tab must remain untouched and yet needs extra data- get from guest tab """
try:
# add a guest tab
browser.execute_script("window.open()")
# switch to the guest tab
browser.switch_to.window(browser.window_handles[1])
yield
@uluQulu
uluQulu / find_user_id.py
Created August 28, 2018 13:56
Finds user ID from page content
def find_user_id(browser, username, logger):
try:
user_id = browser.execute_script(
"return window._sharedData.entry_data.PostPage[0].graphql.shortcode_media.owner.id")
except WebDriverException:
try:
browser.execute_script("location.reload()")
user_id = browser.execute_script(
"return window._sharedData.entry_data.PostPage[0].graphql.shortcode_media.owner.id")
except WebDriverException:
@uluQulu
uluQulu / ping_server.py
Last active August 23, 2018 17:13
A universal server ping tool
def ping_server(host):
"""
Returns True if host (str) responds to a ping request.
Remember that a host may not respond to a ping (ICMP) request even if the host name is valid.
"""
# Ping command count option as function of OS
param = "-n" if system().lower()=="windows" else "-c"
# Building the command. Ex: "ping -c 1 google.com"
command = ' '.join(["ping", param, '1', str(host)])