ymlparsers and parser modules serves as Low-Level API for this module. Here is the story about ymlparsers and here is is the story about parser.
The source code you can found here. It is available as part of my AlexBerUtils s project.
You can install AlexBerUtils from PyPi:
python3 -m pip install -U alex-ber-utils
You should also install some optional dependencies, such as jinja2. The easiest way is to run:
python3 -m pip install alex-ber-utils[yml]
Note also that hiyapyco should be at least 0.4.16.
See here for more details explanation on how to install.
Put the following files to…
This is first part of mini-series of Explaining invokedynamic. This is the full list of all articles:
Number multiplication (almost) complete example. Part IV
Dynamical hashCode implementation. Part V
Since Java 7 new bytecode instruction invokedynamic
(or indy) was added.
It was added in JSR 292 in about 2011. It was originally designed for supporting Dynamically Typed Languages, as JSR name stated. So, it was ignored by waste majority of Java developers.
It is not strickly required to read, theoretical part. The main result of it is provided here.
The last example illustrate how to implement mixin in Python.
Theoretically, not for any inheritance graph C³ Linearization Algorithm can be linearized. In practice, it is rarely happen, and if it did, Python will emit en Error. Another name of this algorithm is MRO — Method Resolution Order.
That’s right, the Diamond problem can be solved (practically). We can use inheritance where both object has the state, and this will not cause any problem. …
and other routine
What is generator in Python? Let’s look on what Wikipedia has to say:
Note: I’ve simplified code a bit.
Generators were added to Python in version 2.2 in 2001.[6] An example generator:
In Python, a generator can be thought of as an iterator that contains a frozen stack frame. Whenever
next()
is called on the iterator, Python resumes the frozen frame, which executes normally until the nextyield
statement is reached. The generator's frame is then frozen again, and the yielded value is returned to the caller.
https://en.wikipedia.org/wiki/Generator_(computer_programming)#Python
So, does generator is simply iterator? But what…
This story is dedicated of describing how Docker container can be configure to use Python package keyring. It is non-trivial task. But first of all, we need to go over some basic .
GNOME Keyring is service designed to store security credentials such as passwords, keys, certificates and so on together with a small amount of relevant metadata and make them available to applications. The sensitive data is encrypted and stored in a keyring file. GNOME Keyring — is persistent storage with keeping data on a hard disk. …
It is very difficult if not impossible to pickle exceptions back to the parent process.
Simple ones work, but many others don’t.
For example, CalledProcessError
is not pickable (my guess, this is because of stdout
, stderr
data-members).
This means, that if child process raise CalledProcessError
that is not catched, it will propagate to the parent process, but the propagation will fail, apparently because of bug in Python itself. This cause pool.join() to halt forever — and thus memory leak! See https://stackoverflow.com/questions/15314189/python-multiprocessing-pool-hangs-at-join and https://bugs.python.org/issue9400
So, I have created GuardedWorkerException
context-manager to mitigate this problem.
The source code you can found here…
What if you have some script or application that use relative path and you want to invoke in from another directory. To get things more complicated. maybe your “external” code also use relative path, but relative to another directory. Here, I will describe the recipe how you can make all of these to work.
Suppose, that you wrote some script or application that is packaged and installed as YourApp (that is, it is installed into site-packages or venv). Something like this:
Code of app.py
:
Note: Here I’m using init_app_conf module. You can read about it here.
Typically, at the…
C++ and Beyond 2012: Herb Sutter — atomic<> Weapons
It may surprise you, but actually up to Java 5.0 many of singleton implementation has a bug. It was so wide spreader, that Java Memory Model was fixed to make the buggy code work. The same problem was in C++, that was fixed in C ++ 11.
Atomic
in C/C++ is the same as Java 5+ volatile
(or AtomicInteger
, AtomicLong
or another Atomic*)
Atomics
enables to write CAS
(or Exchange), that in-turn allows to write lock-free algorithm
.
See also:
http://www.e-reading.club/bookreader.php/134637/Herlihy,_Shavit_-_The_art_of_multiprocessor_programming.pdf
Quote:
Abstract: This session in one…
You can optionally see also https://www.youtube.com/watch?v=OZNHYZXbLY8 and http://www.youtube.com/watch?v=bjH1HphOZ1Y for what is completing square.
I will show alternative way to accomplish this task.
(a+b)²=a²+2ab+b²
So, the tough question will be
x²+3x+4=2
x²+2*(3/2)*x+4=2
x²+2*(3/2)*x+(9/4)–(9/4)+4=2
(x+(3/2))²=2–4+(9/4)
(x+(3/2))²=(1/4)
x+(3/2)=(1/2) or x+(3/2)=-(1/2)
x=-1 or x=-2
And so, alternative derivation would be:
We want to solve
ax²+bx+c=0, where a≠0
Because a≠0 we can divide both parts by a, we will get
0=x²+(b/a)x+(c/a)=x²+2*(b/2a)*x+(c/a)=
=x²+2*(b/2a)*x+(b²/4a²)-(b²/4a²)+(c/a)=
=(x+(b/2a))²-(b²/4a²)+(c/a)
or another way around
(x+(b/2a))²=(b²/4a²)-(c/a)
(x+(b/2a))²=(b²/4a²)-(4ac/4a²)
(x+(b/2a))²=(b²-4ac)/4a²
(x+(b/2a))=± sqrt((b²-4ac)/4a²)
From here:
(x+(b/2a))=± (sqrt(b²-4ac)/2a)
x=-(b/2a)± (sqrt(b²-4ac)/2a)
After, you know the formula, solving the tough question will be much easier:
x²+3x+4=2
x²+3x+2=0
Well, I can think about 2 more ways why we should define 0!=1
I. n!=1*2*3*4*...*(n-1)*n
— this is definition of n!.
n! is multiplication of n factors starting from 1,2,… till n.
For example, 5!
is multiplication of 5 factors 1*2*3*4*5 or 5!=1*2*3*4*5
.
Similarly, 2!
multiplication of 2 factors 1*2
or 2!=1*2
. How much is 1!?
1! is multiplication of 1 factor 1, 1!=1 (
you can ask what does multiplication of 1 factor mean? Well, there is “natural” definition. Because n*1=n y
ou can think of multiplication of 1 factor n as simple multiplication n by 1, that is multiplication…
Senior Software Engineer at Pursway