What options exist for Infrastructure as Code (IaC)

There are several options for Infrastructure as Code (IaC) tools that can help automate the provisioning and management of infrastructure resources, such as servers, networks, and storage, in a reliable and reproducible way. Here are some of the most popular IaC options: Terraform: An open-source tool by HashiCorp that supports a wide range of infrastructure providers, including AWS, Azure, Google Cloud, and more. Terraform uses a declarative language to describe infrastructure as code and can manage both low-level and high-level resources.

How to learn Java in 1 day

Learning Java in one day is not a realistic goal, as Java is a complex programming language that requires time and practice to master. However, here are some tips to get you started: Start with the basics: Before diving into complex topics, learn the basics of Java, such as variables, data types, control structures, and object-oriented programming principles. Watch tutorials and read documentation: There are many resources available online that can help you learn Java quickly.

How to read user input as numbers in Python

In Python 3 onwards, the input function returns a string type.. int value You can explicitly convert this into an int type. 1 val = int(input("Enter a number: ")) float value If you need to accept fractional components, then simply swap this out with a float type: 1 val = float(input("Enter a number:")) map multiple values If you have multiple integers in a single line, then you can use map to extract them into a list:

Capitalize First Letter of Each Word in Python

If you have a sentence containing multiple words, and you want each of the words to start with a capital letter, then you can do one of the following: Option 1 - using string.capwords() 1 2 3 import string string.capwords('this is a test!') Output: 'This Is A Test!' Option 2 - using title() 1 'this is a test!'.title() Output: 'This Is A Test!' Option 3 - using join(), split() and list comprehensions 1 " ".

How to Create a Password Generator in Python

You can easily create a password generator in Python with the following simple method. How to create the Password Generator in Python 1 2 3 4 5 6 7 8 9 import string import random def generate_password(length=16): seed = f"{string.ascii_letters}{string.ascii_lowercase}{string.ascii_uppercase}{string.punctuation}" password_string = [x for x in seed] random.shuffle(password_string) return ''.join(password_string[:length]) How to use the Password Generator in Python With this function, you can either call the generate_password() function without any arguments, and it will generate a 16 digit long password, unless you need a longer one, then pass in an integer to specify the lengh of the password you would like.

How to Convert Bytes to a String in Python

If you need to convert bytes to a string in Python, then you can do the following: 1 2 your_string = b'This works \xE2\x9C\x85'.decode("utf-8") print(your_string) Output: 1 This works ✅ Note that in the above example, we have converted a utf-8 string to.

How to measure the elapsed time in Python

Option 1 - using the time module 1 2 3 4 5 6 7 8 import time start = time.time() print(23*2.3) end = time.time() print(end - start) Output: 1 2 52.9 3.600120544433594e-05 Option 2 - using the timeit module 1 2 3 4 5 6 7 8 from timeit import default_timer as timer start = timer() print(23*2.3) end = timer() print(end - start) Output: 1 2 52.9 6.355400000000039e-05

How to Change a MariaDB/MySQL Data Directory to a New Location on Linux

Step 1 — Moving the MariaDB Data Directory 1 mysql -u root -p 1 select @@datadir; 1 2 3 4 5 6 7 Output: +-----------------+ | @@datadir | +-----------------+ | /var/lib/mysql/ | +-----------------+ 1 row in set (0.00 sec) 1 exit 1 2 sudo systemctl stop mariadb sudo systemctl status mariadb 1 2 Output: mysql systemd[1]: Stopped MariaDB database server. 1 sudo rsync -av /var/lib/mysql /mnt/my-volume-01 1 sudo mv /var/lib/mysql /var/lib/mysql.

[Solved] Docker Daemon Connection Error: Daemon Running?

If you get the following error when trying to run a Docker container: Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running? Then you can resolve it by running the following: 1 systemctl start docker If this doesn’t work because of a root user issue, then you can do the following first: 1 gpasswd -a $USER docker Additional issues? Issue 1 If you have tried the above, and get this error:

[Solved] M1 Docker Image Platform Mismatch with Host (ARM64)

If you get the following error when trying to run a Docker container that was built on an M1 mac: M1 docker preview and keycloak 'image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8)' Issue The solution Then you can do simply add the following argument to your docker build command. 1 --platform linux/amd64 Where this goes 1 docker build --platform linux/amd64 -t your_docker_item .

How to get the SHA512 sum of a string using Python

If you need to get the SHA512 sum of a string using Python, then you can do the following. Step 1 Firstly, we need to use the hashlib module: 1 import hashlib Step 2 Now make sure that the input string is encoded correctly. 1 your_input = "this is your input string".encode('utf-8') Step 3 Finally use the sha512 function of the hashlib module, and get the hexdigest() value from it:

How to get the SHA256 sum of a string using Python

If you need to get the SHA256 sum of a string using Python, then you can do the following. Step 1 Firstly, we need to use the hashlib module: 1 import hashlib Step 2 Now make sure that the input string is encoded correctly. 1 your_input = "this is your input string".encode('utf-8') Step 3 Finally use the sha256 function of the hashlib module, and get the hexdigest() value from it:

How to get the MD5 sum of a string using Python

If you need to get the MD5 sum of a string using Python, then you can do the following. Step 1 Firstly, we need to use the hashlib module: 1 import hashlib Step 2 Now make sure that the input string is encoded correctly. 1 your_input = "this is your input string".encode('utf-8') Step 3 Finally use the md5 function of the hashlib module, and get the hexdigest() value from it:

[Solved] TypeError: datetime Not JSON Serializable

If you get the following error: TypeError: Object of type datetime is not JSON serializable ..then you can solve it by using this trick: 1 json.dumps(your_dict, indent=4, sort_keys=True, default=str)

How to Return a List of All AWS Lambda Function Names in CLI

If you would like to list all AWS Lambda Function Names in your CLI using the AWS CLI, then you can do this: Get a List of all Lambda Functions 1 aws lambda list-functions However, note that this will return a potentially large JSON payload back to your CLI. So what if you only want a list of the function names themselves? You can couple the AWS command above, with the jq command as follows:

How much faster is Python code?

The speed of Python code compared to other programming languages depends on a variety of factors, such as the specific task being performed, the libraries and frameworks used, the quality of the code implementation, and the hardware on which the code is executed. In general, Python is an interpreted language, which means that code is executed line-by-line by an interpreter, rather than being compiled into machine code beforehand. This can make Python code slower than compiled languages like C or C++ for some tasks.

Zip & Encode Dict to String & Back in Python

If you have a Python dictionary, and want to encode it as a string and zip it to save space, perhaps for passing a dictionary through as an environment variable or similar, then you can do the following Zip then Encode / Decode then Unzip Functions 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import json, gzip, base64 from io import BytesIO def _zip_then_encode(data: dict) -> str: """Gzip and base64 encode a dictionary""" if type(data) !

What Categories of Websites are there?

There are many different categories of websites, but here are some of the most common: E-commerce websites: These websites sell products or services online. Examples include Amazon, eBay, and Etsy. News websites: These websites provide up-to-date news and information on a variety of topics. Examples include CNN, BBC, and The New York Times. Blogging websites: These websites are used for personal or business blogs. Examples include WordPress, Blogger, and Medium.

How to Generate a Random Number between 2 numbers in Python

If you need to generate a random number between two (2) numbers in Python, then you can make use of the random module. First, import the module: 1 import random Then you can use it like this: 1 random.randint(0, 255) Another option is to use randrange and uniform as follows: 1 2 3 4 5 6 7 from random import randrange, uniform # randrange gives you an integral value irand = randrange(0, 10) # uniform gives you a floating-point value frand = uniform(0, 10)

How to Install AWS SAM CLI on Mac

If you need to install AWS SAM CLI on a Mac, then the easiest option is to use Homebrew with the following commands: 1 2 brew tap aws/tap brew install aws-sam-cli Now you can validate the installation as follows: 1 sam --version