Dig a Python’s regex trench… or not.

Let’s talk about not so clearly viewed but important thing as regex execution sequence.

Let’s imagine, we have a list of strings:

sarr = [ 'kitty.env', 'doggy-bone.env', 'dog-plum.env', 'dog-bone.as', 'dog-pass-bone1.env', 'dog-shout.env', 'kitty-paw.as', 'doggy-pitstop.env', ];

and we need to match any string ‘^dog.*\.env$’, but not contained ‘-bone[0-9]*’

So, the matches sould be: 3rd, 6th and 8th strings

Referer docs: python’s regex

The first what cames into the head is the following:

>>> [re.match(r'^dog.*(?!-bone[0-9]*)\.env$', s) is not None for s in sarr] [False, True, True, False, True, True, False, True]

“Whuuuut?” it was my first reaction. A few minutes later with colleague’s help, we’ve found the solution, here it is:

>>> [re.match(r'^dog(?!.*-bone[0-9]*).*\.env$', s) is not None for s in sarr] [False, False, True, False, False, True, False, True]

Seems, as you can guessed, python’s regex have sequentially processing of conditional rules

So, in the first case using human words:

1) Does string is starts with 'dog'?
2) Keep in mind any-characters sentence, mark them.
3) Does string contains '-bone[0-9]*'?
    No? OK.
    Yes? I could quit, BTW, it got match to previous rule, then OK.
4) Does string ends with '\.env'

When the second could reads as:

1) Does string starts with 'dog'?
2) Does string contains any sentence '.*-bone[0-9]*'? Yes? This isn't our case, quit.
3) Does string ends with sentence '.*\.env'?

That’s it. I hope, this post helps you or you’ve got a new piece of knowledge.

HH

New blog’s home and cpu managment

The story has a beginning in 2013. Me and my friend got node (aka physical server) in data center for free by marketing company for a year.

Time was going, a year has ended, but DC owners didn’t do anything with it. So, we lived on node until a couple weeks ago they are remembered about and were asked us to renew the contract with a charge or they’ll shut the server down.

Continue reading

Upgrade Fedora… manually.

Fedora’s manual (any many other copy-paste blogs, damn) describes the following steps to upgrade system:

sudo dnf update --refresh sudo fedup download --releasever=24 --allowerasing sudo fedup reboot

Guys, don’t worry about “fedup” it’s just an alias script to “dnf system-upgrade”

I did that steps, reboot finished aaaand.. nothing! F23 on the board yet.
Sure, the post not about happy end and easy way (:

Continue reading

TAR: Speed up compression on multicore systems

This is a little tip to speed up creating tar archive.

By default tar using gzip to compress and if you look at htop output, gzip use only one cpu.

Tar have an argument –use-compress-program, which allow us to set another gzip-ing program.

The most known mutlithreading gzip alternatives is pigz.

So, the tar usage should looks like:

tar --use-compress-program=pigz -cf ...

Under the cut you found the compression time difference between gzip and pigz Continue reading