Wednesday, May 20, 2015

GitHub: Getting the download count for your releases

Do you own a GitHub repository? Did you ever wonder how many people downloaded your releases? Apparently there's an API for that!

For example, you can get the metadata of your latest release by making a GET request:<username>/<repo_name>/releases/latest

It returns a json payload, which has a download_count for each asset.

Getting the download count for your releases - User Documentation
Releases | GitHub API

Thursday, May 14, 2015

Android: unable to uninstall application

A friend of mine wanted to uninstall an app from his Android phone. But for some reasons, the "Uninstall" option is disabled. I tried running adb uninstall <package_name>, but it failed to uninstall.

Checking logcat, there was a warning:
W/PackageManager: Not removing package has active device admin

Basically, this app has device admin features enabled, meaning it can erase your phone's data if you lost your phone for example. So we need to first go into Settings > Location and Security > Device Administrator, and disable the app before we can uninstall it.

uninstall - How to remove an app with active device admin enabled on Android? - Stack Overflow

Monday, May 4, 2015

IE: Issue with Compatibility View settings in Internet Explorer 11

I wrote a Web app using AngularJS for an intranet site. Everything works fine, except a few users reported that they were seeing a blank screen. They confirmed that they were running the latest version of IE 11. But when I check it on mine, the page shows up properly.

It turns out those users have one thing in common: under Tools > Compatibility View settings, the "Display intranet sites in Compatibility View" option was checked. The simplest solution is to ask the user to uncheck that option, which is not ideal.

A better solution is to use a meta tag to instruct IE to always use the latest standards rendering mode:
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

It would prevent IE from rendering the page with an older rendering engine. And now my Web app displays correctly regardless of the Compatibility View settings.

Understanding Compatibility Modes in Internet Explorer 8 - We know IE! - Site Home - MSDN Blogs
Fix site display problems with Compatibility View - Windows Help

Wednesday, April 22, 2015

AWS EC2: Install Node.js on an Amazon Linux AMI instance

I wanted to install Node.js on my Amazon Linux EC2 instance. Unlike Ubuntu, I can't just apt-get install nodejs.

The solution appears to be very simple. I just need to enable the EPEL (Extra Packages for Enterprise Linux) repository to get yum install to work.

1. Edit the repository config file
  sudo nano /etc/yum.repos.d/epel.repo

2. In the [epel] section, change the enabled flag to 1

3. Press Ctrl+O to save the file, and then Ctrl+X to exit

4. Update yum
  sudo yum update

5. Install npm and Node.js
  sudo yum install npm

6. Verify Node.js is installed
  node -v

How to install node.js on AWS AMI Linux instance | SpiderSoft

Tuesday, April 14, 2015

Java: Send email through Gmail's SMTP server

There are various examples of using the JavaMail API for sending emails, e.g.
I was able to get my program up and running relatively quick. However, the code stopped working once I deployed it to my AWS EC2 instance. It threw an javax.mail.AuthenticationFailedException, and links to

Following the link above, I was able to resolve the issue by enabling allow less secure apps and allow access from a new location or device.

Monday, April 6, 2015

AngularJS: issue with progressbar on IE 11

AngularJS v1.3.14
UI Bootstrap 0.12.1

I used AngularJS UI Bootstrap to display a progress bar in my Web app. It works fine in Firefox and Chrome. But on IE 11, the progress is not getting updated. The weird part is that, if I enable the developer tools in IE, then the progress bar works as expected.

A quick search led me to this article which describe the exact same issue, but for IE 10. It was reported back in 2013, and it has been fixed in a newer version of UI Bootstrap. Then I checked the Internet Explorer Compatibility but I didn't find anything relevant. The progress bar demo on UI Bootstrap site is working fine as well.

My next thought was that, perhaps I should detect and add special handling just for IE 11 until I have more time to investigate the root cause. So I started to look for ways to detect IE 11, and the most common practice seems to be using conditional comments. Unfortunately, it does not work with IE 11. It turns out conditional comments are no longer supported since IE 10.

While I was struggling with IE, I noticed something weird. The way my Web app works is that, it polls a .json file through $http.get() to update the progress every 250ms. But looking at the server logs, only 1 GET request was made, which explains why the progress is not getting updated. It suggested that IE is being "smart" and caching the .json response. Searching online, it looks like other people ran into the same issue as well.

In my case, I used Node.js to run the server. I was able to resolve the issue by setting the following headers in my json response:
response.writeHead(200, {"Content-Type": "application/json",
                                     "Cache-Control": "no-cache, no-store, must-revalidate",
                                     "Pragma": "no-cache",
                                     "Expires": 0});

Monday, March 30, 2015

Java: Getting console output of an executable .jar file on Windows

I added a few System.out.println() statements in my executable .jar for logging purposes. It works fine in Eclipse. But when I run it through cmd, I noticed there's no console output at all.

What's happening?
By default, .jar files are handled by javaw.exe instead of java.exe on Windows.

"The javaw command is identical to java, except that with javaw there is no associated console window. Use javaw when you do not want a command prompt window to appear. The javaw launcher will, however, display a dialog box with error information if a launch fails."

So this is by design.

If you want to get the console output, there are 2 options.

#1. Manually call java.exe to execute your .jar file, e.g.
java -jar <your_jar_file_path>

- or -

#2. Change the .jar file association from javaw.exe to java.exe
a) Open regedit
b) Navigate to HKEY_CLASSES_ROOT\jarfile\shell\open\command
c) Change the path from javaw.exe to java.exe