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

Using Reduce to Remove Duplicates

Most examples I see for reduce talk about summing up numbers. Can we use reduce to do more than punching numbers? Doesn’t it sound ironic that these accumulator or sum calculator examples look more like they are increasing some values rather than reducing? I know I’m pushing the envelope here. I think removing duplicates from an array would be a more suitable example of reducing the array we are working with. Because, after all, we would be reducing it to a minimal state.

How ever you define what reduce does, here is my take on using reduce to remove duplicates from an array. It only works for simple data types of course but you can enhance it the way you see it fit. For simplicity sake, I’ll attach my solution to Array.prototype. Again, this is optional.

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

Programming

For The Love of Eve!

Roughly two months ago, I rekindled my love for Eve. It had been the most exciting thing when I started to play in 2005. I renewed my membership and kept playing when I moved to Toronto in 2008 from Istanbul. After another 3 years, I stopped my Capsuleer experience in 2011 November. So, my character has been in a Cryo pod for almost 4 years. I think I have a better control of my life now so I can afford some free time without feeling guilty but this is not the essence of this article.

4 years is a long time and a lot has changed in Eve. I always liked Manufacturing and other side businesses in this game and I’m now investigating newer ways of making money with more advanced blueprints. One thing I did not have back when I left is that I now know Python so I can utilize it to do the heavy lifting in certain areas. Like finding all the blueprints that use the same raw materials! If I have excess quantity of a certain commodity what other blueprints can be used to spend what I have?

Could this question also be formulated as : If a company has commodity A,B and C; find all the people who have purchased these items and the quantity they did so we can figure out clients’ spending behavior, frequency or whatever. I know people are not blueprints but putting the problem in a familiar context sometimes helps. However, we are going to shop not even online today but offworld. Up we go!

Continue reading