An Alchemy News API Library for Node.js

A few months ago, I worked on a project that required some natural language analysis of recent news articles from around the world. I decided to achieve this  using a third party natural language processing API. This led me to AlchemyAPI.

AlchemyAPI is an IBM company that provides twelve different semantic text analysis APIs that leverage state-of-the-art natural language processing techniques. One of the provided APIs is AlchemyData News. This API provides the ability to carry out targeted semantic search and analysis of recent news articles and blogs from around the world. For instance, using AlchemyData News, one can search for all positive news articles about Google published within the last 30 days.

AlchemyData News was exactly what I needed for my project. Since I was working with AngularJS and Node, my first instinct was to find a Node.js library for AlchemyData News. I felt this was necessary because AlchemyData News provides an extensive query language that I considered to be overkill for basic targeted search queries. I also found the query language to be quite verbose, although I could see why it was so, considering that such a service must support complex and flexible queries. Unfortunately,  at the time, I was only able to find a Node.js library for the more mature and popular AlchemyLanguage API which provides general text analysis services. I eventually resorted to making raw queries to AlchemyData News using the provided query language. However, in that moment, I decided to eventually get around to creating a simple Node.js library for AlchemyData News. My intention was to make it as similar as possible to the excellent Node.js API I had found for AlchemyLanguage.

I have recently completed a basic implementation of a Node.js library that simplifies some of the basic queries supported by the AlchemyData News API. There are a lot of additions and improvements that can be made to the library especially with regard to supporting some of the more flexible querying capabilities provided by AlchemyAPI. However, this basic version provides the ability to retrieve:

  • categorized news content by searching for news on topics you care about e.g. baseball, mobile phones, etc.
  • news content containing abstract concepts e.g. democracy, polygamy, etc.
  • news content containing specific keywords where keywords are terms explicitly mentioned in the article that are determined to be highly relevant to the subject matter of the news article.
  • news articles containing named entities e.g. proper nouns such as people, cities, companies, products, etc.
  • news articles based on positive, negative or neutral sentiment.

The primary purpose of this Node.js library is to simplify the construction of some simple queries supported by AlchemyData News. It works for some basic queries but is far from being a complete mirror of the capabilities provided by AlchemyData News. I encourage everyone who finds this useful to make changes, suggestions and contributions as necessary.

Documentation and source can be found at

Extracting Raw Location Data from Android Mobile Phones

Some months ago, a friend of mine told me about a research study that required some analysis of location data that was to be potentially gathered from participant’s mobile phones. This got me thinking about building a simple Android mobile app that gathers location information, stores it in a database and allows this data to be exported in an appropriate format. I eventually built a working prototype called LocMon. This prototype does the following:

  • It enables users to start and stop the collection and storage of location information.
  • When users initiate data collection, the app collects and stores finely grained longitude and latitude information about the device’s location. The user can stop this data collection at any time by pressing a stop button.
  • Users can erase all collected data.
  • The application allows users to export all collected location information by sending a JSON file to a specified email address.

This was simply a learning experiment for me. However, it is possible that others might find the app and source code useful either for personal amusement, learning about Android or for research studies that require real-world location information. Below is a brief video of how the application works. You can find the application source code here on Github. An APK file is also available here for download.

A Diary of Solutions to Common Coding Interview Questions and Programming Puzzles

Over the past few months, I have tried to form a long-term habit of reading about and writing solutions to programming puzzles and common coding interview questions. In the process, I have implemented quite a number of solutions to many programming puzzles and compiled them into some sort of constantly updated “diary”. This “diary” is maintained and updated as a git repository on Github.

As at the time of this blog post, the repository contains 60 Python solutions to about 55 programming puzzles and common coding interview questions. Find the repository here:

The Unstoppable Rise of Twitter “Screenshorts”

Since M.G. Siegler’s post about “Hacking the Tweet Stream” and my little contribution to the “screenshort” trend, I have paid relatively close attention to the apps and tools being built to share text as images on social media platforms, especially Twitter.

A number of people have very eloquently outlined the downsides of this trend. Foremost among the points raised against sharing images of text on social media are:

  • Accessibility issues due to inability of screen readers to parse text in images.
  • Tiny device screens and disparity of image quality on different screen sizes.
  • Mis-configured and overzealous ad-blockers that may prevent the images from being shown.
  • Unreliable internet connections that are unlikely to load images quickly.
  • Text rendered as images cannot be automatically translated or searched.

