to author or to fork?

I was interested in exercising Github’s REST API so I burned out a quick-and-dirty applic-ation to display some statistics.

Screen Shot 2019-01-02 at 1.53.46 PM

Honestly, a tool like this would be useful for a hiring manager in the software develop-ment space. Imagine being able to enter a list of ten accounts and to see a side-by-side comparison of the coders like this.

Puffed-up Like a Cheeto

I’m surprised at the number of Github accounts which are mostly filled with dead forks of someone else’s code with no contributions whatsoever. I don’t know if people are trying to pad their profile intentionally or if they just are unclear of the cloning behavior expected of them most of the time.

A good collection of code should include mostly your own authored work. You’re hoping to give something back to the community. From the standpoint of your résumé, you’re hoping to show what kind of work you’re capable of doing.

So What’s Good?

I think I’d suggest that for anyone who’s looking for a new position as a coder, that Authored percentage value should be above 75%. I suppose the theoretical limit of 100% could potentially be the best and yet it would likely indicate that you don’t help out other coders with their repositories.

Rule of Thumb

If you fork a repository, you should do one of two things:

  1. immediately start creating your own new software from it or…
  2. immediately start working to help the original author so as to create a pull request.

This behavior of fork-and-do-nothing just seems patently wrong to me. If you think about it, it’s almost the equivalent of copying someone else’s résumé content into your own.

ms-dos is now open… 36 years too late

I suppose Microsoft is trying to go with this whole… open source thing that the rest of the world embraced a long time ago. They’ve just placed the source code for MS-DOS out into the public domain about three or four decades after it’s useful. Seriously, guys?

It’s probably lost on most people that this code is utterly useless, unless you have access to a time machine, of course. In order to assemble the code you’d need MASM v1.10 which is a very old Microsoft Assembler program indeed. I remember actually owning that about thirty years ago, believe it or not.

Obvious chicanery

Looks like whoever made this available has added a number of poison pills: file-renaming, garbage characters to prevent assembly, the absence of an old (required) assembler, etc. It’s so blatant it would be funny otherwise.

disengenuous

adj. Not straightforward or candid; insincere or calculating

rpi-update => bricked raspberry

The Internet is full of advice. This is especially the case in the world of Raspberry Pi tutorials. The problem is that sometimes you get an anti-pattern with respect to upgrading the Pi’s firmware and/or operating system: people are confused and they’re giving the wrong advice. And then this same wrong advice is repeated over and over.

Two Upgrade Paths and Only One Is Correct

There are two paths available to people so that they may upgrade their Raspberry Pi. One is for a tiny fraction of the coders out there, those who actually create the Raspbian operating system itself. And then the other path is for everyone else.

Incorrect:
sudo rpi-update

Correct:
sudo apt-get update
sudo apt-get -y upgrade

Why is This?

Unfortunately, the people who wrote the Raspbian operating system included the tools they themselves use to develop it. Just because it’s there as a command line tool, that doesn’t mean that most of us were supposed to use it.

Granted, people will take the fewest steps to get somewhere. If they think that they can save a few characters with what looks to be a simpler command, they’ll try to use it. If things don’t figuratively blow up in their face, they assume it’s good and they’ll give this advice to others.

What’s the Difference?

When you run the sudo apt-get -y upgrade version, you’re pulling the latest code from the stable master branch of Raspbian. That sudo rpi-update command instead pulls from the development branch known as next. It’s a great way of trashing your Ethernet and wi-fi driver stack so that you can no longer get to it remotely, turning your Raspberry Pi into a brick.

brick

the zen of source code formatting

 

Source code—assuming for a moment that you didn’t already know this—is a collection of (often English) words and symbols for humans which usually is turned into something more meaningful for a computer to understand when the program is running. Each computer language has its own rules about how you order the words and symbols but most allow for a fair amount of leeway with respect to whitespace, the “rests within the melody”, if-you-will.

“most [computer languages] allow for a fair amount of leeway with respect to whitespace, the rests within the melody…”

“Source code formatting is the task of using that whitespace to maximize… something.”

Source code formatting is the task of using that whitespace to maximize… something. This of course means different things to different people. For some, they believe that source code formatting can be done only one way. To format code using any other method, in their mind, would be the equivalent of breaking some sort of law.

