text:
Q: Generating non-repeating random numbers in Python Ok this is one of those trickier than it sounds questions so I'm turning to stack overflow because I can't think of a good answer. Here is what I want: I need Python to generate a simple a list of numbers from 0 to 1,000,000,000 in random order to be used for serial numbers (using a random number so that you can't tell how many have been assigned or do timing attacks as easily, i.e. guessing the next one that will come up). These numbers are stored in a database table (indexed) along with the information linked to them. The program generating them doesn't run forever so it can't rely on internal state.
No big deal right? Just generate a list of numbers, shove them into an array and use Python "random.shuffle(big_number_array)" and we're done. Problem is I'd like to avoid having to store a list of numbers (and thus read the file, pop one off the top, save the file and close it). I'd rather generate them on the fly. Problem is that the solutions I can think of have problems:
1) Generate a random number and then check if it has already been used. If it has been used generate a new number, check, repeat as needed until I find an unused one. Problem here is that I may get unlucky and generate a lot of used numbers before getting one that is unused. Possible fix: use a very large pool of numbers to reduce the chances of this (but then I end up with silly long numbers).
2) Generate a random number and then check if it has already been used. If it has been used add or subtract one from the number and check again, keep repeating until I hit an unused number. Problem is this is no longer a random number as I have introduced bias (eventually I will get clumps of numbers and you'd be able to predict the next number with a better chance of success).
3) Generate a random number and then check if it has already been used. If it has been used add or subtract another randomly generated random number and check again, problem is we're back to simply generating random numbers and checking as in solution 1.
4) Suck it up and generate the random list and save it, have a daemon put them into a Queue so there are numbers available (and avoid constantly opening and closing a file, batching it instead).
5) Generate much larger random numbers and hash them (i.e. using MD5) to get a smaller numeric value, we should rarely get collisions, but I end up with larger than needed numbers again.
6) Prepend or append time based information to the random number (i.e. unix timestamp) to reduce chances of a collision, again I get larger numbers than I need.
Anyone have any clever ideas that will reduce the chances of a "collision" (i.e. generating a random number that is already taken) but will also allow me to keep the number "small" (i.e. less than a billion (or a thousand million for your europeans =)).
Answer and why I accepted it:
So I will simply go with 1, and hope it's not an issue, however if it is I will go with the deterministic solution of generating all the numbers and storing them so that there is a guarentee of getting a new random number, and I can use "small" numbers (i.e. 9 digits instead of an MD5/etc.).

A: With some modular arithmic and prime numbers, you can create all numbers between 0 and a big prime, out of order. If you choose your numbers carefully, the next number is hard to guess.
modulo = 87178291199 # prime
incrementor = 17180131327 # relative prime

current = 433494437 # some start value
for i in xrange(1, 100):
    print current
    current = (current + incrementor) % modulo

A: If they don't have to be random, but just not obviously linear (1, 2, 3, 4, ...), then here's a simple algorithm:
Pick two prime numbers.  One of them will be the largest number you can generate, so it should be around one billion.  The other should be fairly large.
max_value = 795028841
step = 360287471
previous_serial = 0
for i in xrange(0, max_value):
    previous_serial += step
    previous_serial %= max_value
    print "Serial: %09i" % previous_serial

Just store the previous serial each time so you know where you left off.  I can't prove mathmatically that this works (been too long since those particular classes), but it's demonstrably correct with smaller primes:
s = set()
with open("test.txt", "w+") as f:
    previous_serial = 0
    for i in xrange(0, 2711):
        previous_serial += 1811
        previous_serial %= 2711
        assert previous_serial not in s
        s.add(previous_serial)

You could also prove it empirically with 9-digit primes, it'd just take a bit more work (or a lot more memory).
This does mean that given a few serial numbers, it'd be possible to figure out what your values are--but with only nine digits, it's not likely that you're going for unguessable numbers anyway.

A: If you don't need something cryptographically secure, but just "sufficiently obfuscated"...
Galois Fields
You could try operations in Galois Fields, e.g. GF(2)32, to map a simple incrementing counter x to a seemingly random serial number y:
x = counter_value
y = some_galois_function(x)

*

*Multiply by a constant

*

*Inverse is to multiply by the reciprocal of the constant

*Raise to a power: xn

*Reciprocal x-1

*

*Special case of raising to power n

*It is its own inverse

*Exponentiation of a primitive element: ax

*

*Note that this doesn't have an easily-calculated inverse (discrete logarithm)

*Ensure a is a primitive element, aka generator
Many of these operations have an inverse, which means, given your serial number, you can calculate the original counter value from which it was derived.
As for finding a library for Galois Field for Python... good question. If you don't need speed (which you wouldn't for this) then you could make your own. I haven't tried these:

*

*NZMATH

*Finite field Python package

*Sage, although it's a whole environment for mathematical computing, much more than just a Python library

