What is ‘\0’ in C++?

‘\0′ equals 0. It’s a relic from C, which doesn’t have any string type at all and uses char arrays instead. The null character is used to mark the end of a string; not a very wise decision in retrospect – most other string implementations use a dedicated counter variable somewhere, which makes finding the end of … Read more

“cond”,”and” and “or” in Scheme

Imagine you wrote if as a function/procedure rather than a user defined macro/syntax: The problem with my-if is that as a procedure every argument gets evaluated before the procedure body gets executed. thus in atom? the parts (not (pair? x)), #t and #f were evaluated before the body of my-if gets executed. For the last example means (add (- a 1) (+ b 1)) gets evaluated regardless of what a … Read more

What is the default password for Postgres

WARNING: trust means exactly that. Anyone who can connect to the PostgreSQL server can control it. If you set trust mode that allows superusers like user postgres (or all users) to connect, they get total control of your PostgreSQL and can probably run shell commands too. You should usually only use it to change the password then restore the configuration back to the auth mode … Read more

Implementing an efficient queue in Python

As Uri Goren astutely noted above, the Python stdlib already implemented an efficient queue on your fortunate behalf: collections.deque. What Not to Do Avoid reinventing the wheel by hand-rolling your own: Linked list implementation. While doing so reduces the worst-case time complexity of your dequeue() and enqueue() methods to O(1), the collections.deque type already does so. It’s also thread-safe and presumably more space and time … Read more