These are all fair and important points. But are they cogent enough to stall mass adoption of this use case for images on social media?

I find this trend of sharing text as images and its associated apps incredibly amusing. Most of the apps fall into either one of two categories; those that focus on creating and sharing your own content as images of text on Twitter and those that focus on sharing pieces of other people’s content that you find interesting. Since M.G. Siegler’s initial post, many apps and tools  have sprung up including:

Squall – I am particularly impressed by Squall. It was created quite recently and is a very nicely laid out app that generates pretty neat images of your posts. Also, through Squall, I found Assembly which seems like a really cool platform for collaboration.


Cliptext – My own attempt at hacking the tweet stream to scratch my own itch. I like sharing short excerpts from articles I read on the Internet. This can sometimes be a difficult thing to do because of Twitter’s 140 character limit. So, I decided to create a Chrome extension and Android app to automatically convert selected text in my browser into an image and share it on Twitter.

cliptext – built by Karan Goel. apparently morphed into Squall.


Oneshot – This is an incredibly well-designed iOS app for sharing screenshots of articles. Just like Cliptext, this app seems to focus on sharing pieces of other people’s content that you find interesting. It does some pretty amazing things like automatically finding the source URL of the screenshot. The app takes a very intelligent approach to content attribution and generates really attractive images.


Medium, the popular writing platform, recently announced the ability to “highlight any passage on Medium to create a screenshot tailor-made for tweeting”.


Pablo – This is a web app that lets you “design engaging images for your social media posts in under 30 seconds”. It provides beautiful background images for short pieces of text and also lets you upload your own background images.


Judging by the quality of some of the aforementioned apps and the amount of effort obviously being put toward pushing this use case for images on Twitter and other social media platforms, one can see that there is traction to be found for the “text as images” use case. However, as is often the case with trends, this could just be something that would eventually fizzle out with time. Nevertheless, there is no denying that sharing passages of text as images, especially within the confines of Twitter’s 140 characters, can be quite useful despite its obvious downsides .

Struggling to Keep Up; Rediscovering the Pomodoro Technique


Going through a Computer Science PhD program is a grueling ordeal. At this point, it is not about writing exams and doing homework. There is that great scary monster called RESEARCH that needs to be tamed. If there is only one thing I have learned thus far, it is that computer science research is quite complex and time-consuming.

I truly enjoy building and thinking about web and mobile applications. However, I have reason to believe that it is possible to be a stellar doctoral student in Software Engineering and be relatively ignorant of web and mobile applications development trends. Chances are that things like AngularJSGruntJade or Ionic have little to no business with your research. This is not to say that there are no doctoral students conducting research in web development tools and technologies. It is just that as a doctoral student in Computer Science, you are more likely to be dealing with things at a much lower level than a JavaScript framework or templating engine.

My research interests are in Software Engineering. As a doctoral student in this area, I do not necessarily get to spend a lot of my time sharpening my applications development skills even though I am actively carrying out Software Engineering research. Trying to stay aware of rapidly evolving web and mobile applications development trends and keep my applications development skills and project portfolio up to par while also making reasonable progress on my doctoral research has been a real struggle. I daresay this is not for the faint of heart. There are a thousand and one things to do, deadlines to meet and self-assigned goals to achieve. Having a PhD is nice, but I refuse to graduate with the degree and find out I have lost touch with practical and readily applicable industry tools and trends.

A few months ago, I came to the stark and sudden realization that I simply was not keeping up with neither my research nor advances in web and mobile applications development tech. Every Software Engineer knows how quickly the software development landscape evolves and how vital it is to stay up to date if one is to remain relevant. Not only was I struggling to find research direction, but I was also beginning to lose track of the myriad of tools, frameworks and patterns that are becoming de facto industry standards in this present day and age. I needed to do something about my apparent lack of productivity and effectiveness if I was to have any hope of being the kind of well-rounded computer science professional I strive to be.

Sometime early last year, while carrying out my regular “online stalking” activities, I stumbled on a number of posts by Adulfattah Popoola where he wrote about how he uses the Pomodoro Technique to improve his efficiency and productivity. Since I am one hell of a copycat, I decided to adopt the technique and structure my days around Pomodoros.

One fundamental assertion of the Pomodoro Technique is that multitasking and distractions are counter-productive. Many of us like to think we can multitask effectively. However, a focused assessment of just how much work we actually get done while “multitasking” compared to what we achieve if we focus on a single task during a single time stretch seems to suggest that humans are pitifully bad at multitasking.

The following is my basic understanding of the Pomodoro Technique and how I have chosen to use it.

  • A Pomodoro time block is typically 25 minutes, although you can choose to make it whatever length of time you please.
  • The Pomodoro Technique suggests that you focus on a single task during a time block and eliminate ALL distractions during that time. This means no social media, no phone calls, texting, eating, drinking, smoking, dying, NOTHING but the task at hand all through the entire stretch of a single time block.
  • After each 25 minute time block is a 5 minute break during which you can do whatever you want. During this break time, I would typically do a quick social media crawl, read some random article or take a walk to make sure my legs still function the way they should.
  • After each set of four 25-minute time blocks, you get a 15 minute break. I usually spend this time returning phone calls, text messages, clowning around and arguing with my colleagues in nearby research labs.

My days are typically split into two phases; research and teaching during the day, and side projects, reading and programming practice during late evenings and at night. I aim to put in 8 Pomodoros (just 4 hours of focused work) each day at the research lab working on my research, and 8 Pomodoros (another 4 hours of focused work) at home working on side projects, learning new programming tools/techniques and just generally “keeping up”. In total, that’s 16 Pomodoros (time blocks of 25 minutes) each day with pre-assigned tasks split across these time blocks. For instance, on a good evening, I currently spend 2 Pomodoros each (just 1 hour) on Android programming, JavaScript, algorithms/problem-solving and hybrid mobile applications development frameworks (I love Ionic). This configuration of tasks evolves over time as I choose to learn new things. I use an Android app called Clockwork Tomato to keep track of my time blocks.

What I find most amusing about all this is how ridiculous the actual number of hours seems to be. A mere 4 hours of work each day at the research lab seems like so little time, but you will be amazed by how difficult it can be to put in focused work for that amount of time. Also, finding 4 distraction-free hours does not always happen in one fell swoop as things get in the way and there are sometimes other things to attend to. So, squeezing out 8 Pomodoros (4 hours) sometimes requires being at work for 8 hours. A lot of the time, I am not able to complete my Pomodoro sets for the day seeing as there are times when the mind is willing but the body is weak. However, at the bare minimum, I try to complete one set of four Pomodoros each on research and side projects/interests each day. Struggling through eight Pomodoros in as many hours has a way of showing you just how little “real” work we actually get done throughout the typical work day. It is funny how life and distractions get in the way.

All this is not about working till I drop or trying to achieve mind-blowing feats of software engineering each day. It is about consistency; putting in little bite-sized steady amounts of work and practice each day without fail. In the last few months, I have made some strides that have left me a lot less devastated when I think of the state of my research and software development skills. I have been able to learn things that previously kept being eternally postponed. I believe I now have a vision and work plan for my research. Of course, I am not completely satisfied. Just a lot less sorry for myself. :)

There is lots of information on the Internet regarding the Pomodoro Technique and I understand there is even an entire book (which I have actually never read). I believe anyone who decides to use the technique needs to come up with his or her own adaptation that works best in his/her own unique circumstances. I can quite confidently say the technique has helped me keep up with the 1000 things that compete for my attention. I am definitely eager to see what things I am able to accomplish in the long run.

What productivity hacks and/or adaptations of the Pomodoro Technique have helped you keep up with overwhelming tasks and goals? Please share in the comments.

Hacking the Tweet Stream with Cliptext

Sharing images that contain significant amounts of text is something quite a number of Twitter users already do. It also seems like a pretty convenient way to “hack the tweet stream” and avoid the 140-character limit.

Sharing excerpts from online articles is something I do quite often on Twitter.  These excerpts often exceed Twitter’s 140-character limit, so copying and pasting these pieces of text directly into Twitter’s status message box does not always work out as planned. When faced with this 140-character dilemma, one option is to copy these pieces of text into and share the generated image. But being the “lazy” person that I am, I find that process a little tedious.  Another option is to create a Marc Andreessen-style tweetstorm using an app like or WriteRack. Unfortunately, this option does not seem particularly suited to sharing a text excerpt especially seeing that one might want to make a short personal comment about the excerpt being shared. Besides, there is that dreadful copying and pasting that I’m trying very hard to avoid like a plague. Oh, how I eschew the arduous labor involved in copying and pasting.

