How to Zip and Encode a Dictionary to String and 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 import json, gzip, base64 from io import BytesIO def _zip_then_encode(data: dict) -> str: """Gzip and base64 encode a dictionary""" if type(data) != dict: raise TypeError("data must be a dictionary") compressed = BytesIO() with gzip....

February 22, 2023 · 1 min · 168 words · Andrew

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....

February 17, 2023 · 2 min · 233 words · Andrew

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: import random Then you can use it like this: random.randint(0, 255) Another option is to use randrange and uniform as follows: 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)

February 16, 2023 · 1 min · 75 words · Andrew

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: brew tap aws/tap brew install aws-sam-cli Now you can validate the installation as follows: sam --version

February 15, 2023 · 1 min · 39 words · Andrew

How to count the amount of rows in MariaDB fast

If you need to find the fastest way to count the number of rows in a massive MariaDB, or MySQL table, then you can do the following instead of performing a select count() query: show table status like '<TABLE_NAME>' This will provide you with a table of information about the table statistics, including the amount of rows.

February 11, 2023 · 1 min · 57 words · Andrew

How to find the Product of Consecutive Fib Numbers in Python

0, 0, 1, 0, 2, 0, 2, 2, 1, 6, 0, 5, 0, 2, 6, 5, 4, 0, 5, 3, 0, 3, … This is the Van Eck’s Sequence. Let’s go through it step by step. Term 1: The first term is 0. Term 2: Since we haven’t seen 0 before, the second term is 0. Term 3: Since we had seen a 0 before, one step back, the third term is 1 Term 4: Since we haven’t seen a 1 before, the fourth term is 0 Term 5: Since we had seen a 0 before, two steps back, the fifth term is 2....

February 10, 2023 · 2 min · 375 words · Andrew

How to Solve Van Eck's Sequence in Python

0, 0, 1, 0, 2, 0, 2, 2, 1, 6, 0, 5, 0, 2, 6, 5, 4, 0, 5, 3, 0, 3, … This is the Van Eck’s Sequence. Let’s go through it step by step. Term 1: The first term is 0. Term 2: Since we haven’t seen 0 before, the second term is 0. Term 3: Since we had seen a 0 before, one step back, the third term is 1 Term 4: Since we haven’t seen a 1 before, the fourth term is 0 Term 5: Since we had seen a 0 before, two steps back, the fifth term is 2....

February 9, 2023 · 2 min · 375 words · Andrew

How to Solve: Help the Bookseller Challenge in Python

A bookseller has lots of books classified in 26 categories labeled A, B, … Z. Each book has a code c of 3, 4, 5 or more characters. The 1st character of a code is a capital letter which defines the book category. In the bookseller’s stocklist each code c is followed by a space and by a positive integer n (int n >= 0) which indicates the quantity of books of this code in stock....

February 8, 2023 · 3 min · 627 words · Andrew

How to solve AWS MediaPackage PackagingGroup Quota Limit

If you are using AWS Elemental MediaPackage and hit the following error, then you need to either do one of the following: Error: error waiting for CloudFormation Stack (arn:aws:cloudformation:eu-west-1:800417762774:stack/dev-MediaPackage-Vod-1/511fc7a0-a092-11ed-b853-068baf6ac251) create: failed to create CloudFormation stack, delete requested (DELETE_COMPLETE): ["The following resource(s) failed to create: [PackagingGroup]. Delete requested by user." "Resource handler returned message: \"Limit exceeded for resource of type 'AWS::MediaPackage::PackagingGroup'. Reason: You reached the quota for resource=PackagingGroup. Delete the resources that you don?...

January 31, 2023 · 1 min · 126 words · Andrew

How to Run Cdk Bootstrap

To bootstrap an AWS CDK environment, you simply need to do the following: npx aws-cdk bootstrap …for each environment that you would like the CD to operate within. This will deploy all the required prerequisites to the AWS account, such as the: An Amazon S3 bucket for storing files and IAM roles that grant permissions needed to perform deployments. The required resources are defined in an AWS CloudFormation stack, called the bootstrap stack, which is usually named CDKToolkit....

January 30, 2023 · 1 min · 95 words · Andrew