Quantum Mechanic

Content from 2016-05

Finally fixed my phone

posted on 2016-05-15 14:32:00

I like to tinker with things, I own. An important part of deciding to buy any given device is that I can tinker with it, take it apart, install whatever hobby OS on it I like, &c. I'v generally been delighted by my Nexus 4 phone, which I've had for perhaps two and a half years and is my favorite smartphone so far!

Recently, though, Google stopped providing android updates for it (well, I think they'll still security patch Lollipop for a while) when Marshmallow, the sixth food-version, came out. I always like to poke at the new things in life, so I started looking around at my options and saw that there was a Cyanogenmod 13 image for my phone. CM goes by their own numbering system, and 13 corresponds to 6 in the official android versions, which is the latest. I had played with Cyanogenmod a few times over the last few years and so I felt pretty comfortable trusting them with my phone.

On top of trying the new version of android, which seems fine, but hasn't really blown me away with anything new, I also tried unlocking my phone's LTE modem. It seems the n4 shipped with an LTE modem which isn't turned on by default because maybe Google never got it properly tested. Some people got it turned on, though, so it's possible to upgrade your data connection considerably! It was like getting a new phone!

Unfortunately, I also had to seek out and install some Google apps. I'm finding Google increasingly irritating, recently, both in their apps and that they called me for an interview, screwed up the scheduling, then the programming language they were interviewing me about, then let me try again in the right language, and finished up by never responding. Mostly, I would seriously suggest the F-Driod repository of FOSS apps, but I need to install the Google Play Store for my banking app, many things I need for work, and I also make heavy use of the Maps app. So, I bit the bullet and installed Google Play using the Open Gapps project.

For a couple weeks, I tolerated the nightmare of continual modal popups from Google Play Services that informed me that it had stopped. Over and over again, it stopped. In the middle of typing words, it stopped and interrupted me. While trying to get directions, it stopped and never figured out where I was. While trying to find emails, it stopped and got confused. It was really annoying, but it tended to happen in terrible, agonizing bursts, so I could still function. I was busy adopting a dog and being an adult human, so I tolerated it.

BUT THAT ENDED TODAY

I finally sat down and got it fixed.

I tried a billion forum posts that suggested combinations of wiping partitions and dances around blood-spattered stone circles, but that wasn't really useful. I know that most of those things are essentially Skinner boxes, and so I try to avoid them, but desperation makes fools of us all.

I had avoided hitting the 'Report' button on the error dialog, because, on the stock android version, this brings up a wall of legal text about how Google is going to pack up as much data as it wants and ship it off to their servers when you submit the bug report (disclaimer: I never read that and have no idea what it really says, I'm just tired of accepting legal agreements). On cyanogenmod, though, the data will be shipped off to a bunch of friendly hackers (in the best sense of the word) who I don't know, but trust to care more about my privacy than Google, for some reason. I didn't submit the report, but being made by hacker-friendly people, the CM report dialog shows the Java backtrace of the problem. This was the most helpful information I'd gotten so far, and it informed me that the problem was
com.google.android.gms missing android.permission.ACCESS_FINE_LOCATION
But I had given Google Play services that permission!

Eventually, I found an issue that seemed to address it on the Open GApps issue tracker, that contained these commands:

pm grant com.google.android.gms android.permission.ACCESS_FINE_LOCATION
pm grant com.google.android.gms android.permission.ACCESS_COARSE_LOCATION

and that was it. No problems, yet.

I hope that this saves someone all the hours it cost me!

Clack Static Asset Middleware

posted on 2016-05-12 02:01:00

As part of my glacial march to get Knttl running the way I'd like, I wrote a middleware for the clack web framework to help me out!

When you're serving javascript and css files for a website, you want to inform the browser to keep a local copy as long as possible, because then it won't bother your webserver to download it again and the page will render faster for your users, too. There's a popular quote about programming

There are only two hard things in Computer Science: cache invalidation and naming things.
It seems this was said by a Phil Karlton.

So, like many things related to the it-was-never-meant-to-be-used-this-way world of web technology, there are some interesting best practices that evolved around this idea that, ideally, only one copy of a static file should ever need to be sent to a user, if their browser works well.

There are ways to tell a browser how long to hold onto a file before checking if there's a new version of it, but that only gets you so far. Presumably, your javascript is going to change, some day, and then you'll feel silly when all of your users are still running a three week old version of it that's still cached by their browsers.

The next bit is the hack that makes it all shine.

"Why not just change the filename when the file's contents change?" asked some bright engineer, somewhere. So, we do. We just attach a hash of the file to the filename and serve that. When the file changes, the filename we show the web browser changes, and we can tell the browser to just cache the file forever, or as close to forever as we can!

It's kind of a pain to generate a copy of all of your files with hashes attached, so what clack-static-asset-middleware does is store calculate some hashes of your files and just pretends those files exist and serves up whatever you tell it about.

I also wrote some helpers you can load to use this stuff easily with Djula, like so:

<a href="/" class="logo u-pull-left" title="Home">
<img src="{% asset-path "small-logo.png" %}"
width="54" height="60"
alt="Knttl" />
</a>
So, to summarize:
  1. Have style.css
  2. Template asks for hashed filename, gets something like style_2867f3f83a6a91ad4a19a6cd45536152.css
  3. Browser asks for style_2867f3f83a6a91ad4a19a6cd45536152.css
  4. Server says "Aha! I have fooled you! Here's style.css! Keep it as long as you like!"
  5. Browser says "Golly gee! I will, mister Server! I'll never ask for style_2867f3f83a6a91ad4a19a6cd45536152.css again!"
  6. Hooray!
So check out clack-static-asset-middleware, which will hopefully be in quicklisp soon!

We Can Has Doggle

posted on 2016-05-10 01:41:00

I have been a bad blogger lately, as always, but there's something worth throwing a few words onto the internet about.

We've adopted a dog! A little over a week ago, we took a trip out to the North Shore Animal League America and adopted a very mixed breed dog who we've named Wedge after the legendary starfighter pilot from the Battle of Yavin (and the X-Wing series of books that I loved in my teens). It only took us eight hours after the staff lost our application for a while and left us sitting in the dog meeting area hungry and uncertain.

IMG_20160501_015518.jpg

Wedge came from a pupply mill, which means he was probably brought up in a situation where he was kept in a cage all the time and probably wasn't treated like he was a sentient being all that often. If you look around online, you'll find that adopting a mill dog can mean signing yourself up for a fair bit of doggy rehab (figuratively speaking).

For the first week we had him, Wedge was afraid of just about anything at just about any time. You couldn't even give him a treat, half the time! He would walk up to take it and then it was as if the realization of how close he'd come to me hit him about two feet out from my hand. Then he'd turn so fast that his butt and head were going different directions for a moment. It was cute and sad all at the same time!

I'd never really expected to get a dog - the one we had growing up didn't like to do much but steal food and be ornery - so I wasn't really looking for another dog experience. After our trip to Portland, OR, though (which I'm now realizing I didn't write about here! More soon!), we were left with feelings about things that were missing from our lives. Things like really good coffee, vegan donuts, and maybe having a cute dog to stop us from being all depressive a lot of the time (therapist recommended!). Naturally we picked a dog with it's own emotional problem.

Now, Wedge is calming down and doesn't run away from me when I move around the rooms of our tiny apartment anymore. I haven't really had to train a dog before, though I grew up with one, so this is a bit of a challenge. Hopefully, he'll come out of his shell in the next few months and we can take him camping over the summer.