Robert Eisele
Systems Engineer, Architect and DBA

How to write a PHP Daemon

PHP is a language primarily used by web developers, but even these have problems which have to be scheduled to background processes, like sending newsletters, analysing stats, or simply maintaining the database. The most common way to solve this, is abusing crond for almost everything. When things are getting more complicated, like running jobs every 10 seconds people get really creative like blocking the execution or whatever silly custom.

Improving Interval Conditions

Checking if a certain number \(x\) falls into a given range between \(a\) and \(b\) is a quite easy task:

Calculate the intersection points of two Circles

How can you find the intersection points of two circles, given by the two center points and their radii? More formally: Given two circles with their center points \(\vec{A}\) and \(\vec{B}\) and their radii \(A_r\) and \(B_r\), we want to find the points \(\vec{P}_1\) and \(\vec{P}_2\) which represent the intersection points of both circles. Obviously, there can be one, two, infinity or no intersections at all, namely when one circle is completely within the other or the areas of the circles does not overlap. One way would be to formulate the two circles as their circle-formulas, subtract them and work out the x and y values. Quite simple, but needs a lot of calculations if you want to keep it fully parameterizable. Here is a different way:

Store a tag-cloud in MySQL

There was a time when tag-clouds were the thing for website owners to fancy oneself. These clouds are mostly gone, but seen from the perspective of how to implement such a thing, one can learn quite a lot, especially with large amounts of links. Anyway, imagine you publish some articles on your website, which are stored in a table "post" and you want to to add tags to every post in order to print a tag-cloud.

Simultaneously set and delete bit flags in a database

Imagine, we store bit-flags in a database as integers and want to update the bit-set by simultaneously deleting and updating the bits. An expression like this can quickly become unhandy. However, I wanted to make this solution pretty and after some tinkering I came up with a quite nice solution.

Using GPS with node.js and JavaScript

GPS is probably the best known global positioning system, even if there are other countries besides America who built up their own, like Europe with Galileo, Russia with GLONASS and the newest, BeiDou in China. All are based on the same technique, a triangulation of spheres, whose radius is the signal transfer time, given by an atomic clock on the satellite. In general, the more satellites you use this way, the better the accuracy of the determination of the location and some receivers already combine the varying systems.

Calculate the argmin of the sum of absolute values

Imagine, you have a coordinate system with some points. Parallel to the x-axis is a line, which is connected to each of the points. Your goal is to figure out what the minimum accumulated distance of the points to the line is by moving the horizontal line up and down. Look at this illustration and use the mouse to get a feeling for it: