InputHint
InputHint – JQUERY/PHP plugin that adds hints with variants of the entered text to input fields, with the possibility of their selection by the user, and filling the field with text from the selected hint.
InputHint – JQUERY/PHP plugin that adds hints with variants of the entered text to input fields, with the possibility of their selection by the user, and filling the field with text from the selected hint.
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.
1 2 3 4 5 6 7 8 9 10 11 12 |
import zlib long_text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' print('long_text', len(long_text)) long_text_compressed = zlib.compress(long_text.encode('utf-8')) print('long_text_compressed', len(long_text_compressed)) # long_text 445 # long_text_compressed 270 |
As we can see with this simplest example, the line size has been reduced by more than one and a half times.
To add a program link to the Windows Explorer (“My Computer”) context menu – we need to edit the Windows registry.
The windows registry editor must be opened with administrator rights. Now we need to make the following changes:
How to add a program link to the Windows Explorer context menuRead More »
Widget for Elementor page builder plugin for WordPress. It allows you not to show your e-mail on your pages explicitly to prevent gathering it by web-spiders and robots for spam. Visitors will see your e-mail address after clicking a “show e-mail” button.
To get the first element found in a list by some condition or None if nothing was found we can use the following construction:
1 2 3 4 |
elements_list = ['One', 'Two', 'Three'] element = next(iter([e for e in elements_list if e in ['One', 'Two']]), None) print(element) # 'One' |
With nothing found it returns None:
1 2 3 |
element = next(iter([e for e in elements_list if e in ['Four', 'Five']]), None) print(element) # None |
Some default parameters in GIMP can be set using the gimprc file.
To quickly create directories with the name equal to the current date through the Total Commander:
1 2 |
set dir_name=%date:~6,4%.%date:~3,2%.%date:~0,2% md "%1%dir_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 make directories with current data name in Total CommanderRead More »
To check what version of the Python interpreter is using to execute code, you can use the “version_info” command from the “sys” module:
1 2 3 4 |
import sys print(sys.version_info) # sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0) |
In this example the Python version 3.5.2. is using.
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.
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:
1 2 3 4 5 6 7 |
## test_cls.py class Test1: pass class Test2: pass |
we can get a list of classes with the following code:
1 2 3 4 5 6 7 8 |
## test.py import inspect classes = [cls_name for cls_name, cls_obj in inspect.getmembers(sys.modules['test_cls']) if inspect.isclass(cls_obj)] print(classes) # ['Test1', 'Test2'] |
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
If we have a list:
1 |
my_list = ['one', 'two', 'three', 'four'] |
in order to go through the elements of this list in pairs from the current to the next, we can use the following code:
1 2 |
for first, next in zip(my_list, my_list[1:]): print(first, next) |
Results:
1 2 3 |
one two two three three four |
Some functions take in their parameters a variable number of arguments *args, for example, the itertools.product function.
1 2 3 |
list(itertools.product(['a', 'b'], [1, 2])) # [('a', 1), ('a', 2), ('b', 1), ('b', 2)] |
In order to pass the list as the parameters to this function, we need to use the * operator:
1 2 3 4 5 |
my_list = [['a', 'b'], [1, 2]] list(itertools.product(*my_list)) # [('a', 1), ('a', 2), ('b', 1), ('b', 2)] |
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:
1 |
src = '1, 3-5, 8' |
Split the line by comma delimiter:
1 |
linearr = [s.strip() for s in re.split(r'[,;]+| ,', src) if s] |
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.
1 2 |
linearrframes = [int(i) for i in linearr if '-' not in i] linearrdiapasones = sum([list(range(int(i.split('-')[0]), int(i.split('-')[1]) + 1)) for i in linearr if '-' in i], []) |
Combine the lists into one and drop the duplicate values.
1 2 |
linearrframes.extend(linearrdiapasones) print(list(set(linearrframes))) |
Complete code:
1 2 3 4 5 6 7 8 9 |
src = '1, 3-5, 8' print(src) linearr = [s.strip() for s in re.split(r'[,;]+| ,', src) if s] linearrframes = [int(i) for i in linearr if '-' not in i] linearrdiapasones = sum([list(range(int(i.split('-')[0]), int(i.split('-')[1]) + 1)) for i in linearr if '-' in i], []) linearrframes.extend(linearrdiapasones) print(list(set(linearrframes))) # '1, 3-5, 8' # [1, 3, 4, 5, 8] |
PHP supports the Late Static Bindings mechanism. The full class name with static inheritance we can get by calling the function:
1 |
get_called_class() |
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?php class Parent { public static function getName() { echo get_called_class(); } } class Child extends Parent { } Parent::getName(); Child::getName(); ?> // Parent // Child |
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:
1 |
lst = [1,2,3,4,5] |
forward:
1 2 3 4 |
lst = lst[1:] + lst[:1] print(lst) [2, 3, 4, 5, 1] |
and backward:
1 2 3 4 |
lst = lst[-1:] + lst[:-1] print(lst) [1, 2, 3, 4, 5] |
If a cyclic shift is necessary, repeat this command the required number of times in “for” cycle.
To check the version of the Linux Debian installed on the server, type the following command:
1 |
lsb_release -a |
The operation system response:
1 2 3 4 5 |
No LSB modules are available Distributor ID: Debian Description: Debian GNU/Linux 9.1 (n/a) Release: 9.1 Codename: n/a |
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.
1 2 3 4 5 6 7 8 |
class TestObj: def __init__(self, x, y): self.__x = x self.__y = y def __repr__(self): return "TestObj({x},{y})".format(x = self.__x, y = self.__y) |
The dictionary with objects:
1 |
datadict = {"group": {"Object1": TestObj(10,22), "Object2": TestObj(36,74)}} |
Saving the dictionary to JSON:
1 2 3 4 |
with open("c:/file.json", "w", encoding="utf-8") as file: import pprint pprint.pprint(datadict, indent=4, stream=file) file.close() |
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:
1 2 3 4 5 6 7 8 |
a = ((1, 2), (3, 4)) print(a) # ((1, 2), (3, 4)) b = (5, 6) print(b) # (5, 6) a += b print(a) # ((1, 2), (3, 4), 5, 6) |
In order an added tuple to become nested, put a comma “,” after an added tuple:
1 2 |
a += b, print(a) # ((1, 2), (3, 4), (5, 6)) |
Obtaining the “centroid” – convex polygon central point coordinates, from polygons points (vertices) coordinates:
1 2 3 4 5 6 7 |
def centroid(vertexes): _x_list = [vertex [0] for vertex in vertexes] _y_list = [vertex [1] for vertex in vertexes] _len = len(vertexes) _x = sum(_x_list) / _len _y = sum(_y_list) / _len return(_x, _y) |
The input function parameter is a tuple with coordinates of the polygon points. The function returns a tuple with the centroid coordinates:
1 2 |
polygon_data = ((0, 0), (1, 0), (1, 1), (0, 1)) print(centroid(polygon_data)) # (0.5, 0.5) |
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:
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:
1 2 3 4 5 6 7 |
a = 0 print(a) b = [1,3,7] print(b) for a in b: pass print(a) |
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.
1 2 3 4 |
# output > 0 # print(a) > [1, 3, 7] # print(b) > 7 # print(a) after loop execution |
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.
To check how match time code execution takes you need to frame checking code with following instructions:
1 2 3 4 5 6 7 |
<?php $StartTime = microtime(true); // Checking code sleep(rand(5,10)); // End of checking code echo "Executed for: ".(microtime(true)-$StartTime)." sek."; ?> |
This example result:
Executed for: 8.9997079372406 sek.
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 |
mklink %2 %1 |
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 |
%P%N %T%N |
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 language has no internal multiline comment syntax (like \* … *\ in other languages). There are two ways to solve this:
1 2 3 4 |
''' this is multiline comment second comment row ''' |
Disadvantage of this way is that such comment remains constant string and processed in finished code.
To remove comments from multiple commented strings select them and press Ctrl + / again.