An easy fix for missing exercise minutes on Apple Watch

The Apple Watch is a nice little device, and it’s known to have motivated even lazy people into taking better care of themselves through the “gamification” of exercise.

However, it can happen that the Workout app doesn’t properly track exercise minutes (and, to a lesser extent, burned calories), and while Apple provides an official checklist for improving workout calibration, sometimes the issues persist.

TL;DR: If you wear the Watch low on your arm, move it higher. Seriously, that fixed it for me.

One very peculiar problem I had myself was that indoor walking workouts were not always being recorded properly: calories mostly worked, but I could walk half an hour and yet only a few minutes would be recorded as exercise, even if I walked fast. (Yes, I do walk around he house when it’s too cold to do so outside; a book or a friend on the phone are great reasons not to sit still!)

The weirdest thing was outdoor workouts generally worked much better, and rebooting the watch usually fixed the indoor workout problem… for a while anyway, which ruled out a hardware problem. Recalibrating fitness data didn’t seem to help in the long term either. Definitely annoying.

I knew that Apple Watch calculates exercise by applying some sort of “mathemagics” (did I actually write that?) to sensor data, especially the heart rate monitor and the accelerometers, so I started going through the heart rate graphs of my indoor walking workouts, and I stumbled upon stuff like this:

Notice how there are considerable gaps in the heart rate graph, especially considering the time scale at the bottom. That made me think: I do keep the Watch “not too tight, not too loose” as per instructions (and, honestly, as per comfort) so I knew that was not the issue. I also have zero tattoos, and while I do sport a little hair on my arms, I’m definitely not furry. Yet something was occasionally preventing the Watch from recording my rate, and I was determined to figure out what it was.

In the coming days I started paying attention at the monitor: at a glance it worked just fine, however a pattern started to emerge as I looked more closely. I noticed that whenever I brought the watch up and screen turned on — I have a Series 4 so the screen is not always off — the heart icon was not solid, but rather just showed an outline. Only after a second or so did it become solid and started pulsating, while the number itself started updating again. That was consistent with the lack of recording, but why? Was it some kind of bug in the software that put the heart rate monitor into sleep mode when the screen was off? Yet the green lights at the bottom worked just fine. That couldn’t be it.

Source: u/nilsej on Reddit.

At this point, I must confess, I was a little disheartened — pun fully intended. A few months ago I had had another issue with the heart rate monitor in my Watch, and in that case it was indeed a nasty software bug: for some reason, it just wouldn’t update the label in the Workout app. It was perfectly functional in the Heart Rate app, and the graphs were perfect. Just the Workout app, during the workout itself, wouldn’t let me know how my heart was doing. No amounts of reboots helped and I ultimately had to unpair the Watch and re-pair it again. Thankfully a restore from backup didn’t carry the bug over, so it was just a matter of wasting some time.

This was different, though. It worked fine, just not always. And looking at the screen would always fix it. I felt like Bilbo playing riddles with Sméagol, until it dawned on me: what if I’m wearing it wrong? Not in terms of how tight the strap was, rather where on my arm the watch was. So I did what a man of science would do: run an experiment.

I normally wear the Watch quite low on my wrist, quite close to the hand. It’s actually comfortable for me, but I thought it might indeed interfere with the readings, especially if my wrist is bent inwards. So I moved the Watch a little higher, away from the hand, and off I went. Lo and behold, it worked perfectly, and so far it has kept working perfectly for over a week: I just move it a little higher before starting a walk, and bring it back to where it’s more comfortable for everyday use later on. Also, it looks like this simple fix has made the Workout app more sensitive even for other kinds of workouts: now my full Outdoor Walk Workout is recorded (except when I stop because my dog goes forensics on some blades of grass), whereas before it would often only records the minutes I spent walking uphill, burning more energy. I had assumed it was due to the Watch “learning” what was more or less straining for me, but it turns out it just didn’t have a good view of my veins.

What is weird about this is that a reboot did seem to temporarily fix the problem. I wouldn’t be surprised if there was something in the software that sort of adapts to compensate for different readings over time, even though in my case it was actually causing problems. Still, moving the Watch seems to have fixed it for good. I noticed that I still get the outline heart occasionally, but that stays on screen for a shorter time and sensor data is recorded just fine; perhaps that’s just a way for watchOS to avoid refreshing the display framebuffer until it’s actually needed to be shown on screen, though it also seems to happen with the always-on Series 5.

Does anyone want to, ahem, chime in?

Get rid of those apps in iTunes that you never sync anymore