Matrix multiplication in GF(2)
Pick a suitable 32×32 invertible matrix in GF(2), and multiply a 32-bit input counter by it. This is conceptually related to LFSR, as described in S.Lott's answer.
CRC
A related possibility is to use a CRC calculation. Based on the remainder of long-division with an irreducible polynomial in GF(2). Python code is readily available for CRCs (crcmod, pycrc), although you might want to pick a different irreducible polynomial than is normally used, for your purposes. I'm a little fuzzy on the theory, but I think a 32-bit CRC should generate a unique value for every possible combination of 4-byte inputs. Check this. It's quite easy to experimentally check this, by feeding the output back into the input, and checking that it produces a complete cycle of length 232-1 (zero just maps to zero). You may need to get rid of any initial/final XORs in the CRC algorithm for this check to work.

A: I think you are overestimating the problems with approach 1). Unless you have hard-realtime requirements just checking by random choice terminates rather fast. The probability of needing more than a number of iterations decays exponentially. With 100M numbers outputted (10% fillfactor) you'll have one in billion chance of requiring more than 9 iterations. Even with 50% of numbers taken you'll on average need 2 iterations and have one in a billion chance of requiring more than 30 checks. Or even the extreme case where 99% of the numbers are already taken might still be reasonable - you'll average a 100 iterations and have 1 in a billion change of requiring 2062 iterations

A: The standard Linear Congruential random number generator's seed sequence CANNOT repeat until the full set of numbers from the starting seed value have been generated.  Then it MUST repeat precisely.
The internal seed is often large (48 or 64 bits).  The generated numbers are smaller (32 bits usually) because the entire set of bits are not random.  If you follow the seed values they will form a distinct non-repeating sequence.
The question is essentially one of locating a good seed that generates "enough" numbers.  You can pick a seed, and generate numbers until you get back to the starting seed.  That's the length of the sequence.  It may be millions or billions of numbers.
There are some guidelines in Knuth for picking suitable seeds that will generate very long sequences of unique numbers.

A: This is a neat problem, and I've been thinking about it for a while (with solutions similar to Sjoerd's), but in the end, here's what I think:
Use your point 1) and stop worrying.
Assuming real randomness, the probability that a random number has already been chosen before is the count of previously chosen numbers divided by the size of your pool, i.e. the maximal number.
If you say you only need a billion numbers, i.e. nine digits: Treat yourself to 3 more digits, so you have 12-digit serial numbers (that's three groups of four digits – nice and readable).
Even when you're close to having chosen a billion numbers previously, the probability that your new number is already taken is still only 0,1%.
Do step 1 and draw again. You can still check for an "infinite" loop, say don't try more than 1000 times or so, and then fallback to adding 1 (or something else).
You'll win the lottery before that fallback ever gets used.

A: You could use Format-Preserving Encryption to encrypt a counter. Your counter just goes from 0 upwards, and the encryption uses a key of your choice to turn it into a seemingly random value of whatever radix and width you want.
Block ciphers normally have a fixed block size of e.g. 64 or 128 bits. But Format-Preserving Encryption allows you to take a standard cipher like AES and make a smaller-width cipher, of whatever radix and width you want (e.g. radix 10, width 9 for the parameters of the question), with an algorithm which is still cryptographically robust.
It is guaranteed to never have collisions (because cryptographic algorithms create a 1:1 mapping). It is also reversible (a 2-way mapping), so you can take the resulting number and get back to the counter value you started with.
AES-FFX is one proposed standard method to achieve this.
I've experimented with some basic Python code for AES-FFX--see Python code here (but note that it doesn't fully comply with the AES-FFX specification). It can e.g. encrypt a counter to a random-looking 7-digit decimal number. E.g.:
0000000   0731134
0000001   6161064
0000002   8899846
0000003   9575678
0000004   3030773
0000005   2748859
0000006   5127539
0000007   1372978
0000008   3830458
0000009   7628602
0000010   6643859
0000011   2563651
0000012   9522955
0000013   9286113
0000014   5543492
0000015   3230955
...       ...

For another example in Python, using another non-AES-FFX (I think) method, see this blog post "How to Generate an Account Number" which does FPE using a Feistel cipher. It generates numbers from 0 to 2^32-1.

A: You can run 1) without running into the problem of too many wrong random numbers if you just decrease the random interval by one each time.
For this method to work, you will need to save the numbers already given (which you want to do anyway) and also save the quantity of numbers taken.
It is pretty obvious that, after having collected 10 numbers, your pool of possible random numbers will have been decreased by 10. Therefore, you must not choose a number between 1 and 1.000.000 but between 1 an 999.990. Of course this number is not the real number but only an index (unless the 10 numbers collected have been 999.991, 999.992, …); you'd have to count now from 1 omitting all the numbers already collected.
Of course, your algorithm should be smarter than just counting from 1 to 1.000.000 but I hope you understand the method.
I don't like drawing random numbers until I get one which fits either. It just feels wrong.

A: My solution https://github.com/glushchenko/python-unique-id, i think you should extend matrix for 1,000,000,000 variations and have fun.

A: I'd rethink the problem itself... You don't seem to be doing anything sequential with the numbers... and you've got an index on the column which has them. Do they actually need to be numbers?
Consider a sha hash... you don't actually need the entire thing. Do what git or other url shortening services do, and take first 3/4/5 characters of the hash. Given that each character now has 36 possible values instead of 10, you have 2,176,782,336 combinations instead of 999,999 combinations (for six digits). Combine that with a quick check on whether the combination exists (a pure index query) and a seed like a timestamp + random number and it should do for almost any situation.

A: Do you need this to be cryptographically secure or just hard to guess?  How bad are collisions? Because if it needs to be cryptographically strong and have zero collisions, it is, sadly, impossible.

A: I started trying to write an explanation of the approach used below, but just implementing it was easier and more accurate.  This approach has the odd behavior that it gets faster the more numbers you've generated.  But it works, and it doesn't require you to generate all the numbers in advance.
As a simple optimization, you could easily make this class use a probabilistic algorithm (generate a random number, and if it's not in the set of used numbers add it to the set and return it) at first, keep track of the collision rate, and switch over to the deterministic approach used here once the collision rate gets bad.
import random

class NonRepeatingRandom(object):

    def __init__(self, maxvalue):
        self.maxvalue = maxvalue
        self.used = set()

    def next(self):
        if len(self.used) >= self.maxvalue:
            raise StopIteration
        r = random.randrange(0, self.maxvalue - len(self.used))
        result = 0
        for i in range(1, r+1):
            result += 1
            while result in self.used:
                 result += 1
        self.used.add(result)
        return result

    def __iter__(self):
        return self

    def __getitem__(self):
        raise NotImplemented

    def get_all(self):
        return [i for i in self]

>>> n = NonRepeatingRandom(20)
>>> n.get_all()
[12, 14, 13, 2, 20, 4, 15, 16, 19, 1, 8, 6, 7, 9, 5, 11, 10, 3, 18, 17]

A: If it is enough for you that a casual observer can't guess the next value, you can use things like a linear congruential generator or even a simple linear feedback shift register to generate the values and keep the state in the database in case you need more values. If you use these right, the values won't repeat until the end of the universe. You'll find more ideas in the list of random number generators.
If you think there might be someone who would have a serious interest to guess the next values, you can use a database sequence to count the values you generate and encrypt them with an encryption algorithm or another cryptographically strong perfect has function. However you need to take care that the encryption algorithm isn't easily breakable if one can get hold of a sequence of successive numbers you generated - a simple RSA, for instance, won't do it because of the Franklin-Reiter Related Message Attack.

A: Bit late answer, but I haven't seen this suggested anywhere.
Why not use the uuid module to create globally unique identifiers

A: To generate a list of totally random numbers within a defined threshold, as follows:
plist=list()
length_of_list=100
upbound=1000
lowbound=0
while len(pList)<(length_of_list):
     pList.append(rnd.randint(lowbound,upbound))
     pList=list(set(pList))

A: I bumped into the same problem and opened a question with a different title before getting to this one. My solution is a random sample generator of indexes (i.e. non-repeating numbers) in the interval [0,maximal), called itersample. Here are some usage examples:
import random
generator=itersample(maximal)
another_number=generator.next() # pick the next non-repeating random number

or
import random
generator=itersample(maximal)
for random_number in generator:
    # do something with random_number
    if some_condition: # exit loop when needed
        break

itersample generates non-repeating random integers, storage need is limited to picked numbers, and the time needed to pick n numbers should be (as some tests confirm) O(n log(n)), regardelss of maximal.
Here is the code of itersample:
import random
def itersample(c): # c = upper bound of generated integers
    sampled=[]
    def fsb(a,b): # free spaces before middle of interval a,b
        fsb.idx=a+(b+1-a)/2
        fsb.last=sampled[fsb.idx]-fsb.idx if len(sampled)>0 else 0
        return fsb.last
    while len(sampled)<c:
        sample_index=random.randrange(c-len(sampled))
        a,b=0,len(sampled)-1
        if fsb(a,a)>sample_index:
            yielding=sample_index
            sampled.insert(0,yielding)
            yield yielding
        elif fsb(b,b)<sample_index+1:
            yielding=len(sampled)+sample_index
            sampled.insert(len(sampled),yielding)
            yield yielding
        else: # sample_index falls inside sampled list
            while a+1<b:
                if fsb(a,b)<sample_index+1:
                    a=fsb.idx
                else:
                    b=fsb.idx
            yielding=a+1+sample_index
            sampled.insert(a+1,yielding)
            yield yielding

A: You are stating that you store the numbers in a database.
Wouldn't it then be easier to store all the numbers there, and ask the database for a random unused number?
Most databases support such a request.
Examples
MySQL:
SELECT column FROM table
ORDER BY RAND()
LIMIT 1

PostgreSQL:
SELECT column FROM table
ORDER BY RANDOM()
LIMIT 1


text:
Q: Access to RSOP via WMI I need to retrieve data from RSOP using the following script written in VBS:
Const FL_FORCE_CREATE_NAMESPACE = 5

strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,AuthenticationLevel=default}!\\" & strComputer & "\root\rsop")
Set provider = objWMIService.Get("RsopLoggingModeProvider")
provider.RsopCreateSession FL_FORCE_CREATE_NAMESPACE, Null, namespaceLocation, hResult, eInfo
Wscript.Echo "hresult " & hresult

sometimes it crashes with the following error:
hresult -2147217405
The HRESULT code is 80041003 error in HEX form.
Script is called by a service.
Platform: Windows 2003
I believe that it is a problem with permissions for WMI RSOP namespace, but I do not know what permissions should be.
Anybody knows where is the problem?
Thank you in advance