I eventually decided to whip up a quick and simple solution for myself by hacking up something I called Cliptext. Cliptext is a chrome extension/web app/Android app that converts text selections into images that can be automatically shared on Twitter. It started out as an excuse to create a chrome extension. Getting some insight into Chrome extensions was nice, but crafting something I knew I was actually going to use quite often was even more delightful.

I am nowhere near being some sort of Kryptonian super-programmer who knows how to do everything off the bat. I typically need a lot of consultation from multiple sources. My first step to conjuring up Cliptext was to read the chrome extension getting started guide  in order to get a feel for how chrome extensions are structured. Subsequently, I needed to figure out how to add items to Chrome’s context menu on text selections. This blog post by Paul Kinlan helped set me straight in that regard.

My starting point on the PHP  side of things was this Stack Overflow question where someone asked how to convert text to an image. Reading the answers to the StackOverflow question suggested that PHP’s GD/Image Processing library was the way, the truth and the life.

Not wanting to mess with PHP Curl, stream contexts and all that jazz, I decided to take advantage of some of the existing Twitter API wrappers/libraries. My first attempt was to use codebird-php, but using it felt like swimming in snake-infested muddy water and I got bitten a few times.  I guess I just could not get it working as quickly as I had hoped.  I decided to try TwitterOauth as an antidote to all that snake venom from using codebird-php. Pure heaven it was! You should try it sometime.

Cliptext did not require any complicated code gymnastics and is as simple as Chrome extensions and web apps get. The intentionally plain user interface is based on Skeleton. Putting these resources together, I eventually came up with a working version of Cliptext that met my requirements. Thanks to the various authors of the resources I used.

I have made the chrome extension available on the Chrome Web Store and the Google Play Store in the hope that it will be useful to someone. I have also provided the source code on my Github page. Maybe someone out there might be able to learn something from it, just as I have been able to learn from others.

Handling CORS Requests in Flask(-RESTful) APIs

Sometimes, it is useful to make cross-origin requests when building web applications and interacting with remote APIs. For example, it may be necessary to make a HTTP GET request from to an API endpoint at Such a request is considered to be a cross-origin request since it involves different domains. Ordinarily, such requests are forbidden by web browsers that conform to the same-origin security policy.

Cross-Origin Resource Sharing (CORS) allows requests for resources (e.g. JavaScript files, API calls, etc.) to be made from a domain that is outside the one from which the resource is being served. Using CORS, a web browser and server can team up to decide whether or not to allow a cross-origin request. JSONP is another way to achieve this.

This blog post demonstrates how to enable CORS when developing web applications with AngularJS (or any other front end JavaScript framework) and Flask-RESTful. Flask-RESTful is an extension to the lightweight Flask framework for building RESTful APIs in Python.

Imagine you decide to build your AngularJS front end using angular-seed as a starting point. Angular-seed and Flask-RESTful both provide built-in development servers. The angular-seed server for your app runs on by default while the Flask-RESTful server runs on  This qualifies as two different domains since the port numbers (8000 and 5000 in this case) are different. In other scenarios, the IP addresses (or domain names) could be different too. When your AngularJS app attempts to make a cross-origin request (e.g. a HTTP POST) from to one of your Flask-RESTful API endpoints at, explosions start going off everywhere eventually resulting in an error message that looks like this:

XMLHttpRequest cannot load No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘′ is therefore not allowed access.

When you make a cross-origin request, be it GET, POST, PUT, or DELETE, the browser first sends an OPTIONS request instead of the original request you made. Your Flask-RESTful server/API is expected to provide a response with headers specifying whether or not to allow the cross-origin request as well as what HTTP verbs to allow. There are other headers that can be specified as well. If the response is in the affirmative, the browser then sends the original request and your API responds as usual.

Browser Requests

Browser Requests

So how do you provide the adequate response to OPTIONS requests in Flask-RESTful? One way to do this is to specify that the required CORS headers be sent back each time your API responds to a request. This can be done in Flask by registering a function to be run after each request and then using that function to add the required headers to every response as shown in the following code snippet:

Lines 15-20 authorize cross-origin requests to the Flask-RESTful API by adding the required headers to every response.

Note that you do not need to change anything  on the front end (AngularJS).

