21/10/2014
For last week’s entry, I wrote a small script to monitor my wireless keyboard’s activity, logging keys, and mode changes. This week, let’s have a look at the data we can grab, and what we can do with it.

So, after grabbing keyboard activity for a bit more than a week (from 2014-10-12 22:47:31.059636 to 2014-10-20 08:45:06.733120), we’re ready to preprocess the logs and extract useful information.
Read the rest of this entry »
2 Comments |
Bash (Shell), hacks | Tagged: Bluetooth, Keyboard, wireless keyboard |
Permalink
Posted by Steven Pigeon
14/10/2014
So, again, I got a Bluetooth keyboard. This time, I’m pleased with the fact that it will, in principle, never need to have its batteries changed. It’s solar. I got the Logitech K760.

So of course, I set out to test it a good while before concluding whether or not it would be charged enough to keep up with me. But how much typing do I do in a day? Well, let’s find out!
Read the rest of this entry »
5 Comments |
Bash (Shell), hacks | Tagged: Bluetooth, HCI, Keyboard, wireless |
Permalink
Posted by Steven Pigeon
30/09/2014
One of the tools I use to make figures for papers and books—if I need to make a graph, of course—is Graphviz. Graphviz is flexible, powerful, but also a rather finicky beast that will repeatedly bite your fingers. Today, I’ll share some of my tricks with you.

Read the rest of this entry »
2 Comments |
Design, hacks | Tagged: graph, graph theory, GraphViz, layout, lecture notes, patience, planar, planar graph |
Permalink
Posted by Steven Pigeon
02/09/2014
You’ve certainly heard of Fermat’s last theorem stating that

has no integer solutions for
. Well, guess what:
.
Take that, Fermat!
Read the rest of this entry »
Leave a Comment » |
algorithms, hacks, Mathematics | Tagged: Fermat, Fermat's Last Theorem, integer solutions, number theory |
Permalink
Posted by Steven Pigeon
06/05/2014
last week, we saw that we could use a (supposed) efficient machine-specific instruction to derive good bounds (but not very tight) to help binary search-based and Newton-based square root extraction algorithms go faster. Last week, we saw that the technique did lead to fewer iterations in both algorithms.

Now, does the reduced number of iterations translate into actual, machine speed-up?
Read the rest of this entry »
3 Comments |
algorithms, C, C-plus-plus, hacks, Mathematics, programming | Tagged: Newton, Square root, Square Roots |
Permalink
Posted by Steven Pigeon
29/04/2014
Computing (integer) square root is usually done by using a float square root routine and casting it to an integer, possibly with rounding. What if, for some reason, we can’t use floats? What are the possibilities?

One possibility is to use binary search to find the square root of a number. It may be a good choice because it will only perform a number of iterations that is half of the (maximum) numbers of bits of the number (we will explain why in a moment). Another possibility is to use Newton’s method to find the square root. It does a bit better than binary search, but not exceedingly so: on very small integers, it may iterate a third as much iterations as binary search, but on large integers, it will do only a bit fewer iterations. Can we do better? Yes!
Read the rest of this entry »
10 Comments |
algorithms, hacks, Mathematics | Tagged: Binary Search, bllaarrghghglblbl, Logarithm, Newton, Square Roots |
Permalink
Posted by Steven Pigeon
15/04/2014
In the recent panic surrounding the Heartbleed bug, we ask ourselves why, and how, these bugs still happen. We know that it was a preventable bug, with a simple fix, but with potentially important repercussions.

The bug is explained in non-technical (but accurate) terms here, and the patch is shown here. But that’s not what I want to talk you about. Let’s discuss the source of the problem.
Read the rest of this entry »
4 Comments |
algorithms, Cryptography, hacks, programming, Zen | Tagged: heartbleed, KISS, nonce, OpenSSL, ping, runcible, Simplicity, SSL, SSL certificate |
Permalink
Posted by Steven Pigeon
18/03/2014
Nothing too this week: how to convert a Djvu or PDF to hard black and white PDF—not shades of gray. Why would you want to do that anyway? Well, you may, like me, have a printer that has no concept of color calibration and has dreadful half-toning algorithms, resulting in unreadable text and no contrast when you print a Djvu or a PDF of a scanned book.

Read the rest of this entry »
Leave a Comment » |
Bash (Shell), hacks | Tagged: black and white, convert to black and white, Djvu, half-tone, half-toning, pdf, printing |
Permalink
Posted by Steven Pigeon
04/02/2014
One good thing with 64 bits addresses, is that you can, in principle, use essentially as much memory as you want—the address space certainly exceeds today’s computers’ capabilities. One bad thing, especially when you create lots of objects and need plenty of pointers, is that 64 bits pointers are big. They use 8 bytes of memory. One or two pointers aren’t a problem, of course, but what if your data structure is a sparse graph, each node being mostly pointers, and that you need to create a very large graph?

One solution is to use stretch codes, as I proposed a while ago, trading off precision of addressing for shorter pointers. However, unless you rewrite the memory allocator, the technique won’t play well with the default new. Another solution is to store just barely the number of bits (rounded to bytes) necessary to hold an address. Can we do this? If so, how?
Read the rest of this entry »
3 Comments |
C-plus-plus, data compression, data structures, hacks, programming | Tagged: 64 bits, address space, stretch codes, virtual memory |
Permalink
Posted by Steven Pigeon
14/01/2014
Last week we discussed GCC intrinsics a bit. This week, let’s have a look at what kind of speed-ups we can get, and how the use of intrinsics affect code generation.

Sometimes, I do strange things. I mean, my experiments aren’t necessarily self-evident, and sometimes, I need performance from primitives that usually are not bottlenecks—such as computing the GCD. This time, I need to get
and
in
as fast as possible. Let’s have a look at how intrinsics help us.
Read the rest of this entry »
4 Comments |
bit twiddling, C, C-plus-plus, hacks, programming | Tagged: clz, code optimization, g++, gcc, Hacker's Delight, intrinsics |
Permalink
Posted by Steven Pigeon