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.

 

python

remember internet radio on itunes?

Years ago on macOS and when iTunes first came out, it included an awesome feature—you could easily stream Internet radio from within the interface in iTunes. Apparently that got in the way of Apple’s revenue on iTunes, always trying to sell you something.

morpheus

iTunes -> click on the down arrow next to Library -> Ctl+click Songs -> Edit List -> add a checkmark next to Internet Radio

 

And that’s all it takes to return this sought-after feature to iTunes.

Screen Shot 2019-02-11 at 12.06.24 PM

kivy, the hero of iot gui developers

Kivy – An open-source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps.

The Internet of Things (IoT) is the likely future of gadgets and devices that you’ll have in your homes and cars (if you don’t already) as well as technology that you wear. As a minimal criteria, these things use the cloud to gather and store information. In a way, even smartphones fall into this category if you think about it. Amazon’s Echo device is a good example.

For many of us who self-identify as “makers”, we use small computers with similar capabilities and we create these type of gadgets. Often when we’re coding software in this space, the Python language is the usual choice for the task.

Until now, we’ve not had many options for displaying graphical menus on such tiny screens other than the full “Desktop” GUI of some Linux-like operating system which didn’t really work, to be honest.

Introducing Kivy

A relatively new technology is the Kivy library. Imagine being able to describe the many screens you’d find in an application, whether it’s a smartphone or the touchscreen of a printer or even a watch. Then Kivy takes care of the rest for you, rendering those screens using a graphics engine behind-the-scenes. It even manages clicks and other gestures, getting these to fire off portions of your code.

Kivy comes equipped with an impressive collection of pre-defined screen widgets as well as the ability to create your own custom types. And you get all this for the low, low price of free (unlike its $5K+/year—priced competitor Qt).

I’ve had the pleasure of working on an almost daily basis with Kivy over the last two months and I must say that I’m still just as fond of it now as the day I originally learned of it.

If you’re a coder and you know Python, I would suggest that you add Kivy to your toolbelt. You’ll find that it’s easy to use and worth the effort you put into it.

metro app is metro

I thought I’d share a couple screenshots of a web app I worked on a couple of months ago. I was cleaning up my computer’s Desktop space today and it made me smile, remembering the work that I’d done then.

I doubt if I’ll continue the project since I’m now working on something new.

home

login

The site was to be a code-learning area for kids. The requirements for not using/saving personal data was the reason for the interesting username behavior shown above. Usernames are combinations of adjective-noun and passwords then are combinations of color + icon.

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

goo.gl broke it

Jumping into the Wayback Machine to the year 2010, Google introduced a means of shortening URLs. Since they’d purchased the goo.gl domain name, they took advantage of this plus an abbreviated means of issuing shorter URLs. The shorter URL would then redirect to the actual target address.

Why?

You might ask why Google would create a seemingly-free service that would redirect URLs for people. Part of it could be explained by re-using a domain name that sounds a lot like Google as a form of advertising their brand name. But the strongest reason would be to build a database of URLs which could be mined in some way, perhaps for their own search engine’s optimization.

It’s clear that analytics was a big reason for offering a service like this. There is value in knowing everything about what other people are doing.

And den?

Good question. What comes next after the Internet has then embraced the concept and created millions of shorter links? You guessed it…

Google is killing the [goo.gl] service in March of 2019.

What will break?

It’s difficult to even fathom how much of the Internet will take a hit in three months. People routinely used these shorter URLs in combination with both Google Drive— and Microsoft OneDrive—related documents. There are numerous one-off solutions which automatically submit URLs to goo.gl vicariously for you. These should be the first things to break.

Google will likely continue to redirect links for a while but they will eventually need to pull the plug.

Imagine the sheer number of times these shorter URLs were used in printed documentation to refer back to online support pages. This would have been typical of many consumer products with small printed manuals. Imagine the number of boxed consumer products still sitting on shelves in stores which contain these soon-to-be-deprecated links.

Is that it?

Google is now moving the service over to Firebase (which they bought in 2015) as Dynamic Links which presumably few people will use since they’re not Google Developers.

 

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

a series of unfortunate search results

IanCalderon
Calif. lawmaker Ian Calderon proposes jail time for anyone who brings you a drinking straw.
WhiteHouse
Press Secretary Sarah Sanders describes how presidential hopefuls are recruited from the private sector.
CIA
If even the CIA can’t find you, then you are well-hidden indeed.
UnsolvedMysteries
You would think that they work work on the important questions.
Harvard
This puts a whole new twist on “higher” education.

 

Whittier
Richard Nixon was educated at Whittier College.
Forestry
Important issues were discussed at the conference, to be sure.

programming through advertisements

Imagine an alternate universe to ours, similar in many ways. Watching television and browsing through magazines is the norm in this world. Just as we in our universe have ad impressions and our own ideas about society are shaped in this way, the people in this other universe are also programmed on a daily basis. How to treat others, what to wear, what to eat and what’s socially-acceptable and even expected are all topics which are schooled, if-you-will, in both worlds by our & their collective media “teachers”.

Using some pretty sophisticated multi-universe equipment that I’ve just invented, I’ve managed to pull some of their advertisements across the ether over into our world to share with you but a warning: some of these images may seem shocking to you. One can only imagine what a wretched society would result from social programming such as this.

This slideshow requires JavaScript.