Efficiently generate a 16-character, alphanumeric string

As none of the answers provide you with a random string consisting of characters 0-9, a-z, A-Z: Here is a working solution which will give you one of approx. 62^16 = 4.76724 e+28 keys: import random, string x = ”.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(16)) print(x) It is also very readable without … Read more

Java Equivalent to Python Dictionaries

Python’s dict class is an implementation of what the Python documentation informally calls “mapping types”. Internally, dict is implemented using a hashtable. Java’s HashMap class is an implementation of the Map interface. Internally, HashMap is implemented using a hashtable. There are a few minor differences in syntax, and I believe the implementations are tuned slightly … Read more

Compile time string hashing

This is a little bit late, but I succeeded in implementing a compile-time CRC32 function with the use of constexpr. The problem with it is that at the time of writing, it only works with GCC and not MSVC nor Intel compiler. Here is the code snippet: // CRC32 Table (zlib polynomial) static constexpr uint32_t … Read more

Strange, unexpected behavior (disappearing/changing values) when using Hash default value, e.g. Hash.new([])

First, note that this behavior applies to any default value that is subsequently mutated (e.g. hashes and strings), not just arrays. It also applies similarly to the populated elements in Array.new(3, []). TL;DR: Use Hash.new { |h, k| h[k] = [] } if you want the most idiomatic solution and don’t care why. What doesn’t … Read more

Why can a Python dict have multiple keys with the same hash?

Here is everything about Python dicts that I was able to put together (probably more than anyone would like to know; but the answer is comprehensive). A shout out to Duncan for pointing out that Python dicts use slots and leading me down this rabbit hole. Python dictionaries are implemented as hash tables. Hash tables … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)