redpajama_set_name: RedPajamaStackExchange


text:
Q: Fuzzy data matching for personal demographic information Let's say I have a database filled with people with the following data elements:

*

*PersonID (meaningless surrogate autonumber)

*FirstName

*MiddleInitial

*LastName

*NameSuffix

*DateOfBirth

*AlternateID (like an SSN, Militarty ID, etc.)

I get lots of data feeds in from all kinds of formats with every reasonable variation on these pieces of information you could think of. Some examples are:

*

*FullName, DOB

*FullName, Last 4 SSN

*First, Last, DOB

When this data comes in, I need to write something to match it up. I don't need, or expect, to get more than an 80% match rate. After the automated match, I'll present the uncertain matches on a web page for someone to manually match.
Some of the complexities are:

*

*Some data matches are better than others, and I would like to assign weight to those. For example, if the SSN matches exactly but the name is off because someone goes by their middle name, I would like to assign a much higher confidence value to that match than if the names match exactly but the SSNs are off.

*The name matching has some difficulties. John Doe Jr is the same as John Doe II, but not the same as John Doe Sr., and if I get John Doe and no other information, I need to be sure the system doesn't pick one because there's no way to determine who to pick.

*First name matching is really hard. You have Bob/Robert, John/Jon/Jonathon, Tom/Thomas, etc.

*Just because I have a feed with FullName+DOB doesn't mean the DOB field is filled for every record. I don't want to miss a linkage just because the unmatched DOB kills the matching score. If a field is missing, I want to exclude it from the elements available for matching.

*If someone manually matches, I want their match to affect all future matches. So, if we ever get the same exact data again, there's no reason not to automatically match it up next time.

I've seen that SSIS has fuzzy matching, but we don't use SSIS currently, and I find it pretty kludgy and nearly impossible to version control so it's not my first choice of a tool. But if it's the best there is, tell me. Otherwise, are there any (preferably free, preferably .NET or T-SQL based) tools/libraries/utilities/techniques out there that you've used for this type of problem?

A: There are a number of ways that you can go about this, but having done this type of thing before i will go ahead and put out here that you run a lot of risk in having "incorrect" matches between people.
Your input data is very sparse, and given what you have it isn't the most unique, IF not all values are there.
For example with your First Name, Last Name, DOB situation, if you have all three parts for ALL records, then the matching gets a LOT easier for you to work with.  If not though you expose yourself to a lot of potential for issue.
One approach you might take, on the more "crude" side of things is to simply create a process using a series of queries that simply identifies and classifies matching entries.
For example first check on an exact match on name and SSN, if that is there flag it, note it as 100% and move on to the next set.  Then you can explicitly define where you are fuzzy so you know the potential ramification of your matching.
In the end you would have a list with flags indicating the match type, if any for that record.

A: This is a problem called record linkage.
While it's for a python library, the documentation for dedupe gives a good overview of how to approach the problem comprehensively.

A: Take a look at the Levenshtein Algoritm, which allows you to get 'the distance between two strings,' which can then be divided into the length of the string to get a percentage match.
http://en.wikipedia.org/wiki/Levenshtein_distance
I have previously implemented this to great success.  It was a provider portal for a healthcare company, and providers registered themselves on the site.  The matching was to take their portal registration and find the corresponding record in the main healthcare system.  The processors who attended to this were presented with the most likely matches, ordered by percentage descending, and could easily choose the right account.

A: If the false positives don't bug you and your languages are primarily English, you can try algorithms like Soundex. SQL Server has it as a built-in function. Soundex isn't the best, but it does do a fuzzy matching and is popular. Another alternative is metaphone.


text:
Q: how to create shape in a web page from image and change its fill using javascript I have a PNG image of black sock shape with a transparent background.
I want to be able to embed this image in a web page and change the fill of the shape from black to any valid web colour using javascript (jQuery).
I would like to do this without flash, is this possible.
From my research it looks like I could convert the image to a html table but thats inefficient i'm sure.
Also I think Vector / SVG graphics might help here, but im not sure how to implement this.
Any help would be greatly appreciated.
I am a developer by day and web designer by night... still learning :)

A: Have u checked Google Chrome expermients? they have some that can be really helpful for u.

A: I can't think of any way to achieve this with a png image, however you can export images directly to SVG using Illustrator. SVG is simply xml based markup like html, so this would allow you to programmatically alter the image with javascript.


text:
Q: Icewesel misbehave on local symbolic link to html file Hi all I download the Gtk3.0 documentation to my hard drive and deploy it on /doc on my linux  root file system. And I've created a symbolic link to the /doc/index.html but when it navigate to other pages it uses the symbolic address as the relative path.
for a example I have symbolic link to /doc/index.html at /root/Desktop like this
    ln -S gtk_docs.html /doc/index.html
The index.html page loads fine. But lcewesel uses command line parameter as the URL, so it does not symbolically expanded. The correct behavior should be expand the symbolic link first and then load the original location into the URL if it's a symbolic link.
Any fix up or workaround for this issue ?

A: try to make a symbolic link of the whole folder


text:
Q: Cannot convert dateTime string with Datetime.ParseExact This is the exact string i have: 18-2-2014 00:00:00
My code bumps into this error:

An unhandled exception of type 'System.FormatException' occurred in
  mscorlib.dll
Additional information: String was not recognized as a valid DateTime.

At this line:
newDateTime = DateTime.ParseExact(
                        part[0],
                        "dd-mm-jjjj hh:mm:ss",
                        CultureInfo.InvariantCulture
                        ); //I tried a couple of time string variations, but it should be the above or "dd-m-jjjj hh:mm:ss".

What am i doing wrong?

A: mm specifier is for minutes. Use M specifier which is for months (1 to 12).
hh format is for 01 to 12 (12-hour clock). It doesn't have 00 as an hour. That's why you should use HH format which is for 00 to 23 (24-hour clock).
And there is no jjjj date and time format specifier which I think you want to use yyyy format.
var s = "18-2-2014 00:00:00";
var date = DateTime.ParseExact(s,
                              "dd-M-yyyy HH:mm:ss",
                               CultureInfo.InvariantCulture);
Console.WriteLine(date);

Output will be;
2/18/2014 12:00:00 AM

Here a demonstration.
For more information, take a look at;

*

*Custom Date and Time Format Strings
NOTE: As Jeppe Stig Nielsen pointed, since we don't know your culture exactly (can be nl-BE or nl-NL) your ShortDatePattern day for is d not dd.
That's why you might need to use d format instead dd.

A: Try This:
newDateTime = DateTime.ParseExact(part[0],"dd-M-yyyy HH:mm:ss",
                    CultureInfo.InvariantCulture);


text:
Q: Proof of this series converging to zero does not convince me I have a function $F$ that is bounded and such that $F(x) \to 0$ whenever $x\to 0$. Then, I have the following series
$$
\sum_{k=0}^\infty \frac{F(2^{k+1}\delta)}{2^k}
$$
for $\delta > 0$. I want to show that this series converges to $0$ as $\delta\to 0$.
Proof from the book which I don't understand
Given $\epsilon > 0$ we choose $N$ so large that
$$
\sum_{k \geq N} \frac{1}{2^k} < \epsilon.
$$
Then, by making $\delta$ sufficiently small, we have (since $F(x)\to 0$ as $x\to 0$)
$$
F(2^k \delta) < \frac{\epsilon}{N}
$$
whenever $k=0, 1, \ldots, N-1$. Since $F$ is bounded then the result follows.
What I don't understand
I am very lost by this proof. What is it doing in the first step? How does it know I can find such an $N$? And how does it know that by choosing $\delta$ sufficiently small, I can bound $F(2^k \delta)$?

A: *

*In the first step, they take advantage of the fact that $F$ is bounded and $\sum_{k\in\Bbb N}\frac1{2^k}$ is convergent to prove that some tail of the series is sufficiently small, independently from $\delta.$ More precisely, given $\epsilon>0,$ for $N$ large enough (and this "large enough" is easy to calculate),
$$\sum_{k\ge N}\frac1{2^k}=\frac1{2^{N-1}}<\epsilon$$
hence if $|F|$ is bounded by some positive $M$ then $\left|\sum_{k\ge N}\frac{F(2^{k+1}\delta)}{2^k}\right|\le\sum_{k\ge N}\frac{|F(2^{k+1}\delta)|}{2^k}\le M\epsilon$ for every $\delta.$

*Now that $N$ is fixed, in the second step, there only remains to bound a finite number of terms of the series. For each $k<N,$ they prove that for every $\delta$ small enough, each of the $N$ first terms of the series will also be small. More precisely, given $\epsilon>0$ again, since $\lim_{x\to0}F(x)=0,$ there exists some $\alpha>0$ such that
$$|x|<\alpha\Rightarrow|F(x)|<\frac\epsilon N,$$
so that for every real number $\delta,$
$$|\delta|<\frac\alpha{
2^{N-1}}\implies\forall k\le N-1\quad|F(2^k\delta)|<\frac{\epsilon}N$$
hence
$$|2\delta|<\frac\alpha{
2^{N-1}}\implies\sum_{k=0}^{N-1}\frac{|F(2^{k+1}\delta)|}{2^k}\le \sum_{k=0}^{N-1}|F(2^{k+1}\delta)|<\epsilon.$$
Putting the two steps together, since
$$\left|\sum_{k\ge0}\frac{F(2^{k+1}\delta)}{2^k}\right|\le\sum_{k=0}^{N-1}\frac{|F(2^{k+1}\delta)|}{2^k}+\left|\sum_{k\ge N}\frac{F(2^{k+1}\delta)}{2^k}\right|,$$
they found that
$$\forall\epsilon>0\quad\exists\beta>0\quad\left(|\delta|<\beta\implies\left|\sum_{k\ge0}\frac{F(2^{k+1}\delta)}{2^k}\right|<\left(1+M\right)\epsilon\right).$$
For every $\varepsilon>0,$ applying this to $\epsilon=\frac\varepsilon{1+M}$ proves the claim, i.e.
$$\forall\varepsilon>0\quad\exists\beta>0\quad\left(|\delta|<\beta\implies\left|\sum_{k\ge0}\frac{F(2^{k+1}\delta)}{2^k}\right|<\varepsilon\right).$$

A:
What is it doing in the first step? How does it know I can find such an $N$?

Because $\sum_{k\geq N}\frac1{2^k} = \frac1{2^N}\sum_{k=0}^\infty\frac{1}{2^k}=2^{-N}2=2^{1-N}$ and we just choose $N\geq1-\log_2(\varepsilon)$.

And how does it know that by choosing $\delta$ sufficiently small, I can bound $F(2^k\delta)$?

The precise definition of $F(x)\to0$ as $x\to 0$ is:
$$\forall\varepsilon>0\exists\mu\forall x\colon |x|<\mu\Rightarrow |F(x)|<\varepsilon$$
(The usual definition uses $\delta$ instead of $\mu$, but we already have a different $\delta$ so I use $\mu$ to avoid confusion).
This means that if I choose some $\varepsilon$, for example $\varepsilon=\frac{\epsilon}{N}$, then I get a $\mu$ such that $F(x)<\varepsilon$ for all $x$ with $|x|<\mu$. Now if we take $\delta = \frac{\mu}{2^{N}}$, then all numbers $\delta 2^k$ for $k=1,2,\dots,N-1$ have $\delta 2^k<\mu$, so we have $F(\delta 2^k)<\varepsilon=\frac\epsilon N$.

A: the idea is to split the series into two separate sums. That means:
$\big\vert \sum_{k \geq 0} \frac{F(2^{k+1}\delta)}{2^k} \big\vert \leq \big\vert \sum_{k=0}^{N-1} \frac{F(2^{k+1}\delta)}{2^k} \big\vert + \big\vert \sum_{k\geq N} \frac{F(2^{k+1}\delta)}{2^k} \big\vert.$
Now, both sums on the right hand side tend to zero, under different assumptions. The first one, by using the continuity of $F$ in $0$, combined with $F(0)=0$ and the second one, using the boundedness of $F$. In fact you can proceed the inequality as follows.
For the first term:
$\big\vert \sum_{k=0}^{N-1} \frac{F(2^{k+1}\delta)}{2^k} \big\vert \leq N \max_{k=0,...,N-1} \vert F(2^{k+1} \delta) \vert. \tag{1}$
And the second term:
$\big\vert \sum_{k\geq N} \frac{F(2^{k+1}\delta)}{2^k} \big\vert \leq M \sum_{k\geq N} \frac{1}{2^k}. \tag{2}$
Note, such an $M>0$ exists, since $F$ is bounded.
Now you are ready to prove the claim. You can pick an arbitrary $\varepsilon >0$. Then, since the second sum (2) tends to zero, you find some $N(\varepsilon) \in \mathbb{N}$ s.t. $\sum_{k\geq N(\varepsilon)} \frac{1}{2^k} < \frac{\varepsilon}{2}$.
And, you can also find an $\delta(\varepsilon) >0$ small enough, s.t.
$\vert F(2^{k+1} \delta) \vert < \frac{\varepsilon}{2 \cdot N(\varepsilon)}, \quad \forall \delta \leq \delta(\varepsilon)$, for all $k=0,...,N(\varepsilon)-1$. Which gives you
$N(\varepsilon) \max_{k=0,...,N(\varepsilon)-1} \vert F(2^{k+1} \delta) \vert \leq \frac{\varepsilon}{2}, \quad \forall \delta \leq \delta(\varepsilon).$
Put everything together, and you get
$\big\vert \sum_{k \geq 0} \frac{F(2^{k+1}\delta)}{2^k} \big\vert \leq \varepsilon, \; \forall \delta \leq \delta(\varepsilon).$
This proves the claim, as $\varepsilon$ was arbitrary.

A: Let $\sum_{k=0}^{\infty}a_k = S \in \mathbb{R}$ be a convergent series. Now define a "tail sum" sequence: $t_n = \sum_{k=n}^{\infty}a_k$
Notice that this sequence is well defined because the series converges. Now we will prove that: $t_n \underset{n \to \infty}{\longrightarrow} 0$
Notice that $t_{n+1}=S-\sum_{k=0}^{n}a_k$ whoever we know that by definition $\sum_{k=0}^{n}a_k \underset{n \to \infty}{\longrightarrow} S$ so using arithmetic of limits we get $t_{n+1} \underset{n \to \infty}{\longrightarrow} S-S=0$ and thus also $t_n \underset{n \to \infty}{\longrightarrow} 0$ (because shifting a sequence does not impact the convergence or the limit itself).  Now substitute $a_k = 2^{-k}$ and use the definition of a limit of sequence on $t_n$ to get your desired $N$ for each $\epsilon$.
Regarding your second doubt about $\delta$ consider the following:
Let $0 < \epsilon, N$ be two numbers, we know that by the definition of the limit on the number $\epsilon/N$ there is some $0 < d$ such that $x \in (-d,d) \implies -\epsilon/N < F(x) < \epsilon/N$. Now the question is how to choose $0 < \delta$ such that $2^k\delta \in (-d,d)$ for $k=0,...,N-1$. Now note:
$-d < 2^k\delta < d \Leftrightarrow -d/2^k < \delta < d/2^k$ so pick some $0<\delta$ such that: $-d/2^{N-1} < \delta < d/2^{N-1}$ and then because $(-d/2^{N-1},d/2^{N-1}) \subset (-d/2^k,d/2^k)$ for $k = 0,...,N-1$ that $\delta$ satisfies our requirement.


text:
Q: How do I call a cache busting function inside request.static_url() in my layout.pt chameleon template I'm using a Cookiecutter Pyramid web development framework. This has three linked files:
utils.py - defines the random cache string to add to an url
views.py - passes utils functions to chameleon template
layout.pt - chameleon template calling static css urls etc.
In layout.pt pre-cache-busting there is a link that says:
<link href="${request.static_url('pycharm_app:static/theme.css')}" rel="stylesheet">

I'm trying to edit this link to call the build_cache_id function as so:
 <link href="/static/theme.css?cacheId=${build_cache_id('/static/theme.css')}" rel="stylesheet">

but get error:
NameError: build_cache_id

 - Expression: "build_cache_id('/static/theme.css')"
 - Filename:   ... s/first_business_website/pycharm_app/templates/layout.pt
 - Location:   (line 17: col 43)
 - Source:     ... ss?cacheId=${build_cache_id('/static/theme.css')}" rel="styl ...
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Expression: "load: layout.pt"
 - Filename:   ... rst_business_website/pycharm_app/templates/mytemplate.pt
 - Location:   (line 1: col 22)
 - Source:     <div metal:use-macro="load: layout.pt">
                                     ^^^^^^^^^^^^^^^
 - Arguments:  view: <function my_view at 0x109eff8b0>
               renderer_name: ../templates/mytemplate.pt
               renderer_info: <RendererHelper - at 0x109f3f040>
               context: <DefaultRootFactory None at 0x109d3faf0>
               request: <Request - at 0x109d3fa90>
               req: <Request - at 0x109d3fa90>
               get_csrf_token: <partial - at 0x109f32db0>
               project: pycharm_app
               target_language: <NoneType - at 0x10817de60>
               repeat: {...} (0)
               macroname: load: layout.pt

A: The Arguments part of the error output clearly shows that build_cache_id is not passed to the template engine. On the other hand, the project variable is.

 - Arguments:  view: <function my_view at 0x109eff8b0>
               renderer_name: ../templates/mytemplate.pt
               renderer_info: <RendererHelper - at 0x109f3f040>
               context: <DefaultRootFactory None at 0x109d3faf0>
               request: <Request - at 0x109d3fa90>
               req: <Request - at 0x109d3fa90>
               get_csrf_token: <partial - at 0x109f32db0>
               project: pycharm_app
               target_language: <NoneType - at 0x10817de60>
               repeat: {...} (0)
               macroname: load: layout.pt```

Looks like the extend_model function is not correctly called, even though the code looks correct to me. Was the application correctly reloaded? Maybe add simple print calls in these functions as a quick and dirty debug and make sure that the correct code is running.

A: Fixed this! with a lot of help from @sinoroc.
The problem is that using PyCharm to initiate a pyramid web project sets up files and folder structure in a different way to cookiecutter via terminal. It is not immediately possible to copy across "missing" files from the cookiecutter framework to the PyCharm framework without ensuring you fix the plumbing.
- typing proutes development.ini in terminal will list routes. In my instance there were routes for pyramid_debugtoolbar with no url. Deleting pyramid_debugtoolbar from development.ini fixed this issue.
- All routes need to be specified in __init__.py file. Copy pasting new template files in to the folder structure does not mean they will automatically appear here.
- All routes need to be passed to @view_config in views.py. E.g.
@view_config(route_name='index',renderer='templates/index.pt')
def index(_):
return extend_model({'project':'designable_web'})

Again, these routes will not automatically be set up when pasting in new file names from another folder structure.

*

*Check which template language is installed in setup.py (e.g. chameleon, jinja2). At present PyCharm has a bug that defaults to jinja2 EVEN IF YOU SELECTED CHAMELEON ON SET UP. Template files  will not work unless the correct corresponding language is specified here.

*Check folder depth. The cookiecutter framework had a separate views folder with views file inside, whereas PyCharm had the views.py file sitting underneath the top "app level" folder. Again proutes development.ini will specify which is correct.


text:
Q: What is the moby runtime? Currently learning docker and containerization, I get a little confused by the term of "moby runtime".
For my unterstanding, the whole docker has been split up in several libraries / tools / components allowing developers to build their own version of docker using the moby runtime.
Is this assumption correct?
What exactly is the relationship between moby runtime and e.g. the docker for desktop I download on my windows machine if I use the official docker page?
Why does e.g. Microsoft use the moby runtime to run some services like IoT Edge instead of the official docker build? Do they use their customized version of docker?

A: Moby is a bit of an overused name from Docker. In addition to being the name of one of their mascots (Moby is the blue whale you often see in the logos), Moby is:

*

*An upstream open source project that Docker has given to the community. This gives separation from the closed source portions of Docker and the parts with Docker's trademark attached. You can see these projects in their Github repositories. You can think about the Moby Project the same way you think of Fedora as the upstream for RedHat, Docker does most of their development in the Moby Project repos and packages specific releases from there with the Docker name that you see as Docker CE and Docker EE. Some projects may live here forever, but Docker also strives to move these further upstream to be managed by external organizations, e.g. containerd and notary have both been transitioned to the Linux Foundation.

*It is the repository name that was formerly docker/docker, now moved to moby/moby. This is the core of the docker engine.

*It is a virtual machine that is packaged using LinuxKit. This VM is a minimal environment to run docker containers, and well suited for running on desktop and embedded environments where you don't want to manage the VM itself.
The latter is most likely what you are thinking of by "Moby Runtime". A VM is needed to run Linux containers on a Windows or Mac environment (docker containers depend on a lot of kernel functionality that would not be easy to emulate). You can even see examples for building similar VM's in the LinuxKit examples. Inside of that VM is the same Docker CE engine that is installed natively on Linux host. And the VM itself is built and maintained by Docker.

A: Yes, I think your unstanding is correct.
From official web site:

Moby is an open framework created by Docker to assemble specialized container systems without reinventing the wheel. It provides a "lego set" of dozens of standard components and a framework for assembling them into custom platforms. At the core of Moby is a framework to assemble specialized container systems which provides: Components, Tools, Assemblies.

It also said:

Moby IS RECOMMENDED for anyone who wants to assemble a container-based system: Hackers who want to customize or patch their Docker build.

And next digram may make you even clear:

From this you can see, you could start your own project just like Docker CE, Docker EE based on moby project. And here is a good article I think explain it clearly. Also this from official guys response for some relationship.


text:
Q: How can I solve this Mysql2 gem error in CentOS 8? I need to setup ruby on rails with MySQL
I already have installed MYSQL
when I do Bundle install it shows following error.
Fetching mysql2 0.3.21
Installing mysql2 0.3.21 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

I am using Cent-os 8
anyone can help
Thanks

A: Run first this command gem 'mysql2', '~> 0.3.21' in terminal and when finish then try bundle again


text:
Q: Is it possible to combine context state in React? I'm building an app that has some complex state  and I'm trying to handle that state using React Hooks. So I need multiple context providers like that:
export default function Provider({ children }) {
  const [state, dispatch] = useReducer(reducer, {});

  const update = useCallback(payload=> {
    dispatch({ type: UPDATE, payload});
  }, []);

  return (
    <TestContext.Provider
      value={useMemo(() => {
        return {
          state,
          update
        };
      }, [state, update])}
    >
      {children}
    </TestContext.Provider>
  );
}

The state is composed of 2 objects, each of which contains multiple objects.
state: {
  inputs: {N objects}
  outputs: {M objects}
}

The data is fetched and updated from multiple different sources, so in order to keep the code clean I want to split the context providers into multiple providers and still have one state with all inputs and outputs that are the result of all provider's states.
Any ideas and suggestions will be appreciated.


text:
Q: Need to center align a span inside a div both vertically and horizontally using less(css) I am using LESS (CSS) trying to align a span (button text) inside a div (button). The span is centrally aligned horizontally but is top aligned vertically. I would also like the span object to adjust itself to the text size automatically.
Here's the LESS code:
.button(@color:@crimson-red) {
  border-radius: @small-border-radius;
  border-style: none;
  background-color: @color;
  text-align: center;
  display: inline-block;
}

.button-font {
  vertical-align: middle;
  overflow: auto;
  font-family: "Helvetica Neue", sans-serif;
  color: @off-white;
  font-weight: bold;
  font-size: 10pt;
  position: relative;
}

.blue-button {
  .button(@blue);
}

A: You can achieve this by using the flexbox layout.
So by adding the following properties and values to the .button selector you can center the span.
 display: flex;
 flex-direction: column;
 justify-content: center;
 align-items: center;

Here is the full less file for reference.
@off-white: #fefefe;
@blue: #4286f4;
@small-border-radius: 5px;

.button(@color:@crimson-red) {
  border-radius: @small-border-radius;
  border-style: none;
  background-color: @color;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.button-font {
  font-family: "Helvetica Neue", sans-serif;
  color: @off-white;
  font-weight: bold;
  font-size: 10pt;
  position: relative;
}

.blue-button {
  .button(@blue);
  width: 300px;
  height: 100px;
}

This would be the html:
<button class="blue-button">
    Hello, lots of text here
</button>

Here is a link to a JSFiddle with compiled css.


text:
Q: Error al hacer consulta a la tabla pg_user en Redshift Estoy intentado hacer una consulta a la tabla de usuarios de Redshift, llamada pg_user pero me devuelve el siguiente error:
The field 'valuntil' has a type currently unknown to Npgsql (OID 702). You can retrieve it as a string by marking it as unknown, please see the FAQ.
El campo valuntil almacena la fecha de expiración de la cuenta de usuario. Estoy utilizando Aginity.
¿Alguna idea?

A: Investigando por la documentación oficial y foros de consulta de Aginity (el software que estaba utilizando), es una limitación del propio Aginity.
Utilizando la alternativa mencionada en la documentación oficial de Redshift (SQL Workbench/J), al lanzar el mismo comando no hay ningún problema:
select * from pg_user
usename usesysid usecreatedb usesuper usecatupd passwd   valuntil useconfig
adm_m   389      false       false    false     ********
admin   100      true        true     false     ********          {TimeZone=CET}