If you’re like me, you’ve had an iPhone, iPod Touch and/or iPad for a few years now and have probably amassed a fairly big collection of apps, both free and paid. Until last year’s iOS 5, this meant having to keep a local copy of each and one of them on the computer you used to sync your iOS device.

My “Mobile Applications” folder contains 924 items, weighing a whopping 18.78 GB. iTunes only lists 920 apps, so something is out of sync already.
Obviously, I do not use that many apps. My iPhone 4 only has 163, and I could delete many of those as I don’t use them. My father’s iPad, which uses my Apple ID to get apps so that he doesn’t have to purchase the same ones I have already paid for, has about 250, most of them being games he tried once or twice and left there.

I’m about to phase out my glorious 2006 iMac in favor of a new Mac Mini and I’m going to just move the iTunes Library folder; this way, everything is retained and I don’t have to convince a brand new iTunes not to nuke the iPhone and iPad just because they have been synced to a different machines. As for the music itself, I could also use iTunes Match to carry it over, but I’d rather just drop the folder in and be happy about it. The point is that I really don’t want to waste about 20 GB on the new computer for apps I honestly don’t care about.

The most immediate method, deleting the apps from iTunes, kind of works… except that if you delete an app that’s used on your device, it will be removed from that device upon syncing. The proper way to do this would be to manually delete from iTunes the ones you’re not using. There’s a little problem with that: there is absolutely no way of knowing whether any local app is being synced to any device or not, unless you manually check whether every single app is on any of your devices. This sounds dreadful enough with my iPhone, with which I’m very familiar; doing it with my father’s iPad sounds like a nightmare.

Thankfully, after a little searching, I found the way to do it in a much easier fashion. Of course, if you follow these instructions and you delete important data or things like that, I’m not responsible. Do this at your own risk.

I’m using iTunes 10.7 on OS X 10.7 Lion, but it should be the same on OS X 10.8 Mountain Lion. When iTunes 11 is released in a few days or weeks, it’s probably going to be much different.

The first, very important thing to do is to disable automatic syncing. To do this, open iTunes’s preferences, go to Devices, and check Prevent iPods, iPhones and iPads from syncing automatically. You can do this even when your device is not connected, but I recommend doing this when it’s already connected so it’s even less likely that something goes wrong.
After you’ve made sure that the new device does not start to sync automatically, go ahead and run a full backup, just in case something goes wrong. Find your device in the sidebar, right click on it, and choose Back Up. It will take a while.
After it’s done backing it up, it’s time to rock and roll.

Click Apps in the the Library section of the side bar, and either choose Select All from the Edit menu, or hit Command-A on your keyboard. Now all your bazillion apps will be selected. You can either delete them, which I do not recommend, or you can move them to a folder. With all of them selected, just drag them into a folder you previously created with the Finder to make a manual backup of all of them. Again, it will take a while. Once all the files are safely copied, you can delete them: just press backspace on your keyboard, or choose Delete from the Edit menu. At this point your may get a scary message warning you that the apps will be deleted from all devices to which they had been copied. Confirm the deletion and move to trash; that’s why you just copied them out.

Now, here’s the nice part. With your device still connected, right click on its name in the sidebar and choose Transfer Purchases. You may be asked for your Apple ID password, and iTunes will make a local copy of all the apps that are currently on your device.
Rinse and repeat for any other extra device, and you’re done: at the end you will only have a local copy of the apps that you currently have on your devices.

If you want to be extra sure that everything has been copied correctly, you may want to run Transfer Purchases again for each device. At the end, you can safely re-enable automatic syncing. If you start the syncing procedure immediately, it should not copy (nor delete!) any apps in any direction, meaning they are already synchronized.

At this point, if you want, you can delete the backup folder you had copied your apps to when you began this whole ordeal. I’d suggest keeping them on a backup disk just in case, but unless the apps are pulled from the App Store, you can safely download them again at no extra cost at any time.

Personally, I ended up recovering about 13 GB by doing this. Not bad, considering that from my point of view those 13 GB were filled with pointless fluff!

Printing in grayscale with AirPrint

Did you all think I was dead? Unfortunately for you, I am not. I’ve just been fairly busy with work and with my renewed interest in photography. Speaking of which, all of you should follow my Flickr photostream, which I update daily.

So, you’ve got the shiny new iOS 4.2 on your iPhone 4 and you have enabled AirPrint sharing on your Mac, using either the free Hacktivator or one of the commercial packages. You are very satisfied (albeit a bit doubtful about actually using it in the future), except for one thing: it prints in color, and you really wish it could print in grayscale, because toner is not cheap.

Continue reading “Printing in grayscale with AirPrint”

How to use resizeTo in Safari (if it doesn’t work)

Many people are probably familiar with the fact that most browsers allow Javascript code to be entered in the address field. That’s the magic behind bookmarklets, which simply spare the user the hassle of manually typing long, convoluted and obfuscated Javascript statements.

While it’s usually pointless to do so, there is one case in which it makes perfect sense: resizing the browser window to an arbitrary size, in order to test what a website looks like. Essentially, by setting the browser window to a size such as 1024 x 768, one can have a relatively reliable idea of what the current website would look at that screen resolution. In truth, one would have to take the graphical elements of the operating system in question, but it’s usually a fine way to get an idea.

The code to do so is very simple:
window.resizeTo(width, height);

Therefore, if we want to set the window to 1024 x 768 pixels, we type the following pseudo-address:
javascript:window.resizeTo(1024, 768);

and press enter. A few things worth noting:

  • Capitalization is important. It is resizeTo, with a lowercase “r” and a capital “T”
  • There is no space, nor any slash, after the colon
  • The width and height have to be separated with a comma, and (of course) have to be integers
  • The semicolon at the end is optional, but if you’re a programmer it will be natural to type it
  • In some browsers, you can omit the “window.” part, as the current window is implied

This is all good and great, and works in most browser.

Safari, however, only allows this intermittently. Since I spent some time making tests to figure it out, here is a tip: Safari will execute resizeTo only when there is one (and only one) tab in the window.

I’m not sure whether this is caused by a specific setting on my machines, or if it’s a default, or if it can be even changed, but I can see the point in this behavior. Since some websites have the bad habit of resizing the current window to full screen (an annoying and pointless habit, if you ask me), Safari blocks the execution of such command in order not to disrupt the concurrent navigation of different websites/pages.

It’s as if it said: “if this is your own window, do what you want with it; if not, you’ll have to respect your tab brothers.”

So, if resizeTo isn’t working for you, drag that tab out of the bar so it’s instantly opened in its own window, and try again.

Manual duplex printing on a laser printer

My laser printer, a Samsung CLX-3175, does not have any tool for automatic duplex printing. Achieving such result manually is not difficult, but may take some trial and error in order to get the settings right. That’s exactly what I’ve done, and I’m writing this post as a note to myself. Should it be useful to anybody else, however, by all means let me know with a comment.

Keep in mind that this is for my own printer, and that I use OS X 10.6 “Snow Leopard.” Results may vary with different printers and/or operating systems, so make your own tests. If your printer outputs pages “face down,” this will probably work as it is. Most ink-jet printers on the other hand output prints “face up,” so some adjustments will be necessary.

In any case the steps for my own printer are very, very easy (once you’ve figured them out correctly):

  1. Print all odd pages in normal order
  2. If the total number of pages is an odd number, take the last sheet and put it away for the time being
  3. Take the (remaining) sheets and put them back into the tray after rotating them 180°. Do not flip them in any way!
  4. Print all even pages in reverse order
  5. If you put the last sheet away in step 2, put it back at the end of the stack
  6. There is no step 6

Enjoy. 🙂

Prettifying URLs with fake subdirectories using mod_rewrite

Lately, I have been trying to define a common basis for most of my web projects, since I often end up reinventing the wheel every time. I have tried a few PHP frameworks, but none of them tickled my fancy, but I have complicated tastes. I am known for reimplementing something from scratch rather than wasting time adapting other people’s code to my needs, and it’s often much faster too.

Therefore I have been working on JBFW, my very own PHP/Javascript framework. One of the key components of it is pretty URLS and a centralized index.php to handle most of the things.

If you access http://mysite.com/news?lang=en, the server will transparently route that to http://mysite.com/index.php?pagename=news&lang=en. At that point, index.php runs the news module if it’s present, and then loads the news template (possibly showing the result of what was done in the module, if it was called at all.) I find that it’s a very slick and modular way of handling things, as static pages only need new templates and boom, they are live, with the rest of the framework readily accessible.

The mod_rewrite configuration for such a behavior is as follows:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?pagename=$1&%{QUERY_STRING}

This means: if the requested filename is not a directory and is not a file, route the request as described (knowing something about regular expressions, or being proficient in creative swearing — which goes hand in hand with regexp — comes in very handy at this point.)

I used a similar, but coarser, approach on my own main website, http://www.nicolucci.eu. There, I even used fake subdirectories, so that http://www.nicolucci.eu/photography/book/glimpses will have it show the photography-book-glimpses template. Neat, but doesn’t work with real subdirectories. It’s not a big problem on that site, but when you need to have a separate administration section, you need real subdirectories. The problem is that, using the approach I described above, http://mysite.com/admin/login into http://mysite.com/index.php?pagename=admin/login, and while the correct function could be run in PHP by mangling the request as it’s done for the “top level” modules, it could quickly turn into a nightmare.

The solution is to add another set of mod_rewrite rules, as follows:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((.*)/)+(.*)$ /$2/index.php?pagename=$3&%{QUERY_STRING} [L]

Yes, that’s incredibly messy, and I’m pretty sure that there is a better way to do it. However it works, and for now I’m going to concentrate on finishing the website and go back to it later. What this does is: if the request has one or more blocks ending wish a slash (the directory), followed by something else (the file name), it is routed to index.php inside that directory, using the file name as a parameter to pagename, plus the original query string as usual. The [L] at the end tells mod_rewrite: please refrain from doing any other change, this is flaky enough. This ensures that http://mysite.com/admin/login effectively calls http://mysite.com/admin/index.php?pagename=login.

Note that this is another block of RewriteCond and RewriteRule, and goes before the original one. I tried to put them together, since the conditions are the same, but after fifteen minutes of trying all combinations I gave up. I’m sure I was one attempt away from getting it right.

A very clever thing (ok I’m kidding, it’s a side effect I hadn’t fully realized but I’m glad it’s there) is that addresses such as img/logo.png are not rewritten because those files do exist. It would probably make sense to exclude common file extensions, such as image files and javascript, from this kind of mangling; or even better, make it only work when the “file name” part does not have a dot in it. I’ll find a way to do it, at some point.

To finish up, an extra little trick that can come in very handy when you want to make sure that certain files are not downloadable by anybody:

<Files ~ "\.sqlite3$">
Order Allow,Deny
Deny From All
</Files>

Make sure that there are no spaces on either side of the comma in the first line. I was quite frustrated because I kept getting the infamous error 500, and there it was.

I hope this spares someone from wasting as much time as I did with this kind of thing!

20 tips to run a business without committing suicide

Starting earlier this year, I have been a “professional” IT consultant (libero professionista in Italian.)

In practice I mostly deal with web development and computer repairs. It’s what I’ve been doing for over a decade now, since I was still in school, only now I get to pay my own taxes (yay) and therefore I get angrier when people try to rip me off. So, here’s a collection of tips about running a business I put together based on my experience. Note that I refer to the client as a “he,” but that’s just for simplicity.

  1. Befriend a lawyer. You will need one sooner or later. Most likely sooner.
  2. Assume the client doesn’t have any clue on the details of your job. Listen to his ideas, make a mental note of how you’ll approach the problem in practice, and be ready to explain to him why his “perfect” solution just doesn’t work and needs to be achieved differently.
  3. Use lots of metaphors to explain to the client why you’re doing what you’re doing, and why you’re not doing what he thinks you should be doing. Cars and houses are what people understand the most.
  4. Always require an advance payment to start a job and always require the settlement to deliver it. This protects the client from an unfinished work, and protects you from an unpaid work: if the client doesn’t settle, he loses the advance and doesn’t get the job delivered.
  5. Approved and signed quotes are fine for small jobs, but for anything more complex, a full written contract is best. Be shielded from requests that were never discussed in the first place.
  6. Don’t be afraid of writing long contracts. Rather, make sure you cover everything in clear terms. And use a big font. Contracts in small fonts are scary to most people.
  7. Assume all clients are going to try and rip you off: give little trust to strangers, trust friends even less, and just avoid relatives altogether.
  8. If a client asks for a discount, especially if it’s the first time they come to you, deny it and remind them that discounts are a (rare) privilege, not a right.
  9. Do not give discounts on the first job upon the promise that a client will come back to you, because they most likely won’t. Rather, have him pay full price on the first job and promise a discount on the next one.
  10. If some problem arises during the execution of the job, let the client know immediately, even if it’s something trivial. They will appreciate the openness and it’s a good long-term marketing strategy. By the same token, give the client as many details about the work as he needs, but no more. Too much information yields the opposite effect and confuses him.
  11. Do not plan your financial life around prospective clients. Until a quote or a contract is signed, there is no client.
  12. Realize that most clients do not check e-mail regularly or that they are unable to use it properly. You will be in touch with your clients over the telephone.
  13. Take note of the timeline of a job, ie. how long the client takes to do his part (send you materials, issue the payments, etc.) This will let you profile the client so that you can subsequently offer discounts or raise the price accordingly.
  14. Set a base price for the job, and always give a higher quote. Even if the client accepts it as it is, it leaves you room to reduce it and make a good impression on him. Again, this is good long-term marketing strategy. Moreover, learning the fine art of haggling allows you to anticipate your client’s moves and counter them.
  15. If your area has geographical stereotypes about work ethics, be prepared to see them reversed.
  16. Round prices so that they are more client-friendly when including tax, but always think before-tax for your own planning.
  17. Use legalese only when things get rough and you are getting ready to call your lawyer into the game.
  18. If possible, send printed invoices by mail after signing them. This is often pointless, but gives you the chance to add a bunch of business cards that your client can give around if they’re satisfied.
  19. Use a secondary phone number for work and give it around whenever you have the chance.  The more people have it, the more potential clients have it. And you can always turn it off if you need a break.
  20. Accept the fact that dealing with clients is like going to war. It’s bloody, messy, time-consuming, frustrating, psychologically impairing and even when you win, you wonder whether it wouldn’t have been a better idea to buy some land and grow carrots and potatoes instead. And in most cases, it would have been a great idea indeed.

Fix broken IMAP attachments in Mail.app

I have recently started getting broken images in Mail.app. Often, when someone sent me relatively big pictures (over 1 MB in size), the image ended up being corrupted, with a smaller file size that one would expect. This results in a picture that’s visible up to a certain point, and then rest is usually filled with solid grey by the viewer.

While this could happen because the attached image is indeed broken — that is, if the sender is attaching an image that’s already corrupted on his/her machine —, it’s unlikely that the file gets mangled during the transit. To begin with, the base64 encoding adds lots of CRC (1/3 of the file size, and this alone explains why it’s a very bad idea to send big files through e-mail). In addition to that, no MTA will accept a malformed message: MIME parts must be completed with an extra boundary marker, and the infamous dot on its own line has to be there to commit the DATA part. Using a webmail system makes it even more difficult to corrupt a file in transit, because there is the extra uploading step that ensures that the attachment reaches the server before the message is constructed and finally sent.

If none of this makes sense and you want to know more, please refer to RFC 2821, but the point is that it’s virtually impossible for several people to send corrupted images. It’s way more likely that the problem lies within the recipient’s client.

With OS X’s Mail.app, these problems happen when there is some communication failure during the download of the message. Essentially, if the download gets interrupted for any reason, Mail.app may be unable to notice and will be perfectly happy with the broken file. There are two ways to fix this:

  • The hard way: go to ~/Library/Mail, and for each INBOX you may have, delete anything inside the Attachment folder
  • The easy way: select your Inbox folder within Mail.app and simply run Mailbox → Rebuild

That should take care of the problem. Note that the Rebuild procedure will redownload every message from the server again with all the attachments, essentially resynchronizeing the local cache with whatever is on the server, fixing any discrepancies. It may take some time, but you can keep an eye on the progress by opening the Activity window (Window → Activity, or ⌘0.)

Chords for “Soft Kitty,” from The Big Bang Theory

One of the funniest “inside jokes” of The Big Bang Theory is the song that Sheldon’s mom used to sing to him when he was sick. It’s featured in three episodes, as you can see here:

httpvh://www.youtube.com/watch?v=lqSmzGj_sQc

The song is, like most lullabies, very simple. I came up with the chords earlier today, while jamming with my ukulele. Here they are, for all my musically-inclined nerdy readers. Corrections are welcome.

[G] Soft kitty, [C] warm kitty,
[G] little ball of [D] fur;
[G] happy kitty, [C] sleepy kitty,
[G] purr, [D] purr, [G] purr.

Interesting trivia: they are almost the same chords as The Lion Sleeps Tonight, except for a minor difference in the last verse that shouldn’t prevent the most creative among you to fit one into the other.

Should you prefer so, you could play it as C F C G / C F C G C or by whichever transposition makes you happy.

Speed up connections to IRC servers

I have recently gone back to IRC — specifically Freenode — and among the delicious problems of the old days, such as the inability to easily establish DCC transfers (more on that later), I have been presented with the inevitable ident check delay during the connection to server. Ident is essentially a protocol that lets the server know what user is effectively connecting from the client machine. It can be very handy, but most people are behind NAT and/or do not run any ident daemon. This translates to a delay while the server patiently waits for an ident reply before giving up and adding a tilde to the username in the hostmask, which effectively means “this user claims to be called foobar, but I could not verify it.” In practice, this doesn’t change anything at all.

Continue reading “Speed up connections to IRC servers”