switch-case in python

Python is a great language if you’re coding to IoT (Internet of Things) like small devices. If you’re coming from another language though you might be surprised that it doesn’t include the classic switch-case statement construct like you’d find in JavaScript, for example.

Fortunately, I just managed to create something that seems to work and the syntax isn’t too far off from the expected.

def switch(key, default):
    case = {
        0.0: 'zero-point-zero',
        0.1: 'zero-point-one',
        0.2: 'zero-point-two',
        0.3: 'zero-point-three',
        0.4: 'zero-point-four'
    return case.get(key, default)

print switch(0.1, 'Unknown')
Running this would produce “zero-point-one”. This isn’t as robust as JavaScript’s or C’s implementation but this can be adjusted for lambda functions in a similar fashion.



get to dah choppa

Today’s post title comes from the Schwarzenegger movie Predator but the dialog has taken on a life of its own in the world of memes.


GetToDahChoppa CLI tool

I’ve just completed another program written in the Go language compiler which will take an existing GCODE file for 3D printing and chop it into as many layers as you’d like.


Color by layer

You might be wondering why you’d like to do such a thing. One of the best reasons I could think of would be to print different colors on the same part. In this part example displayed, black filament is used from layers one through seventeen and white is used from layers eighteen and up. The result looks quite professional even if this is using the lowest quality setting on my printer and it took less than twenty minutes to finish.


Saving an aborted print

Sometimes things go wrong. In the example below, my (costly) carbon fiber—infused filament spool ran out during the print job, noting that the printer arrived with a faulty run-out switch. For most people, they would just start over on such a part, wasting the plastic and the hours spent and begin again.


Fortunately, you can now chop your original GCODE file to just print the missing top to save the day (and the part, of course).


go figure

For years, if I needed to write a computer program, I’d have used one of the following: C, C++ or C#. Those have been the mainstays of programmers who needed an executable program for at least the two decades. Today, though, I’ve just written my first executable in a new language that’s surprisingly easy to work with.


The Go language is like the new kid on the block of compilers. Like the ones mentioned before, it will take text and convert it into instructions the computer can do.

Probably the best thing about the Go language is that it’s entirely open-sourced. If you wanted to work on the compiler itself, you could do so.


The program I’ve just written is technically called a Command Line Interface (CLI) program and will display technical details inside the selected GCODE file for a 3D print job.


Typical session of the program in use:

$ SlicingInfo RC_3DBenchy.gcode
Slicer:          Cura_SteamEngine 2.3.1
Layers:          239
Quality:         low
Profile:         Low Quality Robo C2
Filament size:   1.75
Hotend temp:     190
Bed temp:        0
Supports:        False
Retraction:      True
Jerk:            True
Speed 1st layer: 10
Print speed:     50
Travel speed:    80
Infill pattern:  cubic

nostradamus, the java-killer

Oh snap! Did I not call this one in my earlier post from twelve months ago pre-dating their announcement?

Riddled with security bugs, an A-list of browsers disabling it by default and the smack-down from the Dept. of Homeland Security advising everyone to disable it, Oracle is licking its wounds in this war-of-the-big-boys.

“Oracle plans to deprecate the Java browser plugin in JDK 9. This technology will be removed from the Oracle JDK and JRE in a future Java SE release.”

Show me the money

There are some big players in the development platform space. And they’re up against the world of open source now and I’m sure that’s got them running a bit scared, even if they are huge in size.


Each of these players is pushing their own ideas about how the future coder will do their job. At stake are monies in the advertisement space (search engines, for example); streaming and provisioned content (iTunes); as well as the very tangible aspects of software compatibility with their collection of products.  And of course, there’s Amazon, eBay and even Wal-Mart who each have their own ideas about all this.

Trust me, these players are obsessed at the moment with the world of open source and it wouldn’t be surprising to me if, say, Google or Apple were to buy out jQuery or MongoDB or even MySql. To own the tiny development company behind something like this is to own its future. Think about it, if you were John Resig of jQuery and Google opened up their checkbook would you roll over on the community and sell out? How many millions would it take before you did?


I guess my advice is to learn and use several good platforms and keep them in your toolbelt, so-to-speak. But don’t embed everything you do with any single tool or you will find yourself obsolete as a coder.

In my past I’ve learned MS-DOS, assembly language, BASIC, ARCnet, WordPerfect, NetWare, the earliest Microsoft Windows, Token-Ring, OS/2, Ethernet, Borland Pascal, C programming, etc, etc, etc. As indicated though, some of these skills are no longer useful so it’s important every month of your career to look for the signs of a dying technology. The way I do this is to follow the big money, watch these “poker players” for any tell-tale signs that they’re about to make a bold move. Obviously, most of the big players didn’t like Java and it was only a matter of time. If you were cynical you could even imagine Microsoft paying security companies to find and publish Java-related flaws.

Read more

Oracle says they’re pulling Java • Oracle’s blog entryAn embarrassing/deleted blog post from Oracle’s CSO