Saturday, June 4, 2016

JS Series: Node.js vs. Java Simple Speed Test

This evening after working through a few asynchronous and synchronous methods in node.js to process huge files I thought I would write the same simple math routine in JavaScript/node.js and again in Java. I have been impressed so far with the performance of node and my JS code. The fact that I am getting the speed I do and I get it with a save then run without compile has me convinced JS is a contender for my next time sensitive project.


var start = new Date();
var n = 1;
for (var i = 1 ; i <= 100000000 ; i++) {
    n = n + i;
var end = new Date();
var tm = end.getTime() - start.getTime();


import java.util.Date;
class Summer {
    public static void main(String[] args) {
        Date startDate = new Date();
        long n = 1;
        for (long i = 1 ; i <= 100000000 ; i++) {
            n = n + i;
        Date endDate = new Date();
        long tm = endDate.getTime() - startDate.getTime();
        System.out.println("tm->" + tm + "milliseconds");


Minus the boilerplate class stuff in Java each of these are exactly 8 lines of code. So how did they do?

Davids-MacBook-Air:numbers dbell$ java Summer
Davids-MacBook-Air:numbers dbell$ node summer.js


The difference isn't drastic for such a simple example but Java runs in 1/3 the time and is our winner!


Friday, June 3, 2016

JS Series: iTunes Connect Test Flight External Users Notify CSV Generator Using Node.js

In this post I want to share a script that I wrote to parse through the iTunes Connect Test Flight external user test to determine which users have been notified of my new app build but who have not installed. The goal is to gather up the list of those users and re-create a new comma separated file for upload. This will cause all those users to be re-notified and will hopefully lead to more downloads of test builds.

Note: This script requires you install node.js to work.

Step 1: Get users into a users.txt file.
Log into iTunes connect,  click on my apps, click on your app name, visit the test flight section, click on external testers. Highlight and copy/paste the list of users into a new text file called users.txt and place into a directory. The file should look similar to this screenshot below.

Step 2: In the same directory as this users.txt file copy and paste the following javascript file.

var fs = require('fs');
var lineReader = require('readline').createInterface({
    input: require('fs').createReadStream('users.txt')

var date = new Date();
var day = date.getDate();
var monthIndex = date.getMonth();
var year = date.getFullYear();

var csvFile = 'notify_' + monthIndex + day + year + '.csv';
console.log('csvFile:' + csvFile);

fs.closeSync(fs.openSync(csvFile, 'w'));

var cnt = 0;
var fName = '';
var lName = '';
var email = '';
var notified = false;

lineReader.on('line', function (line) {
    if (line != '') {
        line = line.replace(',', '');
        switch (cnt) {
        case 0:
            email = line;
        case 1:
            var names = line.split(' ');
            fName = names[0];
            lName = names[1];
        case 2:
            if (line === 'Notified') {
                notified = true;
        cnt = cnt + 1;
    } else {
        if (notified) {
            var lne = fName + ',' + lName + ',' + email + '\n';
            fs.appendFile(csvFile, lne, function (err) {
                if (err !== null) {
                    console.log('err:' + err);
        cnt = 0;
        fName = '';
        lName = '';
        email = '';
        notified = false;

Step 3: Run Script
Open up a terminal and go into the directory where the user.txt and the above script are found. (I called mine ReadFile.js).

Davids-MacBook-Air:itunes dbell$ node ReadFile.js 

When you run the file it should produce a new notify csv file. View the file (I used cat) and you should see only those users listed who need to be notified again. 

Davids-MacBook-Air:itunes dbell$ cat notify_532016.csv 


Step 4: iTunes CSV Load
Go back into iTunes connect now where you copied out your users. Edit and remove each user manually who had only notified next to their name. You can use this new notify csv as a reference for who to remove. Then after they are removed use the add functionality to upload a csv file. Select  your new csv file and then click on save.

In my next Javascript post I will use the same users.txt file to determine how many users have installed and what build and how many are only notified as a means to provide a statistic for your app.