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:

 

PHP: How to get the full class name with static inheritance

PHP supports the Late Static Bindings mechanism. The full class name with static inheritance we can get by calling the function:

Example:

 

Python: How to shift values in a list

To shift values in a list (replace the value at the first place of the list to its last place and vice versa), you need to rearrange the list with two slices.

The shift for the list:

forward:

and backward:

If a cyclic shift is necessary, repeat this command the required number of times in “for” cycle.

How to find out the Linux Debian version

To check the version of the Linux Debian installed on the server, type the following command:

The operation system response:

Python: how to save a dictionary with objects to JSON

Each object’s class to be stored in JSON in a convenient for viewing way must have the __repr__ function, which returns the text representation of the object.

The dictionary with objects:

Saving the dictionary to JSON:

 

Python: how to enclose a tuple in a tuple

Tuples in python can be nested.

If simply add one tuple to another through the concatenation operation “+”, python will merge the values of the tuples:

In order an added tuple to become nested, put a comma “,” after an added tuple:

 

Python: How to find the polygon center coordinates

Obtaining the “centroid” – convex polygon central point coordinates, from polygons points (vertices) coordinates:

The input function parameter is a tuple with coordinates of the polygon points. The function returns a tuple with the centroid coordinates:

 

How to start working with Git and GitHub

Version control systems for today are almost mandatory for any project. One of the most popular version control systems is Git. Consider working with Git in conjunction with GitHub – the largest hosting server for the deployment of IT-projects of joint development. GitHub allows publishing open source projects for free.

In this article, we start to work with Git and GitHub on the Windows operating system.

What we need, in order to start our work with Git:

  1. Download the Git distribution for windows:
    1. https://git-scm.com/download/win
  2. Install Git on the user’s computer
    1. All installing options can be set “by default”

The for loop counter in Python does not have a local scope

One of the for loops features in Python is that the iterated variable (counter) does not belong to the local scope of the loop.

For example, after executing the following code:

The “a” variable declared before the for loop will change its value if the variable with the same name “a”  declared as the loop counter.

It is necessary to remember about this feature, in order to avoid writing to the previously declared variable the values of the iterator of the for loop.

How to check code execution time in PHP

To check how match time code execution takes you need to frame checking code with following instructions:

This example result:

Executed for: 8.9997079372406 sek.

How to create symbolic links in Total Commander

Symbolic links in Windows (starts from Vista) can be created using mklink command.

Let’s make a button in Total Commander to create a symbolic link from the selected file:

  1. In a convenient location, for example in Total Commander plug-ins directory c:\TotalCommander\Plugins\ create a batch file mklink.cmd with the following content:

This command creates a symbolic link to the file transferred from the first input parameter and places it in a location from the second input parameter.

  1. Create a button in Total Commander panel by dragging this file to this panel.
  2. Right click on this button and select “Edit …”
    1. In the “Settings” field specify:

Save changes.

%P – path to the file under the cursor in active panel

%N – the name of the file under the cursor in active panel

%T – path to the location, open in a second (non-active) panel

As a result by pressing created button a symbolic link to the file under the cursor in the active Total Commander tab will be created in a location of the inactive tab with the same file name.

Python – multiline comment in PyCharm

Python language has no internal multiline comment syntax (like \* … *\ in other languages). There are two ways to solve this:

  1. Use multiline string literal syntax: ′′′

Disadvantage of this way is that such comment remains constant string and processed in finished code.

  1. If the PyCharm IDE is used to write Python code – select multiple code rows to comment and press keyshot Ctrl + / to comment all of them.

To remove comments from multiple commented strings select them and press Ctrl + / again.

Sending parameters to external javascript file *.js

Setting input parameters in *.html file:

 

Getting parameters in external javascript file *.js