Posts

Permanently automatically answer 'Yes' when using apt-get install - installing packages

Open your bashrc file sudo nano .bashrc 2. add the following alias apt-get='apt-get -y' And that's it. never have to press 'Y' when installing things again!

SNAPPED!

Remove https www from domain or URL string in Google Sheets

=trim(REGEXEXTRACT(REGEXREPLACE(REGEXREPLACE(A2;"https?://";"");"^(w{3}\.)?";"")&"/";"([^/?]+)"))

SNAPPED!

Executing Shell Commands with Python within a script

import os os.system("your_command_here")

SNAPPED!

Multi threading Python simple example

from multiprocessing import Pool def f(x): return x * x if __name__ == '__main__': with Pool(50) as p: print(p.map(f, [1, 2, 3, 2, 4, 5, 6, 7, 8, 9, 19]))

SNAPPED!

add space between lines of text HTML CSS

Use line height - css line-height: 0.7;

SNAPPED!

Setup Jenkins on Ubuntu 18.04 on AWS Lightsail

I couldn't find a guide for this - and I had to do this recently. So here goes! 1. Install Java sudo apt update && sudo apt install -y openjdk-8-jdk 2. Add the Jenkins Debian repository wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - 3. Add the repo to system sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' 4. Install Jenkins sudo apt update sudo apt install jenkins systemctl status jenkins 5. Add firewall rule In AWS lightsail > click on instance

SNAPPED!

Multi Line Comments Python

Multi Line Comments """ This is a comment This is a comment """

SNAPPED!

python print

python print print("Hi")

SNAPPED!

Commenting in Python

#This is a comment

SNAPPED!

Big list of selenium options + injecting cookies for testing

Use these options as you need! import csv import random import time from selenium.webdriver.chrome.options import Options from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.common.exceptions import NoSuchElementException import pickle option = Options() # option.add_argument("headless") # option.add_argument("window-size=1980,960") # option.add_argument("screenshot") # option.add_argument( # "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36") # option.add_argument("--enable-javascript") # option.add_argument("--disable-infobars") # option.add_argument("start-maximized") # option.add_argument("--disable-extensions") # option.add_argument("--start-maximized") # option.add_argument(&quo

SNAPPED!

Iterate or go through all files in a directory python

TEXT import os from tqdm import tqdm for filename in tqdm(os.listdir(directory)): if filename.endswith(".csv"): fp = os.path.join(directory, filename)

SNAPPED!

Deduplicate files all folders ubuntu

Use the awesome fdupes package: fdupes --noprompt -d -r ~/folder

SNAPPED!

Python requests passing JSON data (for API) boilerplate

Python requests passing JSON data (for API) boilerplate import requests payload = {'key1': 'value1', 'key2': 'value2'} r = requests.get('https://httpbin.org/get', params=payload)

SNAPPED!

Python requests

Python requests boilerplate import requests url = 'URL_HERE' response = requests.get(url) print(url.status_code) content = response.content print(content)

SNAPPED!

Coding croc logo

Image

SNAPPED!

Can't execute 'conda activate' from bash script

Conda init you no longer need to add conda to path manually. Now we have the conda init command: step 1 conda init

SNAPPED!

How to comment out code in a bash or shell script

Comments bash script   single line:  #    multi line:  /*  */

SNAPPED!

Remove all duplicate files from folder and all sub directories linux ubuntu

Use the awesome fdupes package: fdupes --noprompt -d -r ~/folder

SNAPPED!

Embed HTML using prism

Use the language-markup class and replace the first < of each line with  &lt; Example: <pre class="language-markup" id="answer"><code>&lt;a href="your landing page url">     &lt;img src="your image url" /> &lt;/a></code></pre>

SNAPPED!

Make a link clickable HTML

TEXT <a href="your landing page url"> <img src="your image url" /> </a>

SNAPPED!

Append to a json file python

How to append to a json file python - the quick way import json your_dictionary = {'a_new_key': 'a_new_value'} with open('a_json.json') as a_file: data = json.load(a_file) data.update(your_dictionary) with open('a_json.json', 'w') as f: json.dump(data, f)

SNAPPED!

prettify or clean a JSON with python

prettify or clean a JSON with python import json with open('cover_letter_text_parsed_v3.json', 'r') as a_file: parsed = json.load(a_file) with open('cover_letter_text_parsed_v3_clean.json', 'w') as a_file: json.dump(a_file, handle, indent=4, sort_keys=True)

SNAPPED!

Read a JSON file python

Image
Read Json using json.load with open('a_file.json') as file: data = json.load(file) SEND TO YOURSELF, SAVE FOR LATER, OR SHARE WITH YOUR TEAM! SNAPPED!

SNAPPED!

print exception python except statement

Image
except Exception as e: print(str(e)) SEND TO YOURSELF, SAVE FOR LATER, OR SHARE WITH YOUR TEAM! SNAPPED!

SNAPPED!

get all hrefs on page selenium python

Image
elems = driver.find_elements_by_xpath("//a[@href]") for elem in elems: print(elem.get_attribute("href")) Or see shorter snippets below: .find_elements_by_xpath("//a[@href]") driver.find_elements_by_xpath("//a[@href]") SEND TO YOURSELF, SAVE FOR LATER, OR SHARE WITH YOUR TEAM! SNAPPED!

SNAPPED!

Convert HTML to Text Python

Image
html2text  is a great library for this and easy to use! import html2text plain_text = html2text.html2text("<p>I am HTML</p>") SEND TO YOURSELF, SAVE FOR LATER, OR SHARE WITH YOUR TEAM! SNAPPED!

SNAPPED!

Generate a random Number between 0 and 1 (or 0 and less than 1) python

Image
import random random.uniform(0, 1) SEND TO YOURSELF, SAVE FOR LATER, OR SHARE WITH YOUR TEAM! SNAPPED!

SNAPPED!

Tool for formatting inputs for selenium css selectors for multi class names (with spaces) - selenium python

Image
When you use selenium to select an element with multiple classes using driver.find_element_by_css_selector(), you need to replace spaces with dot notation. For example, To select The following element:  <i align="center" class="far fa-copy croc-copy-icon">  you 'll need to use the following selector with dot notation formatting: driver.find_element_by_css_selector(".far.fa-copy.croc-copy-icon”) Having to replace spaces with full stops over and over again can get repetitive and time-consuming especially for lengthy classes. Here is a quick script I use to replace all spaces with dots, and add a dot at the beginning of the string. I found this can save quite a bit of time import pyperclip text = "a really long multi class element t-14 t-black--

SNAPPED!

Get all child elements Selenium python inner HTML (innerHTML)

Image
You can use the get_attribute() method .get_attribute('innerHTML') SEND TO YOURSELF, SAVE FOR LATER, OR SHARE WITH YOUR TEAM! SNAPPED!

SNAPPED!

Infinite scroll selenium python

Image
One way to handle infinite scroll is by using the height of the viewport. Here we continue to scroll until the viewport height before and after does not change, hence, all elements on the page have been loaded import time def scroll_infinite(driver, wait_time, number_of_times_to_scroll): # Current scroll height current_height = driver.execute_script("return document.body.scrollHeight") while True and number_of_times_to_scroll > 0: # Scroll to bottom of page driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") # Wait for new content to load time.sleep(wait_time) # Calculate new scroll height n_height = driver.execute_script("return document.body.scrollHeight") if n_height == current_height: break number_of_times_to_scroll -= 1 current_height

SNAPPED!

Popular posts from this blog

Append to a json file python

Setup Mailhog mail server on Ubuntu