Archive for the ‘Algorithms’ Category
Posted by jpluimers on 2020/04/09
A nice introduction to [WayBack] Hashes and their uses – The Isoblog covering:
- Checksums
- Digit sums as simple, weak checmsums
- Better checksums: ISBN-10 as an example
- Proper CRC checksums
- Hashes for storage
- Building dictionaries
- Breaking dictionaries
- Handling collisions
- Cryptographic hashes
Via [WayBack] I needed to explain Bitcoin. In order to explain Bitcoin, I needed to explain Proof-of-Work and Hash structures. In order to explain Proof-of-Work and H… – Kristian Köhntopp – Google+
–jeroen
Posted in Algorithms, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2020/01/30
A cautionary tale on time zones, and the big warning on using a unix timestamp (only 18 years to go on that one…)
–jeroen
Read the rest of this entry »
Posted in Algorithms, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2019/10/03
Interesting read: [WayBack] Ubiquity: The End of (Numeric) Error
Crunching numbers was the prime task of early computers. The common element of these early computers is they all used integer arithmetic. John Gustafson, one of the foremost experts in scientific computing, has proposed a new number format that provides more accurate answers than standard floats, yet saves space and energy. The new format might well revolutionize the way we do numerical calculations.
via:
–jeroen
Posted in Algorithms, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2019/06/27
For my archive:
I happened to notice that the Arduino OneWire library uses a 256 entry lookup table for its CRC calculations.
I did some research on this topic in 1992-1993, while working on Bulletin Board Systems, FidoNet code and file transfer protocols.
These days memory is not at a premium on most computers, however on Arduino and microcontroller environments it definitely is, and I happen to know that table-lookup CRC can be done using two 16-entry tables!
So I’ve dug up my documentation and code from the time, and applied it to the CRC-8 calculation for the Maxim (Dallas Semiconductor) OneWire bus protocol.
I think this provides a neat trade-off between code size and speed.
License For any of the below code, apply the following license (2-clause “simplified” BSD license), which should suffice for any use. If you do require another license, just ask.
Source: [WayBack/Archive.is] Calculating CRC with a tiny (32 entry) lookup-table | Lentz family blog
The example on the page is for the CRC-8 implementation used in the [WayBack] 1-Wire Communication protocol – Wikipedia.
The generator works for CRC-8, CRC-16 and CRC-32 polynomials and can be downloaded here:
–jeroen
Posted in Algorithms, C, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2019/05/23
Too bad G+ doesn’t allow the WayBack machine or Archive.is to archive the whole thread at [WayBack] [Archive.is] Das es inzwischen fast überall Standard ist die Uhren mit einem guten Zeitsignal zu synchronisiseren (NTP, DCF-77, GPS etc) ist eigentlich eine gute Sache… – Kristian Köhntopp – Google+ so here are a few quotes below.
The generatel conclusions seem to be that:
- for most jobs, especially the ones on dynamic instances like containers, you need some form of jitter
- jitter can have other words like splay
- even absolute times are no guarantee against jitter
- you can do jitter on many levels/tools, for instance:
- ensure the jitter is part of the contract between the systems producing and consuming data
This was the start:
Nils Ketelsen originally shared:
Guckt man live sieht es schon anders aus: Während die RunQueue meist so bei 4-5 liegt (bei 21vCPUs kein Problem) springt sie jede volle Minute einige Sekunden lang auf 20. Bei durch 2 Teilbaren Minuten auf ca. 40. Bei durch 10 Teilbaren Minuten auf 70, bei durch 15 teilbaren Minuten auf 150…. Ich habe eben durch einen schlecht getimten Toilettenbesuch die volle Stunde verpasst, das muss ich gleich mal anders hinbekommen, aber ich gehe davon aus, daß es da noch schlimmer ist.
And these some of the comments:
Read the rest of this entry »
Posted in *nix, *nix-tools, Algorithms, cron, Development, Power User, Software Development | Leave a Comment »
Posted by jpluimers on 2019/01/24
Cult code via [WayBack] Fast inverse square root – Wikipedia part of [WayBack] Quake-III-Arena/blob/master/code/game/q_math.c:
float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;
x2 = number * 0.5F;
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
return y;
}
It is a really fast way to approximate the square root for 32-bit IEEE754 calculations having origins around 1986:
- [WayBack] Symplectic Spacewar » Cleve’s Corner: Cleve Moler on Mathematics and Computing:
Cleve Moler replied on June 27th, 2012 9:35 pm UTC :
Jotaf — Thanks very much for your comment, and for reminding me about the fast inverse square root hack. I didn’t realize that the trick had attained a kind of cult status in the graphics community. The trick uses bit-fiddling integer operations on a floating point number to get a good starting approximation for Newton’s iteration. The Wikipedia article that you link to describes the trick in great detail, and also links to an article by Rys Sommefeldt about its origins. Sommefeldt goes back to the late ’80s and to me and my colleague Greg Walsh at Ardent Computer. I actually learned about trick from code written by Velvel Kahan and K.C. Ng at Berkeley around 1986. Here is a link to their description, in comments at the end of the fdlibm code for sqrt. http://www.netlib.org/fdlibm/e_sqrt.c . — Cleve
- [WayBack] http://www.netlib.org/fdlibm/e_sqrt.c
By now there is also a constant for 64-bit IEEE754 calculations 0x5fe6ec85e7de30da by [WayBack] 2003 research from Chris Lomont who also found a better 32-bit constant 0x5f375a86.
Note you need to be careful with boundary values like zero and infinity. This holds for approximations in general: [WayBack] performance – Why is SSE scalar sqrt(x) slower than rsqrt(x) * x? – Stack Overflow
–jeroen
Posted in Algorithms, C, Development, History, Software Development | Leave a Comment »
Posted by jpluimers on 2018/11/14
Choosing label colours other than black or white is like making a dynamic mouse cursor that inverts the colours underneath it: it fails horribly in the low contrast regions, and looks very strange on pink-noise backgrounds.
This approach is uses black and white depending on the perceived brightness:
[WayBack] How to automatically choose a label color to contrast with background | TrendCT:
What would data viz be without labels? Just viz, that’s what. This guide aimed at web designers discusses how to choose a label text color with enough contrast.