Others believe that your text editor knows best and should be the authoritarian on the matter. There’s usually a feature to “format document” which they believe always gets this right.

As someone who’s been coding now for almost forty years, I’d like to share what I’ve learned and to permission you to completely ignore those first two camps who would say that you must do it their way.

The Virus

In my humble opinion, nearly all of the source code formatting as seen in the world’s collection of code suffers from poor readability. And this is so because of the attitudes surrounding the topic as well as the self-imposed “leaders” and big players who believe their way is better, demanding adherence to their own opinions.

In many software development firms, this is a hot topic for debate. Coders feel strongly about how all this plays out. Outspoken individuals like Douglas Crockford (author of jslint) have even developed tools to enforce their own (wrong) ideas about how code must be formatted.

As large corporations like Google publish more in the open source area, they bring with them this kind of Draconian mindset. If you bring in their code, you’re very likely also bringing in format-enforcing restrictions which come along for the ride.

“If we think of jslint as a virus that self-propagates, then cloning a Google-published project has now infected your project.”

I have personally been held hostage for days trying to make the jslint build tool happy when I’ve been forced to use it. It’s one of the worst anti-patterns I’ve seen in this industry, to be honest.

An Innovative & Meaningful Method of Formatting Your Source Code

For me, I choose to maximize whitespace instead so that I may understand the code instantly. The more I understand the code, the less likely it is that I will later introduce a bug into this code. The faster I can speed-read the code, the more productive and happier I’ll be.

“Code Complete” by Steve McConnell

The genesis of this new method comes in part from my having read this excellent book at least twenty years ago. At the time, this was ground-breaking in its revelations of coding statistics with respect to bugs and the impact of good source code formatting to minimize their presence in code.

My method goes beyond the author’s original suggestions and is the work of a couple decades in the making.

A Practical Example

Below, I show a pair of examples. It is the same code, just differently formatted. The code language is JavaScript and is written for NodeJS, more specifically. The other examples below also are written in JavaScript.

Before (classic jslint-like formatting)

Screen Shot 2018-11-29 at 12.20.13 PM
Figure 1

After (new, suggested method)

Screen Shot 2018-11-29 at 12.22.26 PM
Figure 2

Hopefully you will see the appeal to the second method. The spacing in Fig. 2 allows us to quickly see that this section includes the creation of several variables by pulling them in from separate files and modules. Additionally, they are alphabetized to make it easier to spot accidental double-inclusions.

Given the column-like behavior and the symmetry of those “require” functions, it’s now much easier to scan down the list. It’s now a pleasure to read.

Before (classic jslint-like formatting)

Screen Shot 2018-11-29 at 12.30.22 PM
Figure 3

After (new, suggested method)

Screen Shot 2018-11-29 at 12.17.01 PM
Figure 4

Here, by tightening up the first/third activities to become single-line events in Fig. 4, it’s easier to then see that we have what appears to be a sandwich-like construction:

  1. fs.closeSync() something
  2. create a variable
  3. fs.closeSync() with that variable

The second activity now has some pretty radical source code formatting. But it follows the column rule introduced from before:  columns make assignments easier to scan.

1) The Column Rule

To sum this up: use consistent whitespace to create columns out of assignments (storing a value into a variable). This applies to multi-line assignments as well as to assignments which take more than one line to accomplish.

Create columns: “…use consistent whitespace to create columns out of assignments…”

2) Squash for Readability

If it is possible to remove vertical space so that an entire function may be reviewed in one screenful in your editor, then consider doing so. Good candidates for this treatment are the open/close pairs of file functions seen in Fig. 4. The pairing makes sense to most coders so it’s a welcome form of abbreviation.

Squash: “If it is possible to remove vertical space so that an entire function may be reviewed in one screenful in your editor, then consider doing so.”

3) Comment the Breadcrumb Trail

When there are several levels of braces in one group at the end of something, clearly comment each with judiciously-provided whitespace so that they line up as a column as seen in Fig. 5.

Screen Shot 2018-11-29 at 12.45.00 PM
Figure 5

