Skip to content

Instantly share code, notes, and snippets.

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"
# 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 
https://github.com/faif/python-patterns
https://github.com/satwikkansal/wtfpython
https://github.com/30-seconds/30-seconds-of-python#deep_flatten
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

@yzdann
yzdann / README-Template.md
Created August 28, 2019 13:18 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

#!/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" ];
@yzdann
yzdann / jqcheatsheet.md
Created August 21, 2019 14:45 — forked from talwrii/jqcheatsheet.md
jq cheatsheet

jq cheatsheet

Extract field from list of objects

jq 'map(.foo)'

[ { foo: 1 }, { foo: 2 } ]
[1, 2]

print function

# unpack list with space
print(*['jdoe is', 42, 'years old'])

# seprator
print('node', 'child', 'child', sep=' -> ')

# prevent line break
print('The second sentence', end='. ')

sudo apt install logwatch and create cron.daliy to send email of logs with logwatch