NAB Win #3 – iTunes And Radio Automation For the Win!

I heard from the DJB team at NAB this year – that’s win #3 for one of our products!

To put it in perspective, over the past 5 years that’s been three awards:

  • 2013’s Radio Spider, which aggregates files from the Internet or over a server, including cloud (Dropbox/Google Drive)
  • 2014’s DJB Logger, a multiple stream recording device (hardware/Internet stream) for logging radio content for archiving, competition monitoring, or whatever. The current version is now up to 24 channels simultaneously.
  • 2017’s iBroadcaster, a new twist on Button Broadcaster Pro in that it uses the iTunes database for its library, rather than its own.

So that’s me programming three award-winning programs in 5 years – I really have got to update my resume…

How To Name The Day of the Week for Any Date – FAST (Part 2)

In part 1 we saw how to figure out any day of the week for 2017, just by adding two numbers. Fast, powerful, and (for the nerdishly inclined) very cool.

But 2017 will pass, and sooner or later someone will want to know the day they were born, or something else non-2017ish – then what?

The reason I started with 2017 is that it is a gradual introduction into the full calculation, which can have as many as six steps, versus the two needed for this year:

  1. Add a century year offset value.
  2. Add the non-century years (65 for 1965, 12 for 2012, etc.)
  3. Add the leap years (non-century years divided by 4, ignoring the fractions.)
  4. Subtract 1 if the year is a leap year, AND the date to consider is in Jan. or Feb.
  5. Add the month number.
  6. Add the date number.

For simplicity, you’ll take this final number and subtract 7s from it, until you have a number from 0-6.

Let’s look at November 15, 2017 again, which we determined in Part 1 was a Wednesday:

  1. Add a century year offset value. For 2000-2099, the value is 0.
  2. Add the non-century years (17 for 2017.) So we are at 0+17=17.
  3. Add the leap years. 17/4=4.25, so we use only the 4. 0+17+4=21.
  4. Subtract 1 if the year is a leap year… Not a leap year, so: 0+17+4+0=21
  5. Add the month number: 2 for November, so 0+17+4+0+2=23.
  6. Add the date number, 15th, so 0+17+4+0+2+15=38.

Take 38, and reduce it by removing 7s: 38 is 35+3, or (5*7)+3, so we get rid of the 7s, and end up with 3, or Wednesday.

See why 2017 is so simple? The first four steps end up with 21, which is evenly divisible by 7. So we skip them, and just do the final 2, and then get rid of the 7s.

And if it is a date in the 2000s, and not a leap year, we still skip steps 1 and 4.

Well, then, what about a hard date? Say, a leap year last century, like January 29th, 1988?

  1. Add a century year offset value. For 1900-1999, the value is 1.
  2. Add the non-century years, so we are at 1+88=89.
  3. Add the leap years. 88/4=22, so we get 1+88+22=111.
  4. Subtract 1 if the year is a leap year, AND the date to consider is Jan. or Feb. So we get 1+88+22-1=110.
  5. Add the month number. 6 for January, so 1+88+22-1+6=116.
  6. Add the date number. 29th, so 1+88+22-1+6+29=145.

145 is 140+5, or (20*7)+5, so we get rid of the 7s, and end up with 5, or Friday.

Six steps, and you’ve got the day of the week for two centuries’ worth of dates!

(One caution – 1900 is a special case, and NOT a leap year, so January 1, 1900 is a Monday, not a Sunday – try it and see. But 2000 IS a leap year – that’s calendars for you!)

But even with six steps there is a fair amount to keep track of and do in the head. I tend to follow these steps like this, for example using July 12th, 1979:

  1. Add the leap years. The hardest part of the calculation is the divide by 4, so I do this first, by dividing by 2 twice and throwing away the fraction. So, 79/2 is 39.5 or 39, and 39/2 is 19.5 or 19. Another trick is I can throw away the sevens anytime to keep the total small, so 19-7-7=19-14=5.
  2. Add the non-century years, so add 79. From 79 I can immediately remove 77 (11*7) so I get 2, for a total of 5+2=7. Another 7! So I throw that away and get 0 so far (another way to look at it is 5+79=84, which is 12*7, so I end up with 0 this way as well…)
  3. Add a century year offset value. For 1900-1999, the value is 1. 0+1=1.
  4. Subtract 1 if the year is a leap year… Nope for 1979, so still 1+0=1. (Hint: If you had any fractions when doing the first step, it wasn’t a leap year.)
  5. Add the month number. 5 for July, so 1+5=6.
  6. Add the date number. 12th, so 6+12=18=14+4=7+7+4. Take away the 7s and the end result is 4, or Thursday.

Practice a bit, and you’ll see how easy it is to calculate the day of the week for any date. And even if you don’t use it often, you’ll find yourself paying attention to the day of the week more, and being able to answer questions like “what day was the 19th?”

And of course, with a teeny bit of effort, you’ll be able impress people by telling them the day of the week they were born and many other dates…

How To Name The Day of the Week for Any Date – FAST (Part 1)

What day of the week is March 1, 2017? November 15, 2017? August 22, 2017?

2017 is a very special year – it makes day of week calculations easy-peasy, and opens the door for doing it for any day – any year – or any century.

Tempted to try? Then just look at this list of 12 numbers:

6 2 2 5 0 3 5 1 4 6 2 4

Let’s put them in context:

6 January
2 February
2 March
5 April
0 May
3 June
5 July
1 August
4 September
6 October
2 November
4 December

How it works: Each number after January’s is the offset in the calendar for the next month, modulo 7 (or, wrapping around weekly, where 6 is Saturday, and 7 becomes 0, which is Sunday, then 1 for Monday, etc.) Take June (3) which is 30 days, or 7+7+7+7+2 – the 7s don’t count (Wednesday plus 7 days is still Wednesday – get it?) However the 2 does count, so the number for July is the 3 for June plus the extra 2 days, or 5. And as January shows, you wrap around from 6 to 0 – January has an extra 3 days, and 6+3=9, which you fix by subtracting 7, to get 2. Using this and the number 6, we can create this whole list ourselves, but it pays to memorize it. Note we also use the ‘normal’ February, which is 28 days, no no extra to add to March, so it remains 2 as well.

And 2017 is special because the year started at 0 (Sunday.) Put that together and we have very simple calculations by adding this ‘Month Number’ and the date of the month:

  • January 1, 2017? January is 6, plus 1 for the first is 7. subtract 7 (days always run from 0=Sunday to 6=Saturday) and we get 0, or Sunday.
  • March 1, 2017? March=2 + 1st=3, which is Wednesday.
  • November 15, 2017? November=2; 2+15=17; keep removing 7s until we get 3, which is Wednesday again.
  • August 22, 2017? August=1; 1+22=23, which is 7+7+7+2; throw away the 7s, and we get 2, or Tuesday.

What makes the calculation so simple is that 2017 starts on a Sunday, so very little math is needed – add the Month number and Month’s date, and throw out the sevens to get a day. It also works for any non-leap year year that starts on a Sunday, such as 2023 and 2034.

Of course, once you’ve had some practice, you probably don’t want a trick you get to use only one or twice a decade. So how to expand on this to get the day of the week for any date? Tune in to tommorrow’s part 2 for more…

The Audrey Braille Display, and a Plan to Build It Faster

(PLEASE NOTE – The Patreon page mentioned here is deactivated until further notice)

If you could help someone, what would you do for them?

Almost everyone would talk about helping someone cross the street, or giving a cheery hello to brighten their day, or donating to a worthy cause.

I feel similarly. It’s why I started the Audrey Braille Machine in 2011. A device to turn digital text into Braille patterns that a blind person could feel with their fingers.

Being a programmer for most of my life, the software was never an issue. But hardware was. So I taught myself the Arduino open source hardware and electronics so I could ‘drive’ the project (you can read my articles here.) And I used that knowledge to build smaller projects to help the Blind (examples here, here and here.) Eventually, I learned enough to teach an Arduino course at the local Makerspace.

But despite all that, the Braille Display project moved along slowly. In one way, it was a blessing; I was able to evaluate different designs, so I didn’t go down a blind alley too soon, and eventually created my best design yet, a small embossed wheel (details here.) On the other hand, the blind were not benefiting from an unfinished project…

Then I came across Patreon.com and had an idea. Briefly, the site allows people to donate to a cause or project. Patrons pay, and you give them something for their contribution, usually monthly. It’s a great way to test an idea, to see if you can raise enough interest or not.

But unlike most of them, I’m not a painter or designer or writer giving people my creative work. So at first I wasn’t sure of the fit.

Then I realized – what I REALLY wanted were patrons to encourage me. Simply put, their donation confirms that someone else thinks this is a good idea. And thanking them for their support and confidence would in turn inspire me to work faster on the project.

