Programming

Sorting An Array of Objects

This post has been on my mind for a while. Today, I would like to talk about sorting an array of objects. This exercise assumes your array is uniform, meaning all elements in the array are of the same type. To keep things more simple, I’ll assume you know what you are doing and we won’t check whether the array is uniform.

Additionally, we’ll keep this functionality as part of Array prototype so you can keep using it as if it is a native method rather than passing your array as an argument. One last note before we dive into the code is that while we are implementing our solution, we may as well throw in a way to sort the array ascendingly or descendingly.

Continue reading

Programming

A Better Way of Bookmarking Code Snippets

In an earlier article, I talked about placing your Javascript code snippets as bookmarks. I used this technique to get a list of books on Goodreads and to enhance the user experience on Safari Books Online for their video section. In both examples, I dumped the code directly into the URL section of the bookmark right after typing javascript:. If you need a refresher on how to do this, please check out my earlier article.

Now, can we do a better job than dumping the code there? And, why? Because it’s tiresome to keep pasting the code again and again when I make changes to it. Because the code already lives in a Gist, so it only makes sense that we trigger the Gist code when the bookmark is requested.

Continue reading

Programming

Trifecta: Filter, Map, Reduce

I love using Goodreads. There is a great community there; contributing to the site with their comments, reading lists and such. When I discover a new list such as the Riftwar Cycle, I want to copy the book names to a Google Sheet. When I visit a bookstore, I then pull up the file to see if I have already purchased it or not. So, my Google Sheet is ever changing but one thing stays constant. My rate of buying books is exponentially growing over the rate of reading what I already own.

Some lists are mixed, meaning they are part of a universe and there are many authors contributing to it. In that case, I would like to write down the author’s name next to the book’s title. You might wonder if it would be a better idea to group the items by author name first then the book title. I thought about doing it that way too first but then the books that I’m usually interested in are grouped by type so they are all clustered in one bookshelf rather than distributed all over the store by the author’s name.

So, our goal is to parse a list out of page content in the following format: Book Title, Author Name.

Continue reading

Programming

Bookmark Code Snippets

I’ve recently written two articles that depend on a bookmark. I figured it would be easier to use this article as a reference when I conclude future articles where I need to mention the bookmark method.

[EDIT] This method has had a major update since I wrote this article. If you follow here, you’ll see that there is a more elegant way of running code snippets but you might still like to refer to this article for simpler needs, especially when your code is not hosted.

Continue reading

Programming

A Better Safari Books Online Experience

Now, my experience with Safari Books Online has been great so far, mainly due to the free access I get thanks to Toronto Public Library. As far as I can see from the feature set, you can create playlists and the dashboard is tailored towards your use of content. This is, of course, a completely different mileage I get from the free service. There is none of that custom profile you can keep and sometimes if there are too many people logged in using the Library account, then you are locked out.

However, none of this is what I’d like to talk about in this post. I want to talk about a different kind of user experience and maybe offer a solution. At least, it’s what I’ve needed all this time without realizing I’ve had the power to do something about it. So, shall we?

Continue reading