As a Flask and AngularJS newbie in a hurry to complete a certain project, this stumped me for a short while. I hope this helps someone save time that would otherwise be spent searching the Internet and trying to make sense of questions and answers on StackOverflow.

Additional Resources

My Path to AngularJS

There are people who swear by AngularJS and there are those who think it is the devil. I think AngularJS is… “interesting”! It has a dastardly learning curve; the kind that gets you pulling your hair out and banging your head on a desk at 2am.

Learning AngularJS

Image Credit:

Whilst very well aware of the legendary AngularJS learning curve, I stubbornly set out to learn AngularJS and Flask-Restful as part of a research project I needed to complete in two weeks. As a challenge to myself, I decided to find a way to learn AngularJS as quickly and as properly as I possibly could. In the end, a project I could probably have completed in three days using jQuery and PHP ended up taking me all of two weeks to complete. Nevertheless, I am exceedingly proud of the fact that I was able to learn it quickly enough to actually build a web app that worked adequately well for the purposes of my project. The intent of this blog post is to share the resources that helped me quickly learn how to build a single-page web application with AngularJS.

I found angular-seed and decided to build my project on top of it. Angular-seed provides you with a skeleton for a typical AngularJS web app in addition to preconfigured testing and development tools such as Karma, Jasmine, Protractor and Bower.

I started out by working through two AngularJS tutorials. The idea behind choosing two tutorials was to ensure I got exposed to more than one style of using the AngularJS framework. After looking around for some tutorials on the web, I eventually settled on CodeSchool’s “Shaping Up With AngularJS” and the official AngularJS tutorial. I particularly enjoyed the CodeSchool tutorial and it did not take too long to complete.

In learning any new framework or library, I think it is very important to have a comprehensive awareness of pretty much everything the framework/library is capable of. In my opinion, the best way to do this is to read through the entirety of the framework’s official developer guide. I believe having this kind of general idea of a framework’s capabilities helps you avoid inadvertently reinventing the wheel and/or making bad style decisions while coding.

I set out to work on my project armed with the two aforementioned tutorials and a pretty solid awareness of what AngularJS could actually do for me. After days of gnashing my teeth and vehemently fighting off the temptation to use my beloved CodeIgniter/jQuery combination instead and be done with it, I eventually got my app working well enough.

Although I am still a rookie and there are tons more AngularJS tricks and techniques to learn, I consider the resources mentioned in this post to be pretty good starting points. If you do decide to go down the AngularJS path, remember many have cursed and wailed before you. No doubt, resilience is the key to learning AngularJS, and anything else really. :)

NB: is another really good tutorial that covers many fundamental aspects of AngularJS. You get to build a “GMail clone”. Doesn’t that sound exciting? :)

Some other really good resources:

Reading: Android Programming, The Big Nerd Ranch Guide

I am finally on the verge of “completing” my self-imposed native Android app development boot camp. Phew!!! In between a hectic class schedule, a thousand and one other things to learn and a general lack of discipline on my part, I have definitely spent way too long getting up to speed with Android.

Before now, I had always wanted to dive into native Android app development, but somehow never got around to it. My approach to learning new technologies usually starts with finding a good book. My idea of a good book is one that presents its material in tutorial-style such that you get to build actual things rather than simply get buried in a deluge of concepts, facts and descriptions. Having exhaustively leafed through almost 90% (912 of 1085 pages) of Android Programming: The Big Nerd Ranch Guide, I can quite confidently say it is a good book and I highly recommend it to anyone who intends to learn how to build native Android apps.

As part of your journey through the book, you get to build a number of small apps while tackling numerous “challenges” formulated by the authors. Some of the apps you will build are:

  • CriminalIntent – a crime reporting app (complete with camera and SMS integration).
  • RunTracker – An app that tracks your route when you go on a run (via GPS and Google Maps).
  • A quiz app.
  • A Flickr client.

I have a number of little Android projects lined up and I am particularly looking forward to a particularly “serious” one I have been mulling over for some time ;-). Hopefully, I get around to these things eventually.

On Political Systems…

I have always believed that civilizations need to come up with [unique], alternative political systems that work for and apply to their unique situations and social structure; alternative political systems based on sound observations and research, rather than dysfunctional systems that result from stubbornly trying to copy already-existing ones that are touted by others who have little to nothing in common with them.

I think this TED talk by venture capitalist and political scientist Eric Li is quite interesting and informative. What do you think?