Service Workers in iOS?!!!!111one

Someone has spotted a bug in WebKit’s Bugzilla with a patch for implementing Web IDL and stub for Service Workers.

The “PWA community” is 🔥 on fire 🔥 on Twitter right now.

I find this amusing, as I think it was only yesterday that I was reading Yet Another Rant in Medium by someone who had to learn React Native instead of just building a website, because iOS didn’t support Service Workers, also accusing Apple of not supporting the Web because it doesn’t make them any money directly. I don’t think that was the straw that broke the camel’s back, but it’s a funny coincidence.

I also don’t know where the rant is, as people share so many Medium “pieces” in twitter and I find it hard to differentiate between them. I also often just open in an incognito window out of habit so I can’t even find it in my history.

Anyway, I’m excited! It won’t be implemented next month (I reckon), and we’ll probably have to wait until the next big iOS roll out that ships a new Safari, but it is nice to see movement rather than a stern ‘under consideration’. In the future, you will not need to build two or more different versions of a native app, using different programming languages, in order to get offline support, push notifications, etc, etc. Yay!

I’m also secretly happy that WebKit use Bugzilla as well. There’s something about shared pain that fortifies the soul… 😂

Google Calendar shortcuts and tricks

Since I started managing people, I spend a lot of time looking at my calendar!

Here’s some shortcuts I use a lot:

  • view:
    • m: month view
    • w: week view
    • d: day view
  • navigation:
    • n: next (if you’re in month view, it jumps to next month, if you’re in week view, it jumps to next week, etc)
    • p: previous
    • t: jump to today

I have the calendar pinned on the first tab, so ⌘+1 always brings me to it (I think it’s CTRL+1 in Windows and Linux).

The first thing I do in the morning is to look at what’s in for today–this way I make sure I don’t forget to attend important meetings because I get deep down into something else and then I forget. So I will press “d” and “t” to get the calendar to ‘day view’ plus ‘today’.

I use the other shortcuts to quickly flip between dates when I’m booking new events or to find what is upcoming.

There are also shortcuts to create and edit events but I found them not very useful as you still have to modify the time and date of event anyway-I find it easier to use the mouse to schedule this.

“*Utils” classes can be a code smell: an example

You might have heard that “*Utils” classes are a code smell.

Lots of people have written about that before, but I tend to find the reasoning a bit vague, and some of us work better with examples.

So here’s one I found recently while working on this bug: you can’t know what part of the Utils class is used when you require it, unless you do further investigation.

Case in point: if you place a method in VariousUtils.js and then import it later…

var { SomeFunction } = require('VariousUtils');

it’ll be very difficult to actually pinpoint when VariousUtils.SomeFunction was used in the code base. Because you could also do this:

var VariousUtils = require('VariousUtils');
var SomeFunction = VariousUtils.SomeFunction;

or this:

var SomeFunction = require('VariousUtils').SomeFunction;

or even something like…

var SomeFunction;
lazyRequire('VariousUtils').then((res) {
  SomeFunction = res.SomeFunction;
});

Good luck trying to write a regular expression to search for all possible variations of non-evident ways to include SomeFunction in your codebase.

You want to be able to search for things easily because you might want to refactor later. Obvious requires make this (and other code manipulation tasks) easier.

My suggestion is: if you are importing just that one function, place it on its own file.

It makes things very evident:

var SomeFunction = require('SomeFunction');

And searching in files becomes very easy as well:

grep -lr "require('SomeFunction');" *

But I have many functions and it doesn’t make sense to have one function per file! I don’t want to load all of them individually when I need them!!!!111

Then find a common pattern and create a module which doesn’t have Utils in its name. Put the individual functions on a directory, and make a module that imports and exposes them.

For example, with an `equations` module and this directory structure:

equations
  linear.js
  cubic.js
  bezier.js

You would still have to require('equations').linear or some other way of just requiring `linear` if that’s what you want (so the search is “complicated” again). But at least the module is cohesive, and it’s obvious what’s on it: equations. It would not be obvious if it had been called “MathUtils” — what kind of utilities is that? formulas? functions to normalise stuff? matrix kernels? constants? Who knows!

So: steer away from “assorted bag of tricks” modules because they’ll make you (or your colleagues) waste time (“what was in that module again?”), and you’ll eventually find yourself splitting them at some point, once they grow enough to not make any sense, with lots of mental context switching required to work on them: “ah, here’s this function for formatting text… now a function to generate UUIDs… and this one for making this low level system call… and… *brainsplosion*” 😬

An example that takes this decomposition in files to the “extreme” is lodash. Then it can generate a number of different builds thanks to its extreme modularity.

Update: Another take: write code that is easy to delete. I love it!

Organising files in Google drive

We use Google Drive at work and for a particular project we ended up in a situation where there were multiple documents related to it, but not an easy way to have “links” to all of them on the same place.

One solution would be to create yet another document and link to the documents. Another one is to bookmark documents in your own browser—but the issue is that if someone wants to collect all the links together in their computer, then they have to bookmark the stuff individually as well.

But there’s an easier way: you can make a folder in Google Drive and add any file to it (whether it’s owned by you or not). Then you can share the folder, and voilà! everyone has access to the collection of documents.

To make a folder in your drive, first go to your google drive. Click NEW… folder. Give it a name, for example: Magnificent folder.

Then go to the document you want to add to the folder, click on the File… menu, select Add to my drive. A little pop up will show up, click on the Organize link… Choose Move to folder, and choose the Magnificent folder you created before.

If you refresh the folder in your drive, the document should be present there.

To share the folder, click on the down-facing arrow on the right hand side of the name of the folder. This opens a drop down menu and you can select “Share…” to open the usual Google docs interface to share stuff with people.

Done!

I’d also suggest that changing the folder view from grid to list, showing the document titles, might be useful in many cases, as the document titles tend to get truncated way too easily.

Copy using the command line without overwriting existing files

I learnt about cp‘s -n (or “no clobber”) option that lets you copy, but not overwrite files that already exist:

cp -Rvn folderA folderB

The above would Recursively copy the contents of folderA into folderB, and print a message per file it copies (with the v option). Great to know when things get stuck or interrupted 🙂

It’s quite useful when trying to copy from something like a folder in a remote drive that keeps disconnecting. So if the network times out you can always run the command again after reconnecting, and it will skip files that are already there.

Note that if a file has been partially copied, then cp will skip it the next time and not complete the download. So don’t use this method for stuff that requires some degree of integrity–you’d better reach for tools such as scp.