Navigation


RSS / Atom



Chibios/RT docset for dash.app/zeal

2014-12-05 , , , Comment

The dash.app is a great little offline API/documentation browser (there’s also zeal, which compiles on Unix/Linux and Windows). It’s fairly easy to produce your own docset so I put together one for ChibiOS/RT version 2.2.6, the open source RTOS I’m working with. Download (11MB) org.chibios.tgz from Google Drive.

Comment


D Language

2014-04-19 , , , Comment

I recently had to write a moderate amount of C around vendor libraries and get things working in three days. The effort resulted in about 3200 lines of ugly, hastily written code that compiled under gcc and clang with -Wall -Werror -pedantic and looked reasonably leak-free in Valgrind. I whittled it down over the following week as time permitted to a bit over 2000 lines.

Lines of code is a lousy metric, but it’s easy to extract using available tools. Here are the counts from cloc for the original two projects in C:

-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
C                                3            298            193           1869
C/C++ Header                     3             32              0            178
-------------------------------------------------------------------------------
SUM:                             6            330            193           2047
-------------------------------------------------------------------------------

Quick passes with grep counts 11, 13, and 16 functions.

A better metric might be complexity. Running it through the cyclomatic complexity checker cyclo results in scores of 79, 99, and 110. These seem completely off the charts (10-15 is the recommended range for a “module”). Quick runs against some code I had lying around shows that these numbers are high (OpenBSD’s strncpy and a naive CRC-16 implementation I had both score a 5, SolarDesigner’s concat function scores a 12) but we can use them for comparison. Let’s torture the numbers by averaging, 13.3 functions and a score of 96, for about 7.2 complexity per function.

I’m always on the look out for an advantage (I need them…) and saw a recent announcement of a release of the D Language compiler. The features piqued my interest: native compilation, garbage collection and dynamic memory, types, classes, interfaces, mixins, exceptions, extensive standard library, and an easy interface to C. Walter Bright, the language designer and writer of the reference compiler, is well known. There’s a decent website, a tutorial, and C++ guru Andrei Alexandrescu wrote the book on the language. Cool, I thought, a better C++. I bought the book, started coding familiar tasks, and dug in during my little free time.

It went easily and I had a satisfactory result in a few days. The equivalent in D:

-------------------------------------------------------------------------------
Language          files     blank   comment      code    scale   3rd gen. equiv
-------------------------------------------------------------------------------
D                     2       109        96       709 x   1.70 =        1205.30
-------------------------------------------------------------------------------
SUM:                  2       109        96       709 x   1.70 =        1205.30
-------------------------------------------------------------------------------

Notice that I’ve reduced the number of files, I’ll get to that. The pass through grep counts 8 and 13 functions, of which 3 of them in each source file are two-line logging routines to replace the classic C preprocessor macros dbgprintf and errprintf. cyclo doesn’t perfectly handle D, but it’s reasonably close in syntax to C/C++, producing scores of 45 and 61. Twisting numbers again gives 10.5 and 53 for a score of about 5 per function. The improvement in complexity is on par with the reduction in lines of code.

The kicker is that not only are the D versions are shorter and easier to comprehend, they do more and have more robust error-checking and exception-handling. Overall I’m more confident they behave correctly. I replaced two independent programs with a single one. I replaced a throttled fork()-ing server with a fixed pool of workers. I leveraged associative arrays, JSON, and Base64 without rolling my own or borrowing from other Open Source libraries. None of this is stuff I couldn’t implement or find somewhere but I didn’t have to. Classic force multiplier of a programming language.

Comment


Best running glasses yet!

2014-03-22 , , , Comment

Quick plug: Pyramex Intruder and 3M Tekk Virtua safety glasses.

I run for recreation and fitness whenever I can, nothing extreme and, honestly, not often enough, and I wear eye protection because my eyes tear up profusely which distracts me. I bought a few of these safety glasses as disposable eye protection for around the forge because they were $3-$4 each from Amazon but they’re great for running. They fit very well, the optics are excellent, they don’t slip off my face from sweat, and I don’t worry about scratching them, stuffing them in a pocket, cleaning them on my shirt, washing them with whatever kitchen spray or detergent is on hand, or losing them. If I drop a set and they get scratched I’ll pitch them and take out another set, except I’m still using the same two pairs I started with sixteen months ago! They take so much abuse that after all that time they have only minor wear and tear on the lenses, not enough for me to notice during activity.

Comment


Burst Battery

2013-05-19 , , , Comment

The spare Macbook Pro battery burst overnight. It was sitting on my desk fully charged.



I’m glad it wasn’t in the laptop.

Comment


VoIP, SIP registration, and timeouts

2013-05-08 , , , Comment

Quick comment… Everyone in the family has multiple devices— phones, tablets, game consoles, computers— and these tend to make network connections that linger. If you have a firewall like I do, the default TCP and UDP timeouts are probably too high (often 3600 seconds) and when everyone is around on the weekend you get poor performance and strange complaints about how things don’t work. Separately, I have an OBI100 VoIP device providing phone to the house. The OBI100 has a default SIP registration period of 60 seconds and re-registers after half the interval, this is a bit too frequent so I have mine set to 300 seconds. As I’ve found, if the firewall expires the connection quickly you can end up with what looks like a valid registration at the SIP provider and can make outgoing calls but incoming calls fail. I’ve worked around it by expiring connections at 360 seconds for TCP and 180 seconds for UDP.

Comment


Taking a level

2013-04-23 , , , Comment

Four and a half months ago I began training in Krav Maga to raise my fitness and to pick up a bit after laying off martial arts for fifteen years. In addition to my three days a week regime of running, sit-ups, pull-ups, and push-ups, I train Krav Maga three days a week. This past weekend I took and passed my level 1 test and I feel like I took a level in Badass. The test was tougher than my expectation, harder than the warnings I heard from the other students and harder than I’d estimated from the youtube videos I’d seen. We were warned that if anyone didn’t push hard enough, didn’t check and guard after our moves, or didn’t drop the pad and guard at a transition we would do extra burpees. That didn’t happen. It still pushed me completely past what I thought was exhaustion while still being able to fight.

The test began with a warm-up and then we spent sixty or seventy minutes doing full speed, 80-90% force combatives and defenses. We covered everything we’ve done in class— hammer fists, straight punches, combinations, elbows with a forward burst, elbows to the side, high, and low, groin kicks, stomp kicks, round-house kicks, kicks with an advance, knees, ground defense, ground kicks, pluck and buck defense for a ground choke, clearing and getting away safely from the ground, inside and outside defenses. After the techniques we did rounds of partnered “band sprints”, where you wrap a belt around your waist and drag your partner as you drive with your legs, and knee strike drives. There were three thirty-second breaks to change pads and sip water over the whole test and I was grateful for every one of those pauses.

Then came the reality-based defense portion of the test. Our assistant instructor donned a riot suit and I stood in the middle of the mat with my eyes closed while music blasted. He attacked and I defended, fighting my way clear. After each I’d drop and do three push-up burpees before returning to the center of the mat to wait for the next situation. I can’t remember which ones he did except for the headlock from the right side and the pushing front choke. I only remember those because I was really surprised at how hard he nailed me.

At some point in this sequence of attacks the assistant instructor took me to the ground and I struggled to fight him off. I remember thinking he’s smaller than me and not gripping, I don’t feel anything on my limbs, just weight on my back and shoulder, I should be able to just stand up and turn shrugging him off so I can use my elbows and kicks but my legs wouldn’t work right. In the exhaustion I was going on automatic. My instructor yelled something like “fight out!” so I drove my hand into the face mask and hook-punched at my attacker’s kidneys and ribs until I slipped out and could hammer punch his back and neck. I could barely pull up to a defensive posture by this point but there was at least one more attack, I can’t remember.

When the cycle was over, I did ten more push-up burpees. I was panting, I was bruised (including a nice abrasion on my check and occular orbit from either a headbutt or contacting the mat, I don’t know which), but I had passed.

Comment


« Older Posts   

invention-contempt