Easy ticks and crosses using FontAwesome

I spent a few minutes knocking up a comparison table for a project today and wanted an easy way to have ticks and crosses. After a bit of experimenting I found out that the excellent FontAwesome project makes this quite easy:

Per-component loading spinner for AngularJS

One of the first things that people want to do with AngularJS is to have a loading spinner on their page to prevent the unseemly appearance of a page with no content loaded because you’re waiting on an ajax xhr request. There are quite a lot of these spinner plugins available, or you can relatively easily roll your own.

However most of these are whole-page ie if any infly request is happening, the whole page appears blocked to the user. This can be quite annoying and give the impression of your site being pretty slow. What other sites heavily dependent on ajax (eg Facebook and LinkedIn) typically do is have each individual block/component on the page display a loading graphic so that perhaps your friends list is marked as loading but your news feed had already loaded.

Fortunately with AngularJS’s awesome scope, factory and component design it’s very easy to bolt this on to an existing app in just a few minutes. Let’s look at some code.

Firstly, (as you should be doing already) you need to have your ajax request going through a single point in your code such as the skeletal factory below. I’d typically do something like this:

Then we extend this so that the req function can have a scope passed in which will have a variable called infly_http_request which contains the number of outstanding ajax requests under that scope. We now add this in to the api service replacing the req function with something that will check the requests:

Basically if a scope option is passed in this will scope the spinner to that block, otherwise it will use the global scope so you can still do a whole-page lock.

Finally here’s a quick directive to apply to a nice and easy spinner using fontawesome:

And the LESS (CSS) to go with it:

You can then write your Angular component and HTML as:

Anything within the show-spinner container under the controller and the scope attribute passed in the req() call will be replaced by a spinner while the request is in progress. If not you can have something in the main body of your page to show a spinner like:

rsync with remote filenames with spaces in from bash

Something that always annoys me with rsync is that due to executing a remote shell, any characters in the remote path name require double-escaping (once for this local shell, once for the remote one). For example

creates a remote folder called ‘my’ and puts the directory into that. The solution is to do something like:

But how to do this when you’re running from the shell eg iterating directories? One way would be to use a command like $(sed …) to handle the escaping, however you can do it purely in shell using two different types of quote. For example today I had to do: