Last active
May 13, 2021 20:27
-
-
Save UnderGrounder96/f03832b610419084bbb5e1c6a96229f8 to your computer and use it in GitHub Desktop.
random_notes
This file contains 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
#!/usr/bin/env bash | |
# https://linuxhint.com/3hr_bash_tutorial/ | |
# https://ryanstutorials.net/ | |
: ' | |
This is a | |
multi-line | |
comment | |
' | |
# Stop script on Not zero exit | |
set -e | |
# Stop script if unbound variable found (use ${var:-} if intentional) | |
set -u | |
# By default cmd1 | cmd2 returns exit code of cmd2 regardless of cmd1 success | |
# This is causing it to fail | |
set -o pipefail | |
bash -x filename | "#!/bin/bash -x" | set -x; code; set +x # debug | |
cat << EOF > file | |
Lines to be inside | |
the file; I guess | |
EOF | |
echo $@ # print args arr | |
echo $# # length | |
echo "x" >file.txt 2>&1 # redirects STDERR to STDIN | |
echo "enter text1" | |
read text1 | |
echo "enter text2" | |
read text2 | |
declare hello=hello # sets shell variable | |
myArray=('this' 'is' 'an' 'array') | |
echo ${myArray[@]} # prints entire array | |
# unset myArray[1] # removes element | |
myArray[1]='no' | |
length=${#myArray[@]} | |
indexes=${!myArray[@]} | |
if [ "$text1" \< "$text2" ]; then | |
echo "$text1 is smaller than $text2" | |
else | |
echo "the opposite is true" | |
fi | |
echo ${text1^} # lowercase | |
echo ${text1^a} # letter to lowercase | |
echo ${text2^^} # uppercase | |
count=10 | |
if [ $count -le 4 ]; then | |
echo "count is less or equal to 4 : $count" | |
elif (( $count >= 5 && $count <= 9 )); then | |
echo "count is between to 5 and 9 : $count" | |
else | |
echo "count is greater than 9 : $count" | |
fi | |
case $count in | |
1) | |
echo "count is 1" | |
;; # break | |
*) | |
echo "unknown count" | |
;; | |
esac | |
i=1 | |
while [ $i -ge 2]; do # same as until | |
echo "$i" | |
i=$(( i+1 )) | |
done | |
: ' | |
while read line; do | |
echo $line | |
done < ${1:-/dev/stdin} | |
' | |
# for (( i=0; i<5; i++ )) | |
for i in {0..5..2}; do #start..end..increment | |
echo "$i" | |
done | |
select variable in A B C; do | |
case $variable in | |
A) | |
echo "A selected" | |
;; | |
B) | |
echo "B selected" | |
;; | |
C) | |
echo "B selected" | |
;; | |
*) | |
echo "ERROR! Please select between 1..3" | |
esac | |
done | |
echo "Press any key" | |
while [ true ]; do | |
read -t 3 -n 1 # retries reading every (-t) 3s | |
if [ $? = 0 ]; | |
echo "Thank you for the input" | |
break | |
else | |
echo "Waiting for inpunt!" | |
fi | |
done | |
# numbers and arithmetics | |
n1=3 | |
n2=2 | |
echo $(( n1 % n2 )) | |
echo $(expr $n1 \* $n2 ) | |
echo $(( n1 / n2 )) # prints int | |
function main(){ | |
# more code here | |
: | |
} | |
main | |
echo "Enter path to check dir" | |
read file | |
if [ -f "$file" ]; then | |
while IFS="" read -r line; do | |
echo "$line" | |
done < $file # reading file, line by line | |
echo "directory \"$direct\" exists" | |
fi | |
curl -O ${url} # Download file as it's named in upstream | |
curl ${url} -o newName == curl ${url} > newName | |
curl -I ${url} # prints (header) info about the file |
This file contains 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 baseImage # specifies base image | |
LABEL maintainer="UnderGrounder96" | |
ENV hello "Yo!" | |
WORKDIR /root # changes pwd, creates dir | |
# similar to ADD, but doesn't extract from compressed files | |
COPY . /tmp/ # copies . to /tmp, inside the container | |
#COPY [".", "/tmp"] # same as above | |
RUN echo "$hello" # runs sys commands | |
CMD echo "$hello" # executes this command during container boot, appears once per Dockerfile |
This file contains 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
# ============================================================ | |
git clone --bare git@my.pretty.ip.address:user/old_repo.git # '--bare' excludes working files | |
cd old_repo | |
git push --mirror --force http://my.website/user/new_repo.git | |
# ============================================================ | |
git submodule foreach git pull origin master | |
# equals | |
git submodule update --init --recursive --remote #--merge # merge forces download | |
# ============================================================ | |
git fetch --all -p # sync branches with remote, removes local branches not on origin | |
git diff <hash5> <hash256> # Compares files | |
git diff --binary > foo # saves altered binary files | |
git reset # Resets working dir to before changes | |
git checkout file # Resets file | |
git commit --amend -m "New Message" # Replaces last message | |
git add -A # adds all | |
git commit --amend # Adds files to last commit | |
git log --stat # Shows the files in each commit | |
git log -n 5 | |
git cherry-pick # Creates a new commit; but doesn't delete old commits | |
git clean -df # Removes all non-tracking dir and files | |
git reflog # Shows commits history [permanent] | |
git revert <hash5> # Creates new commits on top of old commits |
This file contains 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
#!/usr/bin/env groovy | |
// https://www.jenkins.io/doc/book/pipeline/syntax/ | |
def gv, FAILED_STAGE | |
pipeline { | |
agent { label 'foo && bar' } // or any | |
environment { | |
MY_VAR = "MY_VALUE" | |
AWS_ACCESS_KEY_ID = credentials('jenkins-aws-secret-key-id') // credentials() can only be accessed from enviroment directive | |
AWS_SECRET_ACCESS_KEY = credentials('jenkins-aws-secret-access-key') | |
} | |
parameters { | |
string(name: "Version_A", defaultValue: "Version_A", description: "string") | |
choice(name: "VERSION", choices: ['1.1.0', '1.7.0', '2.3.0'], description: "this is a description") | |
booleanParam(name: "bool", defaultValue: false, description: "boolean") | |
} | |
options { | |
disableConcurrentBuilds() | |
preserveStashes buildCount: 5 // preserve stash at least 5x (for stage test) | |
timestamps() // provides timestamps for outputs | |
} | |
stages { | |
stage('gitlab') { // needs to be setup | |
steps { | |
echo 'Notify GitLab' | |
updateGitlabCommitStatus name: 'build', state: 'pending' | |
updateGitlabCommitStatus name: 'build', state: 'success' | |
script { | |
FAILED_STAGE=${env.STAGE_NAME} | |
} | |
} | |
} | |
stage('para') { | |
parallel { | |
stage('apple') { | |
steps { | |
println("apple 1") | |
sleep(20 * Math.random()) | |
println("apple 2") | |
script { | |
FAILED_STAGE=${env.STAGE_NAME} | |
} | |
} | |
} | |
stage('banana') { | |
steps { | |
println("banana 1") | |
sleep(20 * Math.random()) | |
println("banana 2") | |
script { | |
FAILED_STAGE=${env.STAGE_NAME} | |
} | |
} | |
} | |
} | |
} | |
stage('Load'){ | |
steps { | |
script { | |
gv = load "groovy/script.groovy" | |
FAILED_STAGE=${env.STAGE_NAME} | |
} | |
} | |
} | |
stage ('Build'){ | |
steps { | |
echo "Building the project..." | |
echo "Your ${MY_VAR}" | |
script { | |
gv.my_function() | |
FAILED_STAGE=${env.STAGE_NAME} | |
} | |
sh 'make build' | |
stash includes: '*.jar', name: 'my_stash_name' // Stash available for next stages | |
} | |
} | |
stage ('Test'){ | |
when { | |
expression { | |
params.bool // Stage test will only execute if params.bool is true | |
} | |
} | |
steps { | |
echo "Testing the project..." | |
script { | |
gv.not_my_function() | |
FAILED_STAGE=${env.STAGE_NAME} | |
} | |
unstash 'my_stash_name' | |
sh 'bash my_script.sh' | |
} | |
} | |
} | |
post { | |
always { | |
echo 'This will always run' | |
} | |
success { | |
echo 'This will run only if successful' | |
script { | |
manager.addBadge("star-gold.gif", "Successful build") | |
} | |
echo 'WARNING: Archiving the project artifacts' | |
archiveArtifacts artifacts: '*.jar,*.log*' | |
} | |
failure { | |
echo 'This will run only if unsuccessful' | |
script { | |
manager.addBadge("error.gif", "Failed build") | |
} | |
echo "Failed stage name: ${FAILED_STAGE}" | |
} | |
unstable { | |
echo 'This will run only if the run was marked as unstable' | |
} | |
changed { | |
echo 'This will run only if the state of the Pipeline has changed' | |
echo 'For example, if the Pipeline was previously failing but is now successful' | |
} | |
} | |
} |
This file contains 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://kubernetes.io/docs/reference/kubectl/cheatsheet/ | |
### kubectl apply commands in order | |
# REPO: https://gitlab.com/UnderGrounder96/mongo_app | |
kubectl apply -f mongo-secret.yaml | |
kubectl apply -f mongo-db.yaml | |
kubectl apply -f mongo-configmap.yaml | |
kubectl apply -f mongo-express.yaml | |
### kubectl get commands | |
kubectl get pod | |
kubectl get pod --watch | |
kubectl get pod -o wide | |
kubectl get service | |
kubectl get secret | |
kubectl get all | grep mongodb | |
### kubectl debugging commands | |
kubectl describe pod mongodb-deployment-xxxxxx | |
kubectl describe service mongodb-service | |
kubectl logs mongo-express-xxxxxx | |
### give a URL to external service in minikube | |
minikube service mongo-express-service |
This file contains 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
#!/usr/bin/env bash | |
sudo !! # executes last command with sudo | |
cat file | tr "[a-z]" "[A-Z]" # converts to uppercase | |
cat file | tr "[A-Z]" "[a-z]" # converts to lowercase | |
awk '/LA/ {print}' file # prints lines with LA | |
find . -name *.rpm | xargs mv -t dest_dir/ # moves found rpms | |
find . -name *.rpm -print | xargs rm # removes found rpms | |
env -i command # executes command in 'empty' env | |
df -h # disk free | |
sudo du -h -d 1 / # disk usage | |
# recursively wget files from RMPS folder | |
wget -np -r -nH --cut-dirs=4 -e robots=off -R "index.html*" --no-check-certificate https://my.pretty.ip/path_to_dir/path_to_version/random_path/rpms/ | |
# https://www.bogotobogo.com/Linux/linux_shell_programming_tutorial3_special_variables.php |
This file contains 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
pip install -U pip # upgrage, already installed package pip | |
pip freeze > requirements.txt # saves "env packages" to requirements | |
pip list # more formal than freeze | |
pip show pip # show more details about pip |
This file contains 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
WebDriverWait(self.browserChrome, Locators.base_sleep) # max_time to wait, if it happens to be true before it continues | |
################################################################################ | |
browser | |
.title # title | |
.current_url # current_url | |
.page_source # HTML page code | |
.maximize_window() # maximize_window | |
.implicitly_wait(5) # it doesn't pause the script!!! Wait 5sec for the page or element to load, every time, callable only once! | |
.quit() # exists the entire browser | |
.close() # closes one tab | |
.back() / .forward() # goes back and forward | |
.refresh() | |
.save_screenshot(full_path_to_file) | |
.find_element_by_id("id") # find_element_by_id | |
.is_enabled() / .is_displayed() / .is_selected() # found_elements' functions | |
.clear() # clears | |
################################################################################ | |
# Select (click) from drpDown | |
from selenium.webdriver.support.ui import Select | |
drpDown = Select(driver.find_element_by_id("ok")) | |
drpDown.select_by_visible_text("my text") | |
#drpDown.select_by_index(2) # empty options tags count towards index | |
#drpDown.select_by_value("my val") # from value attribute in the option tag | |
#print(len(drpDown.options)) | |
for option in drpDown.options: | |
option.text | |
################################################################################ | |
# link text - a tag | |
links = driver.find_elements(By.TAG_NAME, "a") | |
print("All my links: ", len(links)) | |
for link in links: | |
print(link.text) | |
driver.find_element(By.LINK_TEXT, "Register").click() | |
driver.find_element(By.PARTIAL_LINK_TEXT, "Reg") | |
################################################################################ | |
# alerts | |
#driver.find_element(By.XPATH, "//*[@id='bread_crumb_activity_stream']/i") | |
driver.find_element_by_xpath("//*[@id='bread_crumb_activity_stream']/i") | |
time.sleep(5) | |
driver.switch_to_alert() | |
.accept() # pesses ok, on the alert | |
.dismiss() # pesses ok, on the alert | |
################################################################################ | |
#frames / iframes | |
driver.switch_to.frame("name / id") | |
driver.find_element(By.LINK_TEXT, "Register").click() | |
time.sleep(3) | |
driver.switch_to.default_content() | |
time.sleep(3) | |
driver.switch_to.frame("name / id") | |
driver.find_element(By.LINK_TEXT, "Register").click() | |
################################################################################ | |
driver.find_element(By.LINK_TEXT, "Register").click() #opens new tab | |
print(driver.current_window_handle) # current open tab | |
print(len(driver.window_handles)) # all tabs in the browser | |
for handle in driver.window_handles: | |
driver.switch_to.window(handle) | |
print(driver.title) | |
if driver.title == "first title": | |
driver.close() # closes the active tab | |
driver.quit() # exits the entire browser | |
################################################################################ | |
# table | |
rows=len(driver.find_element_by_xpath("/home/body/table/tbody/tr")) # number of rows | |
cols=len(driver.find_element_by_xpath("/home/body/table/tbody/tr[1]/th")) # number of columns | |
print(f"rows: {rows}, columns: {columns}") | |
for r in range(2, rows+1): | |
for c in range(1, cols+1): | |
value=driver.find_element_by_xpath(f"/home/body/table/tbody/tr[{r}]/th[{c}]") | |
print(value, end=" ") | |
print() | |
################################################################################ | |
# scroll down the page | |
drive.maximize_window() | |
driver.execute_script("window.scrollBy(0,1000), "") | |
elem=driver.find_element... | |
# driver.execute_script("arguments[0].scrollIntoView();", elem) | |
# driver.execute_script("window.scrollBy(0,document.body.scrollHeight), "") | |
################################################################################ | |
# mouse operations | |
from selenium.webdriver.common.action_chains import ActionChains | |
# find all elems to hove | |
ActionChains(driver) | |
.move_to_element(elem1) # hover | |
.move_to_element(elem2) | |
.move_to_element(elem3).click() | |
#.double_click(elem4) | |
#.context_click(elem5) # right-click | |
.drag_and_drop(source_elem,target_elem) | |
.perform() # without perfom nothing is done | |
################################################################################ | |
# upload file | |
#driver.switch_to.frame(‘name / number’) #switches to form | |
driver.find_element_by_id("noy_ID").send_Keys("Full/path/to/file.png") | |
#press submit | |
################################################################################ | |
from selenium.webdriver.chrome.options import Options | |
chromeOptions=Options() | |
chromeOptions.add_experimental_option("prefs", {"download.default_directory":"/full/path"}) # sets defautl download folder | |
driver=webdriver.Chrome(executable_path="asdasd", chrome_options=chromeOptions) | |
# sleep for some time | |
click.toDownloadfile() | |
################################################################################ | |
# handling cookies | |
print(len(driver.get_cookies())) | |
print(driver.get_cookies()) | |
driver.add_cookie({"name": "foo", "value": "bar"}) | |
driver.delete_cookie("foo") | |
driver.delete_all_cookies() | |
################################################################################ | |
# screenshots | |
driver.save_screenshot("/full/path/to/save/screenshot.png") # any extension | |
driver.get_screenshot_as_file("/full/path/to/save/screenshot.png") # only .png | |
################################################################################ | |
# logging | |
import logging # auto appends to the log file | |
logging.basicConfig( #https://docs.python.org/3/library/logging.html#logging.basicConfig | |
filename="myfile.log", #name saves on pwd, /full/path saves to path | |
format="%(asctime)s: %(levelname)s: %(message)s", | |
datefmt="%d/%b/%y %H:%M:%S", # https://docs.python.org/3/library/time.html#time.strftime | |
#level=logging.DEBUG # set below | |
) | |
# by default it ignores debug and info. level above, makes it start from debug. | |
# Debug > Info > Warning > Error > Critical | |
logger=logging.getLogger() | |
logger.setLevel(logging.DEBUG) | |
logger.debug("Message") | |
################################################################################ | |
# unittest | |
@unittest.SkipTest #decorator | |
def test_sa... | |
@unittest.skip("I'm providing a reason for why skipping test_as ") #skipping with a reason | |
def test_as... | |
@unittest.skipIf(1==1, "Skipping because numbers are equal") #skipping based a condition | |
def test_as... | |
assertEqual(elem1, elem2, "Message in case it fails") | |
assertIn("Python", [list, turple...]) | |
assertGreater(a,b) | |
assertGreaterEqual(a,b) | |
assertLess(a,b) | |
assertLessEqual(a,b) | |
assertIsNone(a) | |
assertIsNotNone(b) | |
################################################################################ | |
# links | |
https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.command.Command.IS_ELEMENT_ENABLED | |
https://www.selenium.dev/selenium/docs/api/py/webdriver/selenium.webdriver.common.by.html?highlight=selenium.webdriver.common.by#selenium.webdriver.common.by | |
https://www.selenium.dev/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html | |
https://www.selenium.dev/selenium/docs/api/py/index.html | |
https://selenium-python.readthedocs.io/installation.html | |
https://www.youtube.com/watch?v=0eeq0A6rc_E&list=PLUDwpEzHYYLvx6SuogA7Zhb_hZl3sln66&index=6 | |
TO WATCH: https://www.youtube.com/watch?v=BURK7wMcCwU |
This file contains 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
--- | |
- Volvo : | |
year_founded: 1232 | |
website: volvo.com | |
founded_by: | |
- Andrei | |
- Kot | |
- Bugatti: | |
year_founded: 12354 | |
website: bugatti.com | |
founded_by: | |
- Andrei | |
- Kot | |
- Ferrari: | |
year_founded: 12354 | |
website: ferrari.net | |
founded_by: | |
- Andrei | |
- Kot | |
- Mercedez: | |
year_founded: 12354 | |
website: mercedez.org | |
founded_by: | |
- Andrei | |
- Kot | |
- Bentley: | |
year_founded: 12354 | |
website: bentley.jkl.lo | |
founded_by: | |
- Andrei | |
- Kot | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment