Thursday, November 16, 2017

Weekly Discoveries: Dance Teams, Panda Suits and the Christ Stapleton Reactions

Skip reading this post, and just go watch to Edward Sharpe and the Magnetic Zeros' Man On Fire. The music is good, but when combined with the visuals, it's just awesome. Didn't that music video improve your day?

I've decided I'll listen to anything Dermot Kennedy or Dean Lewis are singing. I mean, that Dermot Kennedy song, An Evening I Will Not Forget, what is that? It's almost got sort of a rap, lyrical thing going on. Not expected, but really well done.

Kodaline's Ready to Change is almost more short film than music video. It may be a mere 4 minutes and 24 seconds long, but I still find myself rooting for the characters, hoping that they will connect and have the relationship that they so badly deserve.

Nothing says we have to be so serious all the time, right? I give you Galantis' Peanut Butter Jelly. 100 *million* YouTube views can't be wrong. Just click play and smile.

Back in September I marveled at Chris Stapleton's amazing singing ability. Needless to say, I'm not the only one who finds his skills impressive. Check out this reaction video where a couple of non-country fans hear Stapleton for the first time. Priceless.

View the last couple week's discoveries here and here:

Wednesday, November 15, 2017

Cold Day, Warm(er) Water and Dad make for Fishing Awesomeness

My parents are in town, so naturally I wanted to drag my Dad fishing. Being a fisherman, he's always up for standing in the freezing cold trying to catch fish. But he did warn me that the cold weather, and therefore cold water, would make for trickier conditions. To which I answered: what if I could get you access to 65°F water? With that, I had his attention.

The spot I had in mind was near the 4 Mile Run Treatment Plant, which has outlet that pumps 1,700 gallons of 65 degree water into 4 mile run every minute. My Dad could definitely see the fish being active in that area.

This morning at 7am, we parked 4 Mile Run and made our way to the steaming chute of water. This is clearly a common fishing area, as the grass around the area was trampled and there was plenty of debris along the bank. Though for today, we had the area all to ourselves.

My Dad went to work trying to catch fish. Nominally, I did the same. I also spent a good amount of time snapping pictures, looking for interesting rocks, and trying to figure out how to tie a Uni-knot (which my Dad would go on to effortlessly demonstrate). At one point, David gave me call. As I was explaining how there was clearly no fish to be had, my Dad naturally caught a fish.

OK, it was clearly time to focus. In a classic Dad move, it he updated the tackle on my pole to match what he caught his fish on and pointed me in the right direction. I made a few more casts. Nothing. He caught another fish. Then another. Finally, he just handed me his pole and took mine. I tried a few casts with his setup, again, nothing.

We switched back to my pole and then I had my first substantial hit. Fish on! I reeled my catch in:

Yeah, that would be a glove. We kept at it, and finally, success! A real fish:

After about an hour and half of fishing, we had to call it a day. Something about going to work or some such nonsense.

I've seen plenty of fishermen along 4 Mile Run, and now I can pile on and say that we've had success there, too. If you find yourself looking for warm water on a cold day, I've got your spot. Just make sure you bring along your Dad to have maximum success.

Monday, November 13, 2017

Hop to it - Counting Jumps using a cell phone accelerometer

Last week I was harshly schooled in the difference between theoretical physics and the reality of cell phone hardware. While it may be true that you can calculate distance from acceleration, the hardware on the LG G6 isn't precise enough to do so. But I remain undeterred!

I return instead, to my original and simpler problem: can I use my phone's sensors to determine many jumps have I done in a jump rope session? The accelerometer is clearly one way to approximate this. Just check out the graph below. It shows three bursts of me jumping, with each set of jumps followed by a pause:

The simplest strategy here is to count the peaks of the graph. Swapping out the code to calculate distance with code to do this counting was simple enough. All the code can be found here, but the relevant lines as follows:

;; Counting the peaks in a given accelerometer stream.  This should
;; give us a rough approximation of jumps
(define (count-peaks accum data)
  (let ((lower 0)
 (upper 10)
 (verbose? #t)
 (a-now (+ (data 1) (data 2) (data 3)))
 (rising? (accum 0))
 (num-peaks (accum 1)))
    (cond ((and rising? (>= a-now upper))
    (if verbose?
        (show "peak discovered: " a-now))
    (list #f (+ 1 num-peaks)))
   ((and (not rising?) (<= a-now lower))
    (list #t num-peaks))
    (list rising? num-peaks)))))

For now, a peak is defined as having total acceleration over 10m/s2. I arrived at this number the way all important mathematical constants are: I stood in my living room and jumped up and down. Set the peak height too low, and simple movements are marked as jump. Set it too high, and not all the jumps are counted.

A smarter approach would be to make this number adaptive, making it somehow dependent on the data set itself. But for now, a constant of 10 seems to work OK.

With this code change, I was able to record a 10 jump data file and run it through tinyscheme:

While this was functional, I was curious if I could streamline running this script. Switching to Termux, then entering the right filename in emacs, and then evaluating the code in the *scheme* buffer was all a bit much.

Fortunately, Termux has the answer: Termux:Task. This is an add on for Tasker that allows you to kick off shell scripts under Termux. The first order of business was to wrap up the scheme code as a shell script. That wasn't hard:



usage () {
    echo "Usage: `basename $0` /path/to/data.csv"

if [ -f "$1" ] ; then
    exec tinyscheme -c "(define *src-dir* \"$SRC_DIR\") (load \"$MAIN_SCM\") (show (count-jumps \"$1\"))"

tinyscheme can be invoked with -c which allows for running arbitrary scheme expressions. I'm using this to initialize and run parameterized code.

From there, I soft linked this script under $HOME/.termux/tasker. This allowed the script to be visible inside of Tasker:

Note the use of %asfile1. This variable is set by AutoShare, a Tasker plugin that lets you kick off actions based on the system sharing menu.

With the Tasker code in place, I can record data in the Physics Toolbox Sensor Suite app, then share that data with the Count Jumps AutoShare command. This kicks off the count_jumps shell script, which invokes tinyscheme and runs my code above. Simple, right? It may be a virtual Rube Goldberg, but it does work, and successfully demonstrates how you can get from an Android App to scheme code with very little effort.

As a final test, here's me knocking out 30 test jumps:

And there you have it, 31 jumps. As approximations go, I'll take it.

Thursday, November 09, 2017

Calculating Distance from a Cell Phone's Accelerometer - A failed, but fun attempt

Our gym had a nifty Bluetooth enabled jump rope that would report how many jumps you made in a session. Then the rope broke. This left me thinking: could I approximate the same thing by using the sensors on my phone?

Poking around, I learned that there's a class of app that gives you access to these sensors. In that genre, Physics Toolbox Suite appears to be a top pick. Launching the app gives me access to all sorts of data, from the gyroscope, to barometric pressure, to the GPS. It also gives me a way to record the data for a period of time, generating a simple CSV file. And if all that weren't enough, it's also ad free. To show my support, I just purchased the Pro version, even though the standard version does everything I need.

What caught my eye in the app was the Linear Accelerometer screen:

I've long since forgotten the majority of high school physics lessons, but I do know this: units matter. As the app reminded me (or perhaps taught me), acceleration is measured in meters per second, squared. What jumped out at me was the presence of meters, or distance. I now had my goal: rather than count the number of jumps in a jump-rope session, wouldn't it be far cooler to count distance? That is, how many vertical meters did I manage to conquer while jumping rope. I wasn't sure how I was going to tease this data out of the accelerometer, but I knew I was going to try.

The first stop in my journey was to head over to YouTube and learn how acceleration and distance are 'connected.' I found this Khan Academy video gave me enough background on distance, velocity and acceleration to let me derive a solution. The Physics Toolbox Suite app would give me a CSV file that provide an acceleration value every 100th of a second. Thinking through these concepts, I realized that I could at each moment derive speed and then distance, by looking at the change in time and acceleration. And because I knew that I was starting by standing still (that is, my velocity was zero), the whole system could be initialized and in theory, a final answer derived. I was quite proud of myself. Shira, for her part, rattled off the exact formula and explained to me that this super basic physics. Apparently, I could have skipped the Kahn Accademy, and just talked to her.

Now that I had a method for calculating distance via the accelerometer, I needed to try it in a controlled environment. I laid down a tape measure, and noted 4 meters. I then walked these 4 meters while capturing the accelerometer data via the Physics Toolbox app. With a few test runs captured, it was time to do the fun part: program the above solution.

Because the data was on my phone, I thought it appropriate to code the solution on my phone. I busted out tinyscheme, emacs and termux. Tinyscheme is a delightful tool to work with because it's so lean. This can also be a source of frustration, as to implement the above solution I needed a way of reading form a CSV file, and I'd rather not have to implement the string and file handling. Fortunately, I was able to borrow some code from the Programming Praxis Standard Prelude (thanks!), which meant that I didn't have to implement string-split or read-line.

The following function does the heavy lift for reading and parsing the CSV file:

;; Call handler on each row in the file.
;; Assume the first row is a header and the
;; following rows are all numeric data
(define (with-data file handler init)
  (define (wrap data)
    (lambda (index)
      (case index
 ((all) data)
 (else  (list-ref data index)))))
  (call-with-input-file file
    (lambda (port)
      (let ((header-row (read-line port)))
 (let loop ((line (read-line port))
     (accum (wrap init)))
   (cond ((eof-object? line) (accum 'all))
   (loop (read-line port)
         (wrap (handler
         (wrap (map string->number
      (string-split #\, line)))))))))))))

Ah, it's such a join programming this sort of thing in Scheme. It's like programming with Play-doh: you can invent new constructs with so little effort.

With the file parsing out of the way, it was time to write the actual code to calculate distance:

;; Use Physics 101 to calculate distance
;; based on the current acceleration, time
;; and velocity
(define (calculate-distance accum data)
  (let* ((t-now (data 0))
  (a-now (+
   (data 1)  ; ax 
   (data 2)  ; ay
   (data 3)  ; az
  (t-prev (accum 0))
  (v-prev (accum 1))
  (d-prev (accum 2))
  (t (- t-now t-prev))
  (v-now (+ v-prev (* a-now t)))
  (d-now (+ d-prev (* v-now t))))
    (list t-now v-now d-now)))

There's nothing particular sexy here. I'm taking in the time and acceleration data (via data) and using my accumulated values to calculate the current velocity and distance.

It was now time for the moment of truth. I ran the code against a sample data:

And, it was a bust. My code tells me that I covered 2.54 meters instead of the 4 meters I knew I covered.

I've been through the code a number of times, and I think the algorithm is fine. My guess is that I'm expecting too much accuracy out of my phone's sensor. Though, maybe my algorithm is fine and I just made a boneheaded mistake. You can see the full source code of the project here, and the data file is here.

Still, this exercise has been valuable. I learned about the Physics Toolbox app, which is definitely a keeper. I once again saw the amazing power of Termux, emacs, tinyscheme and how effortlessly they all come together on my cell phone. And I even learned some physics along the way.

While I think my goal of measuring how 'far' I jumped may not work. I'm still not convinced I can't use the sensors on my phone to at least count jumps. The data is there, the function to process the data file is ready, I just need to plug in right algorithm to make this all make sense.

Do you see where my assumptions on the accelerometer all fell apart? Please explain the comments!

Tuesday, November 07, 2017

Action, In-Action and Why I'm always yelling at my TV

[I wrote this post last week and saved it as a draft. Over the weekend, we had yet another mass shooting, and I think the message applies now more than ever]

Between the terror attack in New York, and the mass shooting in Las Vegas, it's pretty clear how each side reacts to these events.

Consider a mass shooting. The left is dumbfounded: how can you possibly not take action? The right offers sympathy and reflects on the nature of living in a free society where bad things happen.

The left is even more dumbfounded. DO SOMETHING. Ban assault weapons. Make owning more than two guns illegal. Heck, just get rid of all guns; I'll turn in my dad's old hunting rifle first.

The right warns that the gun control initiatives the left is suggesting range between ineffective and will make the problem far worse.

The left finds this ludicrous. What harm could come from taking a few guns off the street? To which the right replies, are you kidding me? A gun saved my girlfriend's life. Guns are an important part of our history and the fabric of the United States.

Now consider a terrorist attack. The right is dumbfounded. how can you possibly not take action? The left offers sympathy and reflects on the nature of living in a free society where bad things happen.

The right is even more dumbfounded. DO SOMETHING. End the Diversity Visa Program. Build a wall on our Southern border. Heck, pause all immigration; I'll be the one to tell my dad that his brother-in-law isn't going to be allowed in to the United States.

The left warns that the immigration initiatives the right is suggesting range between ineffective and will make the problem far worse.

The right finds this ludicrous. What harm could possibly come from keeping a few immigrants out of the country? To which the left left replies, are you kidding me? My girlfriend is an immigrant, and her work on the opioid epidemic has saved countless lives. Immigration is an important part of our history and the fabric of the United States.

In short, one side wants action, even if it's imperfect. The other side is sure the imperfect action will do far more harm than good.

Luckily, I know the answer: it's smart, incremental, progress. Look at the scourge of Drunk Driving.

When a family member loses a child to a drunk driver, we don't approach them and say: you've got our thoughts and prayers, but you know, that's just a side effect of living in a free and open society. Alternatively, we don't call for an end to drinking or driving.

Instead, we attack the problem at all angles: legally, technologically and socially. We give stronger jail sentences to drunk drivers and set up checkpoints. We develop breathalyzers in keychain form, or build them into cars. We inject our TV shows, schools and billboards with a clear message that drunk driving is unacceptable. Are there individuals who have been caught up on these regulations and been impacted unfairly by them? Probably. But, we've managed to save significant numbers of lives and made our society better off for it.

When bad things happen, regardless of where you sit on the political spectrum, we should demand smart, measured, action. We should demand solutions from experts who have studied the problem, and we should thoroughly understand the limitations of these solutions. Terrorism. Mass shootings. You name it. We can and should strive to always do better.

Monday, November 06, 2017

RipstopByTheRoll's Belt Kit - A Mostly Great First Sewing Adventure

My parents are in town, which means it's the perfect time to do a project with Mom! Before she arrived, I purchased the Hip Belt Pouch Kit from, a premier supplier of MYOG fabrics and such.

The kit consists of a single sheet of pre-cut fabric, a zipper, some elastic for the belt straps and some zipper pull material. As for instructions, you're given a PDF as well as a reference to a video of a project with similar construction.

After about 3 hours of measuring, re-measuring, zipping, re-zipping and generally cursing out the instructions, we finally had ourselves a finished bag:

I'm impressed with the materials and the finished project. I'm psyched that the instructions are given in such a way that you can scale the bag up and down as you wish.

I'm less than impressed with the instructions provided by Ripstop By The Roll. For one thing, step 6 seems totally out of place. For another, my Mom would have vastly preferred more standardized language when describing how to attach the zipper (wrong-side-to-wrong-side - that sort of thing).

For what the kit costs, a full video tutorial would be appropriate. My guess is that the team at Ripstop By The Roll is just too experienced and can't appreciate what it's like to try to tackle this project as a first sewing adventure. If they are going to sell these kits for the price that they do, they would be well served to bring in a total novice and watch him/her create the bag with their instructions.

Ultimately, the project is a solid one. It's functional, looks polished, and requires a nice balance of skills (including properly marking up fabric and installing a zipper). Now that we've made one bag, the plan is to make another to fully cement the experience.

Hurray for Mom's who love to do projects!

Friday, November 03, 2017

youtube_tools v2.0: Now with Playlist Management Support

Last month I finally got frustrated enough with YouTube's subscription management tools that I took matters into my own hands and wrote a command line tool to take over the job. Earlier this week I set my sights on a similar problem: playlist management.

I wanted a quick way to rename, delete and extract a YouTube playlist data. Extending my original youtube_tools wasn't that hard. And while I was at it, I added full support for paging.

Here's a few examples of the tool in action. Like most command line tools, uses are limited only by your imagination.

# Get a few playlists to work with
$ youtube_tools -a playlists | tail -5
PL755C43F40CCFC4A3:Songs To Make Shira Smile
PL1ED10A844DF6863C:Rock Music that Rocks
PL629D105C873357DE:Sweet Country Music
PL933A9F07113418D8:Funky Music

# Rename one
$ youtube_tools -a playlist-rename \
   -i PL629D105C873357DE -n "Totally Sweet Country Music"
PL629D105C873357DE:Totally Sweet Country Music

# See how many entries are in a playlist
$ youtube_tools -a playlist -i PL629D105C873357DE | wc -l

# Any by Brooks & Dunn?
youtube_tools -a playlist -i PL629D105C873357DE | grep Brooks
UEw2MjlEMTA1Qzg3MzM1N0RFLjFEMzAyRkUyQjlEQzA3ODI=:nopBvlKfYgY:Brooks And Dunn Neon Moon
UEw2MjlEMTA1Qzg3MzM1N0RFLjFFNjE4RTg3MjUyNTNGOUE=:6gS6NucKt20:Brooks and Dunn - Play Something Country [ New Video + Lyrics + Tab + Download ]

# Generate a list of URLs to watch these videos
$ youtube_tools -a playlist -i PL629D105C873357DE | grep Brooks | 
    cut -d ':' -f 2 |
    while read x ; do echo "$x";done

# Print out the thumbnail images for each these videos
$ youtube_tools -a playlist -i PL629D105C873357DE -v 
  | jq -r '.items[] |  .snippet.thumbnails.high.url + ":" + .snippet.title '|
  grep Brooks And Dunn Neon Moon and Dunn - Play Something Country [ New Video + Lyrics + Tab + Download ]

# Generate a trivial HTML page that contains all the videos
$echo "<html><body><h1>My Country Playlist</h1>"; 
 youtube_tools -a playlist -i PL629D105C873357DE | cut -d ':' -f 2 |
  while read x ; do
    echo "<iframe src='$x' width='560' height='300'></iframe>";
  echo "</body></html>"
<html><body><h1>My Country Playlist</h1>
<iframe src='' width='560' height='300'></iframe>
<iframe src='' width='560' height='300'></iframe>

The source code for youtube_tools is found here. Feel free to grab it and hack away.

Wednesday, November 01, 2017

The War on Writer's Block | Yet Another Approach to Tracking Blog Topics

Over the years, I've had various methods for tracking topics I'd like to write about on my blog. Each attempt had value, and ultimately shortcomings.

First, there was good old pen and paper. So gratifying, yet not especially convenient when many topics start online. Then I used browser bookmarks. These are great for web inspired ideas, but were tough to keep in sync. Then I used Google Bookmarks. this kept my ideas in sync, yet it was not effective at tracking non-web inspired ideas. Most recently I tracked ideas in Google Calendar. My plan was to schedule content for publication on a given day. This held promise, but ultimately I ended up ignoring the dates I set for myself and the whole process was just too clunky.

And so now I'm using yet another method for tracking ideas: A Google Spreadsheet. I'm not entirely sure why it took me this long to get here.

The spreadsheet has the following shape:

The sheet is simple: each potential topic gets a short summary and any number of associated resources, which would typically be links to more info. The links may be public content, like a blog entry, or private content like an album of photos. The Priority column allows me to tag certain topics as being higher priority, and then sort the sheet by that column, to have them percolate up to the top.

So far, the approach is working well. In various browsers, I've got a bookmark to this sheet, so adding to it while using a desktop computer is easy enough.

On my mobile device, things are even more automated, thanks to Tasker. To be more specific, thanks to the Tasker Spreadsheet Plugin and AutoShare. These Tasker plugins allowed me to trivially write the following Tasks:

Invoking the first task causes the phone to ask aloud: "What do you want to blog about?" A speech prompt them pops up asking me to recite my idea. The second task is meant to be invoked via AutoShare and means that any app on the phone that has a Share option can have the content routed to my Blog Ideas spreadsheet. This means that a web page or Reddit thread is only one click away from being added to the Blog Ideas spreadsheet.

If this approach works, I may continue to extend it by allowing files to be uploaded and referenced in the spreadsheet, too. That way, I could snap a photo of something and share that photo directly to the Blog Ideas spreadsheet. It's remarkable how effortlessly you can tie in your phone to a Google Spreadsheet by using Tasker and the necessary plugins.

All these approaches really point to one painful truth: coming up with content to write about isn't easy. Even on a blog like mine, where I give myself permission to write about literally anything. The right approach to tracking ideas helps, but ultimately, I stand in awe of writers. As Hemingway never said, There is nothing to writing. All you do is sit down at a typewriter and bleed.


Related Posts with Thumbnails