So I did it – I opened a Patreon offer (currently inactive.) For $5 a month, you tell me if you think the Braille display will make the world a better place. In turn, I will give you progress reports and more each week, and anything else I can think of to keep you in the loop.

I also plan to make everything Open Source, so others can riff off the ideas and implement better and better versions – and ultimately, with the blind benefiting. If you’ve heard about Linux, then you know the power of many people focusing on an Open idea…

My goal is to get at least 100 people involved – and give back 50 hours of work per month on this project. While that ends up being less than a minimum wage (actually, far less, since I’ll likely spend most of it on equipment and parts), it was never about the money.

I want to help. And I think you do too, or you likely wouldn’t have gotten this far in my post. Make no mistake; your support will be fundamental in making this project happen, so join me on Patreon, and let’s make a difference.

(PLEASE NOTE – The Patreon page mentioned here is deactivated until further notice)

The Audrey Braille Display, 2017

It’s 2017 – so how is the Braille Display going?

In a nutshell, alive and well – but moving very slowly along.

The design has evolved from the original rack and pinion to a wheel design. The wheel combines all 64 possible braille cells patterns into a 64-row wheel about 2 inches across, which means a very compact design is possible. Each cell is driven by a single motor that turns in one direction, making the part count low (for example, no H-bridge for motor control – just a transistor.) Since a regular motor can be much cheaper than a stepper, the result is lower cost – in fact, I’ve estimated I can build it for under $200 for a 20-character device.

In practice, an Arduino will communicate with the computer via USB, and send signals to each motor for positioning. By turning the wheels precisely, any given pattern can be placed under a sensor window, to be touched by the finger.

And three wheels per cell? Packing things together makes for a very tight design. If I had a machine shop that could adhere to ultra precise tolerances for parts, I could possibly fit every cell into a single wheel/gear. But I’m working with a 3D printer, requiring quite a bit more ‘slop’ in the design. Using three gears per cell allows the motors, sensors, and braille wheel to fit together in a design and not get in the way of each adjacent cell.

In any case, the videos below give more details and some insight as to the current state in early 2017 – please excuse the quality.

Right now, the main problem is positioning. Turning the wheel means setting the wheel to one of 64 possible positions, and within 1/2 millimeter or so of each position, for practical use.

So while I am still moving along with it, and ironing out kinks, I thought it was worthwhile at this time to get a progress report out on the Internet.

VIDEO 1: Audrey Braille Display – Cell Design

A first prototype of a single Braille display cell using the three gears, one for driving, one for the positioning sensor, and the third for the Braille pattern. Using three wheels allows the cells to be positioned closer together, since the drive motor would get in the way of adjacent cells if it was in the same position for each cell; instead, it can be alternately positioned high and low and still drive the cell.

VIDEO 2: Audrey Braille Display – First Test of Character Positioning

Testing the character positioning accuracy by sending the same character 10 times to the cell, and checking if the rest position varies each time. As a simple visual test, I’m using the single mark on the sensor wheel that marks a full turn of the wheel – it should appear in the same spot for all ten character displays, and if not, means the positioning needs more work (spoiler alert: the positioning needs more work.) However, for a first try with quick and dirty Arduino code I’m happy with the results…


It’s Getting Chilly Out There – So Get Chili In Here…

But first, a Haiku:

Foodie conundrum –
Heats us in wintertime, yet
We call it ‘chili’

As the Missus finishes up her second novel (#2 in the Plant Lady Mystery series – quick plug here) I wanted to do something to free up her time. So I looked around for meals that I could do simply and easily (key for me).

The result is what I’m going to call Dave’s Drop Dead Default Chili:

  1. Put equal sized cans of beans and tomatoes in a pot
  2. Add chili powder to taste – level teaspoon per pair of cans is a good start
  3. Bring heat up slowly to a bubbling boil, then turn down and let simmer

I told you it was simple. Want a lot? Combine four cans of tomatoes and four cans of beans (I prefer kidney beans for the first can, but cannellini, pinto, and black beans have all worked so far.) Want a little? one can of each. Thick? Use tomato paste. Thin? Use whole or diced tomatoes.

This is a basic, simple to make chili – and once you have this down pat, there are many ways to enhance it:

  • I’m a vegetarian, but it shouldn’t be too hard to add meat – fry up some ground hamburger and add it, or cook up and slice in hot dogs (or just let them cook in the chili.)
  • I like to add oil to the pot and put in some diced onions first – cook them on medium heat until they just turn translucent, so that they are still a bit crunchy. I use one of those chopper gadgets to make the onion bits very small, cook some, and let the rest be a garnish (this was Gwen’s suggestion.)
  • My current variation is to add a lot of heat. I take a large jar of banana peppers in water, and split it into two portions for two batches, each with half the water and half the peppers. Then I add the 1/2 jar of ‘hot’ water along with the peppers diced into small pieces.
  • You can also add rice. A small amount of white rice added near the end cooks up nicely; you serve when the rice is soft. A big advantage is that rice+beans ends up providing all the protein building blocks your body needs. Called a Complete Protein, it’s useful for vegetarians who look for non-meat sources for protein.
  • Another alternative for rice: As I found out in one batch, rice needs 2X the water by volume to cook. So add too much to the chili and you end up with a a sludge or stew. Not to worry though, since that makes a great filling for tacos – just add a dollop of sour cream each (organic of course). Alternately, you can cook the rice separately, and pour chili over it for that complete protein benefit.
  • You can go all out – I actually got the original recipe from Joe Cross’s site, where the beans are soaked overnight along with many, many steps and ingredients. I really liked the recipe, but the fact is, if it requires too many steps, it won’t get done, so better canned beans and a hearty meal or two a week, than soaking beans and making a fancy dinner only once a month.

So far, I can make big batches that last three days and allow freezing of the extra. For that, it’s two big cans (28oz) of Tomato paste and whole tomatoes, along with 4-5 regular sized (14oz) cans of each type of bean. A 1/2 jar of pickled banana peppers gives it the perfect heat.

Give it a try – something this easy makes for a great last minute meal, and tastes far better than the simplistic recipe suggests. And it gives your other half time to work on her novel…

The Most Dangerous Bread Recipe on Earth…

Men CAN bake. And the dangerous part is that if you start with this recipe your wife (and your waistline) will want more…

I first saw this recipe on a cooking show with Michael Smith – check here for the original and other variations. However, it is dead simple:

“City Bread”
5 cups of flour
1/2 heaping teaspoon of active dry yeast
2 teaspoons of salt
2 1/2 cups of warm water

Mix dry ingredients together thoroughly, then add water and stir until dough forms. Cover with plastic and let sit in a warm place overnight (8-10 hours). Knock the dough down and move to the (large/2 liter) bread pan. Let it double in size (2-3hrs) and then bake in preheated oven (425F/220C) for 45 minutes.

It is that simple. Some things to watch out for:

  • The flour is always sticky – when making it, keep your hands and bowls as greased as you can or floured.
  • Likewise, put oiled baker’s paper in each bread pan before transferring – makes for much easier cleanup.
  • If you time it right, you can make bread for several days, and have the first one ready in time for supper. Michael says he does it daily timed with supper, but I’m lazy and prefer doing several at once.

Four ingredients – and two of them are water and salt. It’s also inexpensive, since you use hardly any active yeast (unlike with a breadmaker, which goes through yeast like crazy.) That’s because you give the bread time to ferment/create more of its own yeast, by letting it go overnight.

And the result: Best bread I’ve tasted. Nutty and slightly brown throughout (using white flour no less). I eventually had to stop making it, since it was too easy to sit with a hot loaf and some butter and make it disappear ASAP.

But someday, when I am thinner, the most dangerous bread recipe will be cooked yet again in this home…

A REAL VB .net Equivalent To The C/C++ atoi()

For awhile now I’ve used the following code that I got from here to translate text into integers without too much fuss in Visual BASIC:

Public Function ToInteger(ByVal s As String) As Integer
    Dim i as Integer
    Integer.TryParse(s, i)
    Return i
End Function

It’s pretty straightforward: The TryParse() tests the string and places the numeric value into ‘i’ if valid, else 0. It doesn’t exception like CInt() would, which makes a difference when processing large amounts of data – exceptions take a fair bit of time to process within try/catch blocks (and one would argue even more outside!)

There’s a catch, though: TryParse() is not exactly like C’s atoi(), and the difference is quite irritating since I come from that background. Specifically, if there is any trailing non-numeric data in the string, it fails. And since I like to use this to convert combo or listbox entries, you can imagine how annoying it is to fail on a string like “212 (Temperature of boiling water”)” or similar: Whereas our ToInteger() function would return 0, atoi() would return 212, stopping after the number.

So, time to get a bit more complicated – meet ToInteger() Mark II. It’s in VB, but it shouldn’t be too hard to convert to C#:

 Public Function ToInteger(ByVal s As String, Optional ByVal result As Integer = 0) As Integer
        Dim i As Integer = 0
        Dim valid As Boolean = False
        Const Asc_0 As Integer = Asc("0"c)
        For Each c As Char In s.TrimStart
            If (c < "0"c OrElse c > "9"c) Then
                Exit For
            End If
            valid = True
            i = i * 10 + (Asc(c) - Asc_0)
        Next
        If (valid) Then
            Return i
        End If
        Return result
    End Function

This version takes in the string, processing digits until they end, then stops with that value, so text following it is ignored. As well, you can (optionally) specify a default value other than 0, useful if you need to know if the input is invalid (no digits input at the string’s start). And despite being longer, it actually timed 25% FASTER than the previous routine – go figure.

Enjoy!

Have You Mastered Doing What You Love? (An Accidental Part 2)

As I mentioned in my last post of the same name, I was narrowing my focus on tasks to get some more programming done, which is arguably my ‘passion.’ ‘Nuff said.

Not so fast. This month I read a book on NOT following your passion, which made some interesting arguments:

  • Following your passion is awkward when you aren’t sure what you want to do yet (think of choosing a major in college).
  • People change, and what your passion is right now may not be in the future.
  • Passion is only one part of the whole job, with a lot of room for non-passion (my word) in the day to day grind.
  • Passion without experience is likely doomed to failure.

The arguments make sense, but sure put a damper on what we’ve told about following our ‘bliss!’

However, all is not lost. He contrasts passion with work ‘capital’ – for example, years spent learning a craft. And not just learning, but getting good – extremely good – at it. This capital means you have options for the future, and can more easily aim for your dream job.

Serendipitously, I wrote this last month with the title ‘Have You Mastered Doing What You Love?’ because I firmly believe doing something is one thing, but doing it well is quite another.

However, I likewise can’t take credit for this observation, since I learned it from a much older source:

“Do you see any truly competent workers? They will serve kings rather than working for ordinary people.”
-Proverbs 22:29, New Living Translation of the Bible

So we’ve known that quality trumps passion for a long, long time. But which should come first?

I (im)modestly think the issue is one of what ‘bliss’ really is, and that it is really a hint of what to do, rather than a full-fledged job description.

For example, say you love working with horses. Sounds good. But which aspect? Vet, trainer, owner, racer? All of these people work with horses, and all jobs might have pleasant aspects. So does that mean one of them is the winner while the others aren’t?

The book uses the example of Steve Jobs, who was quoted as following his passion. However, as was also pointed out, Jobs was interested in becoming a guru around the time he started selling Apple computers. It was a matter of timing and success that he went into running Apple versus working at an Ashram. So how can only one be the ‘one’ passion?

But what if both jobs were part of the same passion? If we limit passion to running a computer company, only one works, but if we talk of a strong passion for molding people’s lives and influencing others, then both jobs are viable, including many more jobs besides.

To give another example, an older post of mine recommended testing to decide what your strengths are. In my case, one top item was focus, or staying with a problem until solved. Not a surprise, as I enjoy programming. But problem solving is satisfying in many areas. I enjoy inventing (solving problems with devices), and also writing, where I enjoy wrapping my head around a new topic (‘solving’ it for myself) and then explaining it to others. My ‘bliss’ is tied up in those aspects of all three of these things, not each job individually. If I had to choose just one, I’d likely refuse. The common thread, as the testing showed, is that I enjoy the focus involved in each.

So to apply it forward. If I looked for a job, the one that allowed me to focus for long periods on problems would be more satisfying that one that (for example) allowed me to interact with lots of people. So I can still try different jobs, just keep an eye open for how my strengths work best for me (and by extension, for the business that hires me, which makes me more valuable.)

The conclusion: I still think we can follow our passion. The key however is to understand that passion is not a ‘carved in stone’ absolute, but more an inclination of the direction you’d like to go in.

After all, you can have a sweet tooth, and there is a lot of food that appeals to you; but decide you’re eating just cheesecake forever, and you’ll soon wonder if you ever had a sweet tooth at all!

So figure out what kind of ‘tastes’ YOU have, and pursue them – life’s too short for not following your passion – some book authors notwithstanding.