Via: [WayBack] For all those people incapable of choosing the right color combinations. – Thomas Mueller (dummzeuch) – Google+
–jeroen
Posted in Algorithms, Color (software development), Development, Software Development, Usability, User Experience (ux) | Leave a Comment »
Posted by jpluimers on 2018/10/04
Most software developers know they exist, but some (including me) find them hard to visualise, especially for combinations of operators, or for less common operators: the Truth table – Wikipedia.
The common operators that everyone seems to understand are these:
- logical
true
- logical
false
- logical
negation
- logical
and
- logical
or
- logical
xor
It becomes harder with a series of combinations, for instance series of and (not ...) and (not ...) and (not ...) – not to be confused with nand, similarly or (not ...) or (not ...) or (not ...) – not to be confused with nor, which both can be transformed according to the De Morgan’s laws – Wikipedia:
In set theory and Boolean algebra, these are written formally as

Using truth tables
Read the rest of this entry »
Posted in Algorithms, Conference Topics, Conferences, Development, Event, Software Development | 2 Comments »
Posted by jpluimers on 2018/09/11
The [WayBack] Periodic table – Wikipedia contains many symbols.
Combing them allows you to spell word. Not all words, but many of them can be spelled.
So I was glad finding the below article that started with the same fascination I had in chemistry class.
[WayBack] Spelling with Elemental Symbols
It has a great explanation of the algorithm, references to computer science literature and a nice Python implementation.
via: [WayBack] One of the best programming articles I’ve read in a while – This is why I Code – Google+
–jeroen
Read the rest of this entry »
Posted in Algorithms, Development, Fun, LifeHacker, Power User, Python, science, Scripting, Software Development | Leave a Comment »