Breadcrumbs: “When there are several levels of braces in one group at the end of something, clearly comment each with judiciously-provided whitespace so that they line up as a column…”

4) Semicolons for Readability

Use line-ending punctuation to tell one type of scope/block from another. In Fig. 5 above, fs.readdir() and fs.unlink() as function calls are each terminated with a semicolon after the ending brace. Here, I’m omitting the terminal semicolons for both the sections in the if blocks and the for loop at their ending braces.

Semicolons: “Use line-ending punctuation to tell one type of scope/block from another.”

I’m sure this one will have its critics. I would argue that the introduction of chained functions and the concept of “Promises” have created some rather interesting “dogpiles” of code at times which are too difficult to follow without this strategy.

Applicability to Other Languages

The suggestions indicated also apply to other languages. One notable caution, though, goes out to Python-related code which is fairly picky about beginning indentation style. The beginning of each line of Python marks logical blocks of codes as you might see in a matching pair of braces in JavaScript. It’s therefore critical to first make Python happy in this regard before attempting to then adhere to these suggestions. The continuation line technique seen in Fig. 4 above would not work in Python for this reason.

insight landed, still no actual photos

Let’s see… NASA’s InSight probe supposedly landed on Mars back on Monday. Visit their website two days later and there are lots of videos and photos, all of which are CGI-generated or they’re hours’ worth of employees looking excited.

Here’s one I’ve managed to dredge up though:

mars

Is that the best we can do for the US$1B price tag? Presumably, it’s a down-facing camera with a frog-eye lens.

Yet again, it feels like lies stacked on top of lies to me.

recycle, re-use, re-purpose – part ii

Continuing with the work to re-purpose a computer mouse as a filament movement detection device, I designed and printed some parts for this. The bottom part is perhaps 5mm in height from the spool itself and is reasonably a good distance to see changes.

I’ve edited the earlier Python script which originally detected the scroll wheel button; it’s now detecting movements of Y as if the mouse were being moved on a mousepad. It will only do this if I take the white assembly and move it around on a patterned surface, however.

To help the mouse detect movement better, I’ve tried using both grid paper and a polar version of same. I don’t love the feedback loop that’s going now. I’m sure there’s a better way to get this movement detected all the time, though.

IMG_0115

IMG_0116

IMG_0118

recycle, re-use, re-purpose

This week’s project involves dealing with filament-delivery problems on my 3D printer. Out of the box, the filament runout detection never worked. Frankly, it was a terrible design to begin with from the manufacturer and I’m convinced that someone at the factory just turned off that behavior anyway.

As a result of this, I’ve lost a few print jobs over the last year. In only two cases, I simply ran out of filament for large parts. In all the remaining cases, a number of problems contributed to the loss of filament delivery to the printed part:

  1. simple end-of-roll loss of filament
  2. spool sticking to manufacturer’s poorly-designed spool holder
  3. cross-threading of the filament on the roll
  4. hot-spooling the filament at the factory which resulted in filament which sticks together
  5. filament like carbon fiber—infused which likes to stick to itself
  6. old filament which is now brittle and breaks as a result
  7. overall poor design of the spool (boxy) shape itself, resulting in cross-threading
  8. overall poor design of the filament delivery path itself, resulting in too much force needed to extrude
  9. filament thickness quality issues as combined with PTFE feed tubing, resulting in stuck filament in the tube
  10. too-flexible filament as combined with any of the conditions above, resulting in filament notching at the bowden gear
  11. z-offset too close to the bed, resulting in hotend jamming
  12. poor first-layer adhesion, leading to a build-up of filament and ultimate hotend jamming

Now granted, the bowden drive for this printer is one of the beefiest NEMA 17 style of stepper motors I’ve seen. And yet the number of filament delivery—related problems is just too high to continue to ignore. So I’ve decided to finally deal with the issue rather than working around it.

Ideas & inventions

Remove the stock holder, add bearings to its replacement

I designed, printed and assembled a very good dual-spool filament delivery system which worked much better than the stock filament holder. I sometimes still use it.

DSC_0062

Dual runout switches

Perhaps six months ago, I designed, printed, sourced parts for and assembled a very good dual-spool filament runout detection block to replace the stock part. I have yet to install it since I’m not in love with the idea of the filament path beginning at the table level. Time has taught me that the spools need to be higher than the printer for this to be optimal. As designed, though, it works in principle to detect loss of filament from both spools.

DSC_0211

And yet, this entire concept does not directly address the problems associated with cross-linked filament. It only addresses the loss of filament as seen in a switch.

Parabolic spool guides and re-purposed monitor stand

Additionally, I designed, printed and assembled parabolic spool guides to better deliver filament (especially for hot-spooled or otherwise sticky filaments like carbon fiber). This I combined with a designed/re-purposed dual-monitor stand to move the spools above the printer rather than below.

SpoolHolderOverhead

SpoolHolderWithBracket

Remove the temperature gradient

First-layer adhesion was aided by adding a foam enclosure/door and a temperature-monitoring Raspberry Pi 3B to the inside (opposite the internal webcam). The latter helps to heat up the print volume area, keeping things from 90-100 degrees Fahrenheit.

foam

Remove the PTFE tubing

Filament diameter inconsistencies resulted in filament getting stuck in the PTFE tubing. I now rarely route the filament through the tubing, having removed the awkward bottom-to-top filament delivery path from earlier.

And finally, a filament movement detection mechanism

This weeks work then revolves around fixing the underlying problem. The solution isn’t filament runout detection. The more accurate problem and better solution is actually loss of filament movement and its detection.

When I began to think of solutions, in my head I was adding black/white encoder rings to the sides of the spools themselves. I would need to add those to all spools of course. I’d also need to design something which reads those as ones and zeroes.

I decided that a roller/follower which is turned by the spool is also a solution. I then envisioned writing drivers and creating a small circuit board for all this so that it could talk to Raspbian, the operating system which OctoPrint runs on.

Mouse to the rescue

Finally, it hit me that a standard computer mouse does this naturally. The older style of ball mouse has a follower which detects when the ball is moving. Even the newer style of mice still have a scroll wheel which is covered in rubber and would do nicely. In my imagination, the first iteration of this had the filament trapped against that rubber wheel. In today’s version, the wheel merely comes in contact with the side of the spool itself for the win.

As a bonus, the computer mouse already has the serial communication and Linux driver built-in. It was trivial to write a small Python script to detect scrolling events.

no mice will be harmed … in the making of this gadget.

The mouse should fit nicely and without any modifications to a 3D-printed holder. The serial connection goes to the Raspberry Pi and is then detected in an OctoPrint plugin. During a print job the scrolling events will be monitored; any loss of scrolling over the sampling period will then pause the job and alert the operator with a sound event.

rat on computer mouse

rip, red hat

Say it isn’t so.

Since the end of October is all about scary stories… Just on the heals of Microsoft buying github for US$7.5B last year, IBM has now has purchased Red Hat Linux for a cool US$34B dollars.

Screen Shot 2018-10-30 at 12.34.56 PM

Granted, I haven’t used Red Hat in a few years mostly since it is one of the few paid UNIX-based operating systems out there. Ubuntu, backed by Canonical, is clearly the better choice for anyone who knows what’s going on.

IBM is the antithesis of open-source software, as is Microsoft. This is just sad. But good riddance. Now get in the hole, Red Hat.

this-is-capitalism

meetup tonight

I’ll be giving another lightning talk this evening downtown at the San Diego JS meetup. I get to talk about the Autonomous Tank project and the code behind that.

SDJS

Since I no longer have a corporate-sponsored license of Microsoft PowerPoint, I had to improvise for my overhead slideshow this time. So I did what most coders would do in this scenario: I coded something for the task.

Screen Shot 2018-10-02 at 2.45.50 PM

autonomous tank

I managed to snag some great track data today at the venue. It was necessary to write a service to take snapshots every second while I manually drove around the track a few times.

With data in hand now at home, I was able to do some data processing now with the images from my own webcam.

A New Perspective

I thought I’d compensate for the lines-of-perspective effect so that the trending portion of the software could have accurate data. Since Jimp didn’t have a skew function and since its convolute() method didn’t work as expected with the right matrix for this, I ended up writing my own prototype which now works as shown below.

Screen Shot 2018-09-22 at 9.34.22 PM