Checking if list A is in list B

To chek if list A is completely included in list B – all elements of list A are present in list B, we can use the “superset” and “subset” methods of the standard Python “set” class.

Converting lists to sets also allows us not to worry about checking for duplicates if they exist in the compared lists.

subset

The “subset” method acts on a smaller set and checks if it is in a larger set.

HTML-CSS: Creating a fixed-width column on the right side of the page

When designing an HTML page, sometimes it is necessary to make a fixed-width sidebar on the right side of the page with dynamically filling all the remaining space on the left.

 

It is easiest to make this using the markup with tables, but it is quite possible with common “<div>” elements as well.

How to get the Discord channel Webhook URL

What is a “Webhook URL” in Discord and what is it for?

A Webhook URL is an address link that points to the server channel in Discord.

It looks like this:

You can send POST requests to this URL to automatically create posts in this Discord channel.

It is a powerful tool that can be used, for example, for newsletters on a channel, or cross-posting from social networks.

Python: how to zip a text string

In order to reduce the size of a long text string, for example, to minimize traffic when sending some text data over the Internet, it can be compressed before sending and unzipped after receiving. The size of transmitted data is significantly reduced in comparison with sending text strings in their original format.

To zip a text string in memory, we can use the “zlib” module.

Let’s use the “compress” function to compress the string. This function takes a byte string as an input parameter and returns the compressed byte string.

As we can see with this simplest example, the line size has been reduced by more than one and a half times.

Python: How to get the first found element in a list or None

To get the first element found in a list by some condition or None if nothing was found we can use the following construction:

With nothing found it returns None:

 

How to make directories with current data name in Total Commander

To quickly create directories with the name equal to the current date through the Total Commander:

  1. At first, let’s create a cmd script that makes a directory with the desired name:

In the first line of the script, the desired name for the directory is created in the format YYYY.MM.DD.

The second script line creates a directory with the specified name along the path passed in the input parameter %1

How to check what Python version is using?

To check what version of the Python interpreter is using to execute code, you can use the “version_info” command from the “sys” module:

In this exampleĀ the Python version 3.5.2. is using.

Automatic creation of Windows restore points

Creating Windows restore points is a good way to help to restore your computer if any troubles such as virus or advertising bots infection occur.

The restore point is a systemĀ image in which its current state is recorded (settings, appearance, installed programs). By creating and saving such a point, you can return your system to the recorded state at any time.

If you have opened a suspicious mail attachment accidentally, and now advertising banners appear on your computer screen (an advertising bot has been installed in your system) – with restore points you can return the system “back to the past” before the bot infects. Restore points are not absolutely troubles panacea, but very often, a “rollback” of the system saves the situation and returns the computer to a normal working state.

Python: How to get defined classes list from module (*.py file)

The list of classes defined in the * .py file can be obtained using the built-in module “inspect”.

For example, for the “test_cls” module:

we can get a list of classes with the followingĀ code:

 

PHP: How to export HTML to DOC

When developing online projects, it is often necessary to save the HTML page as a document that can be used separately, for example, sent by e-mail, viewed and edited offline. A convenient way is to export the HTML page to one of the most commonly used text formats – doc.

The free open-source PHP-module “html_to_doc” can be used to export the HTML page to the DOC document. It can convert the HTML to the DOC document, which will be correctly processed by the text editor MS Word. If the HTML page includes images, they will be embedded in the DOC document.

The PHP module can be downloaded from https://github.com/Korchy/html_to_doc

Python: How to walk through the list items in pairs from current to next

If we have a list:

in order to go through the elements of this list in pairs from the current to the next, we can use the following code:

Results:

 

Python: How to pass arguments as a list to a function that takes a variable number of arguments

Some functions take in their parameters a variable number of arguments *args, for example, theĀ itertools.product function.

In order to pass the list as the parameters to this function, we need to use the * operator:

 

Python: How to convert a string with mixed numbers and ranges of numbers to a list

Conversion of a string with both individual numbers and ranges of numbers to the list of integer values can be made as follows:

For example a line:

Split the line by comma delimiter:

Let’s split the resulting list into two lists. In the first list, we put only the individual values. In the second – the values got from the ranges of numbers.

Combine the lists into one and drop the duplicate values.

Complete code: