# number of occur
grep -c "error" logfile.txt
# show context lines before and after match
grep --context=6 successful logfile.txt
# case insensitive
grep -i
This file contains hidden or 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 | |
# for kasra :) | |
url = 'http://url:port/' | |
tools_url = 'http://url:port/tools_system.php' | |
password_css_id = "loginpwd" | |
login_button_css_id = "noGAC" | |
reboot_css_selector = "form:nth-child(9) input" |
This file contains hidden or 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
https://github.com/faif/python-patterns | |
https://github.com/satwikkansal/wtfpython | |
https://github.com/30-seconds/30-seconds-of-python#deep_flatten |
This file contains hidden or 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
class RootAccessException(Exception): | |
""" | |
Prevent running with Root Privileges | |
""" | |
pass | |
if os.getuid() == 0: | |
raise RootAccessException("Shouldn't run this script with Root Privileges") |
about comments why the code is doing a certain action, or why it’s doing something that is clear instead of something else that would feel more natural.
So comments can be, for me, a tool for lowering the cognitive load of the reader.
-
Function comments : prevent the reader from reading code in the first place, a form of in-line API documentation
-
Design comments : While a "function comment" is usually located at the start of a function, a design comment is more often located at the start of a file
-
Why comments : even if what the code is doing is crystal clear
This file contains hidden or 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
#!/bin/bash | |
ADDRESS='localhost' | |
PORT='5555' | |
STATE='SUCCESS' | |
LIMIT='1' | |
status=$(curl -s "$ADDRESS:$PORT/api/tasks?state=$STATE&limit=$LIMIT" | jq ".[].uuid") | |
if [ ! -z "$status" ]; |
sudo apt install logwatch and create cron.daliy to send email of logs with logwatch