Benchmark: subtring vs substr


After running benchmark for js substring vs substr I found the following results:

Substring:

(() => {
 let start = +Date.now();
 for (let i = 0; i < 1000000000; i++) {
	let val = "0.fr8gdqxstse".substring(2)
  }
 console.log(+Date.now() - start);
})();

This gave me run time of 21447ms

With end index:

(() => {
 let start = +Date.now();
 for (let i = 0; i < 1000000000; i++) {
	let val = "0.fr8gdqxstse".substring(2, 10)
  }
 console.log(+Date.now() - start);
})();

This ran for 21271ms

Substr:

(() => {
 let start = +Date.now();
 for (let i = 0; i < 1000000000; i++) {
	let val = "0.fr8gdqxstse".substr(2)
  }
 console.log(+Date.now() - start);
})();

This gave me run time of 25522ms

With size:

(() => {
 let start = +Date.now();
 for (let i = 0; i < 1000000000; i++) {
	let val = "0.fr8gdqxstse".substr(2, 8)
  }
 console.log(+Date.now() - start);
})();

Run time: 22510ms

After running several iterations, this was average result.

Conclusion:
substring runs faster.

I may have missed something. Please comment if you like.

Remove adblock detection script


Just read the article All Eyeballs on Reader Reaction as Ad-Blocking War Comes to India, tried both ToI and HT sites. Ad removal banner is easy to remove, just follow the steps below.

1. Install SafeScript for chrome or NoScript for firefox, whichever browser you are using.
2. Restart the browser and poof no adblock detection will work.

Edit:

Came across an addon for Firefox few days back. Indian News Anti Anti-AdBlock by Adblock Fan, nice work.Gemoji image for :thumbsup

Install Oxygen OS on OnePlus One


There are the steps to install Oxygen Os on OnePlus One:

Mac:

  1. Download OxygenOS HERE
  2. On your device, go into Settings -> About and find the Build Number and tap on it 7 times to enable developer settings. Press back and go into Developer Options and enable USB debugging
  3. From your computer, open a command prompt and type:adb reboot bootloader
  4. Unlock the device: fastboot oem unlock (You can skip this step if your phone’s bootloader is already unlocked)
  5. Download latest recovery image from HERE
  6. Run the following command: fastboot flash recovery twrp.img
  7. Reboot the phone by: fastboot reboot
  8. Unzip oxygenos_1.0.0.zip. In there, you will see a oxygenos_1.0.0.flashable.zip file. Copy oxygenos_1.0.0.flashable.zip to your phone. You can use Android File Transfer.
  9. Boot into recovery. You can do this on your OnePlus One by holding down both the volume down key and the power button.
  10. Once you are in the recovery interface, the first thing you want to do is a factory reset. Again, you will lose all your data so please make sure you have backed up everything before doing this.
  11. After the wipe, go to install and find oxygenos_1.0.0.flashable.zip. Confirm flash. This will flash OxygenOS onto your device.
  12. After the flash succeeds, you can reboot the device, which will take you to the new OxygenOS. Enjoy!

Never Settle.

Troubleshoot recovery install HERE
More info HERE

2013 in review


The WordPress.com stats helper monkeys prepared a 2013 annual report for this blog.

Here’s an excerpt:

A New York City subway train holds 1,200 people. This blog was viewed about 4,500 times in 2013. If it were a NYC subway train, it would take about 4 trips to carry that many people.

Click here to see the complete report.

Varanasi, India: “Beyond” Documentary


I have lived in the city from birth for 24 years. Now I live in another city for my job. I miss my Varanasi so much. But the following documentary has helped me relive my past years again. I loved and enjoyed the work so much. Thanks Joey.

Read the director’s experience here: http://www.joeyl.com/2012/12/varanasi-india-behind-the-scenes-documentary/

Adding crosshair in ExtGWT chart


If you want to add crosshair on hover over chart in ExtGWT just like the chart in http://www.highcharts.com/demo/spline-symbols use the following code:

// wire up all series to interact with their highlight behavior
LinkedSeriesHighlightHandler link = new LinkedSeriesHighlightHandler(chart);
series.addSeriesItemOverHandler(link);
series.addSeriesItemOutHandler(link);
series2.addSeriesItemOverHandler(link);
series2.addSeriesItemOutHandler(link);
series3.addSeriesItemOverHandler(link);
series3.addSeriesItemOutHandler(link);

BarSeries bar = new BarSeries();
bar.addSeriesItemOverHandler(link);
bar.addSeriesItemOutHandler(link);
//explicitly not binding to a numeric axis, so that we dont care what values we return as our max
bar.addYField(new ValueProvider() {
    @Override
    public String getPath() {
        return "max";
    }
    @Override
    public Number getValue(Data object) {
        return 100;
    }
    @Override
    public void setValue(Data object, Number value) {
    //no-op
    }
});
//don't actually let them be visible
bar.addColor(Color.NONE);
bar.setColumn(true);
bar.setHighlighting(true);
//not needed if you dont use legend
bar.setShownInLegend(false);
//no gaps between regions - you may want to play with this
bar.setGutter(0);

//add a custom series highlighter to show the crosshair through the bar - this really
//only makes sense with multiple other series
bar.setHighlighter(new SeriesHighlighter() {
     private Map oldCrosshairs = new HashMap();
     @Override
     public void unHighlight(Sprite sprite) {
        PathSprite crosshair = oldCrosshairs.remove(sprite);
        if (crosshair != null) {
          crosshair.remove();
        }
       System.out.println("removed, new size is " + oldCrosshairs.size());
     }

     @Override
     public void highlight(Sprite sprite) {
     //we're especially insistent on only one being visible at a time, aggressively 
     //punch out existing ones
     unHighlight(sprite);

     PathSprite crosshair = new PathSprite();
     RectangleSprite bar = (RectangleSprite) sprite;
     //move to the top of the bar, in the middle
     crosshair.addCommand(new MoveTo(bar.getX() + bar.getWidth()/2, bar.getY()));
     //draw down to the bottom
     crosshair.addCommand(new LineTo(bar.getX() + bar.getWidth()/2, bar.getY() + 
                          bar.getHeight()));

     crosshair.setStroke(RGB.BLACK);
     chart.addSprite(crosshair);
     crosshair.redraw();
     oldCrosshairs.put(sprite, crosshair);
     System.out.println("added, new size is   " + oldCrosshairs.size());
  }
});
//The above impl isn't accounting for animations, so we should either 
//disable those or add some animation code in the highlighter. Also 
//remove the animation button below
chart.setAnimated(false);

chart.addSeries(bar);

//disable all shadows to stop the bar from having shadows - a better fix
//would be to add a custom shadow renderer to the bar series that does 
//nothing. Also remove the shadow button below
chart.setShadowChart(false);

Install Sencha Touch 2 on Ubuntu 12.04


After trying a lot of tutorials, I finally got hold of one which worked like charm. Here is the link.

Install LAMP – Apache2, PHP5 and MySQL on Ubuntu 12.04 LTS


Install mysql:
sudo apt-get install mysql-server mysql-client

Install apache2:
sudo apt-get install apache2
To update home directory, modify the file /etc/apache2/sites-available/default

Install php5:
sudo apt-get install php5 libapache2-mod-php5 php5-mysql

For detailed version, refer this link

2011 in review


The WordPress.com stats helper monkeys prepared a 2011 annual report for this blog.

Here’s an excerpt:

A San Francisco cable car holds 60 people. This blog was viewed about 2,300 times in 2011. If it were a cable car, it would take about 38 trips to carry that many people.

Click here to see the complete report.

Create new mysql user with grant option


Login in mysql using:

$ mysql -u root -p

First create a database using:

mysql> create database dbname;
Query OK, 1 row affected (0.00 sec)

Then in mysql shell create new user using:


mysql> create user 'username'@'localhost' IDENTiFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on dbname.* to 'username'@'localhost' with grant option;
Query OK, 0 rows affected (0.00 sec)

Or you can use ‘%’ wildcard if you want to connect mysql from any host:

mysql> create user 'username'@'%' IDENTiFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on dbname.* to 'username'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)

For more details visit mysql manual.