Ionic – get location permission on android 6

I have a pet project which is building a mobile app using ionic framework. It stopped working on my mobile after upgrading to android 6x. In android 6x, permission was moved from install-time to run-time. This means from now on, users are not granting permissions during installation of apps; rather they’ll be asked to grant permission when they want to use that particular feature in the app. It’s a great idea because if you don’t like to grant one specific permission to an app, you should still be able to use other functionalities.

So, after fixing the issue in my app, I thought it’s worth sharing with others as they may find it useful :). Fixing this issue is pretty simple and straightforward. So, let’s dive in!

Here is how my old codes look like (not exact version though, you got it :p ):

Now we can’t call LocationService.getCoords directly anymore because it’ll fail unless user already granted permission to this app to use location. So let’s ask user to grant permission.

First of all, we need to install a cordova plugin by running the following command in project directory:

cordova plugin add cordova-plugin-android-permissions --save

Then, we gonna write a method, askLocationPermission, for asking permission:

Finally, we can use it just before trying to get coords like:

Notes

  • I read somewhere this (can’t find the link) implementation is backward compatible, which makes sense because in older version of Android you’ll be already granted permission during installation (assuming you’ve mentioned locations permission correctly in your app’s manifest).
  • I’ve used promise in the new method. If you like, you can use callback pattern.
  • For list of available permissions, look at this doc.

ciao!

SparkPost – Control engagement tracking with ActionMailer

In a recent post, I’ve shown how to configure action mailer to send emails through SparkPost. Today, I have faced a situation where it was needed to enable/disable tracking on a specific email. It’s to be noted that, you can globally enable or disable engagement tracking in SMTP. However, if you want to enable tracking (when globally disabled) or disabled tracking (when globally enabled) for a specific email, keep reading.

 

I assume, you’ve created separate mailer for each type of emails (or for at least the mails you want different tracking behavior for). Follow official doc if you’re not sure what that means or how to do it. Now, let’s configure a mailer to enable engagement tracking. For that I’ve created a HelloMailer.

 

In the above snippet, we’ve configured welcome email of HelloMailer, hello_mailer.rb, to enable engagement tracking. So links in your template will be automatically converted to trackable links.

Notes:

  • If email is HTML (text/html), only links will be converted to a tracking URL. It’ll not convert any URLs (because you can use it for, like, anchor text and it won’t make sense to convert)
  • If email is text (text/plain), all URLs in the email will be converted to a tracking URL.
    (See the template, hello.html.erb, to see which URLs will be converted)

If you want to disable engagement tracking in an email, just set the values to false.

headers 'X-MSYS-API': { "options": { "open_tracking": false, "click_tracking": false } }.to_json

It’s that simple :).

WordPress debugging in phpStorm

While working with WordPress after a while, the first problem I encountered is that I can’t debug it easily as I could do it directly from PyCharm (for python/django), RubyMine (for ruby/rails). So, I wanted to figure out how to do it in phpStorm for WordPress. I found it is quite easy to get it done with a few easy to follow steps.

phpStorm 8 (currently available in EAP) has support for WordPress development. Follow the official doc to configure phpStorm for WordPress.

Enable Remote Debugging using xdebug

Check the official document on how to install xdebug extension for PHP and enable it. Once the extension is installed, you need to enable it and also enable remote debugging.

[xdebug]
zend_extension="/Applications/MAMP/bin/php/php5.5.10/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"
xdebug.remote_enable=1

The above is my configuration. However, you may need to change the path of xdebug.so based on your extensions path.

Once installed, restart your web server. To make sure xdebug is activated, run

php -v

This should output something like:

$ php -v
PHP 5.5.10 (cli) (built: Apr 10 2014 17:49:22)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Xdebug v2.2.4, Copyright (c) 2002-2014, by Derick Rethans

Notice that Xdebug 2.2.4 is activated. You can also see this using phpinfo().

Configuring phpStorm

As we’ve installed Xdebug, let’s link it with phpStorm. Open phpStorm’s preference and

Screenshot 2014-08-07 21.08.55

Select version from PHP language level and interpreter where you’ve just configured the xdebug. If it’s not listed, click on the Screenshot 2014-08-07 23.01.03 button.

Screenshot 2014-08-07 21.09.54

Give your interpreter a name. For PHP home, click the Screenshot 2014-08-07 23.01.03 button next to the field and locate your php interpreter. If you don’t know where it is go to your shell and run the following command to get the location.


which php

It should detect that Xdebug is installed in this interpreter. Press Ok buttons.

Now, you need to tell phpStorm to listen for the Debug connections. In the toolbar, you will notice the button shown in the following screenshot. Click there and phpStorm will start listening for debugger connections.

Screenshot 2014-08-07 21.11.45

Triggering the debugger

We’re in the last part of our configuration. Everything is done except triggering the xdebug. There are several ways of triggering the debugger. Easiest way is probably using browser extensions. Install extension for your browser as listed below. I will show for Chrome.

Firefox

Chrome

Safari

Opera

After installing the extension, you’ll notice a new button at the right side of your address bar.

Screenshot 2014-08-07 23.07.44

Click on it and choose Debug option.

That’s all*. Now set a breakpoint in your IDE and the execution will be paused there when you refresh your page.

Screenshot 2014-08-07 23.12.23

You can now step into different levels, evaluate expressions on current context, see all scope variables and so on. Your WordPress development will never be painful like earlier. Follow this link to learn more about debug toolbar.

Screenshot 2014-08-07 23.14.34 * First time, you will receive a prompt in your IDE to accept the incoming connection.

 

Rooting Samsung Galaxy Pop (Mini) on Mac OSx and enabling Bangla (Bengali) support

Introduction
(you can skip this part if you are in hurry)

I was planning to root my galaxy pop for a quite long time. But it was delayed as I found all tutorials applicable for Windows. That means, I need a windows machine to root my device but I don’t have any working windows machine.

Yesterday, I planned to upgrade to Gingerbread from Froyo as some of the friends suggested claiming it improves the battery performance (honestly, so far after upgrade, I believe it really does). I read some tutorials and this also requires windows machine. So, I borrowed my brother’s laptop. After about 10 hours of efforts, I could successfully upgrade the ROM.

So, this morning, I planned to root the device and in office I tried SuperOneClick.exe with colleague’s windows machine but failed. Then I was searching Google to do so on my Mac OSx. After several tries, I could do it. Continue reading →

Get free SMS alert on your server down (or something else)!

Well, first thing first. This blog may be little bit immoral even if it is not illegal by the provider terms of service. So, if you read this or later sentences, the responsibilities are on you.

—————-

I am going to share an idea that I’ve personally used a bit ago (2009) in my previous office to monitor the server and get notified when any server/service is down. I wrote a small PHP application that would do the tasks. Though I planned that time to blog about it, apparently, I forgot about it. The steps of the idea is:

  • A php chunk checks server status
  • If it finds something unexpected (or may be expected; depends on your logic :)) it creates an event in your google calendar which is due just 1-3 minutes from now
  • If your SMS alert is setup in Google Calender, Google will email you about the event.

Here I will not show how to write a PHP script to monitor server. I just told it as I applied this idea for same purpose. I guess you will get lots if you google it. However, the initial version that I developed just checked site’s homepage (using CURL) and if they were returning 200 response within a sensible time limit. If the response was not 200, it would create the event for me.

How to create Event?

It’s very simple. First of all download the following classes from phpclasses.org

Put them in your project path. Create a php file. Lets assume it is createevent.php. Now include the wrapper file in createevent.php.

Continue reading →

Line wrapping is finally available in Netbeans 7.0

Well, if you ask me why I left Netbeans and started using phpStorm; I will say first: Speed, second: Line wrapping along with few other reasons. I’ve used Netbeans for quite sometime but I was very irritated as it did not have good line wrapping support. Some users may wonder why I am saying ‘good’ as it did not have any line wrapping at all.

The fact is that, line wrapping was implemented in earlier versions too but was not enabled by default as it was not stable.  It can be enabled by editing a configuration file but it was causing lots of troubles while coding. However, as the latest version, v7.0, is released on 18th April 2011, line wrapping is now available without any such hacking and so far it is good to me.

How to enable Line Wrapping?

Go to Netbeans  -> Preferences (or press CMD + ,) -> Editor -> Formatting

You will notice a drop down labeled as ‘Line Wrap’. Choose ‘After Words’ or ‘Anywhere’ as per your wish and then hit OK.

That’s it. Simply open a file (opened files need re-opening) and you will not see horizontal scroll-bars :).

Netbeans Linewrapping

Netbeans Linewrapping

Auto updating (svn up) working copy on commit

I am working on a project that can’t be tested locally. So, I need to upload files to server. However, committing and then uploading is rigorous job (as there are lots of files to upload as a directory while changes were made only a few files under different directory. so browsing directory and uploading specific file(s) also annoying.) ! That’s why I used ‘svn up’ command to update all changed files from svn repository.

Continue reading →

Setting Linux as default in rEFIt boot loader

After successfully installing Ubuntu Lucid Lynx on Macbook, I am mostly using it. I only switch to Mac OS to watch movie using the remote control which yet to work on Ubuntu.

However, problem is that Mac OS was default on the rEFIt boot loader. I wanted to make Linux default. After searching the different configuration files, I found what to do.

Boot to Mac OS

Continue reading →

Read/Write on Mac OSx partition from Ubuntu

After dual booting with Ubuntu and Mac OS, I could not write on Mac OS partition. However, I must have to find a way to do that as I will move certain things to ext3 partitions to be seamlessly usable by Ubuntu.

While reading online, somewhere I have read that I will need to disable journaling in Mac OS partition to mount it on Ubuntu with writing permission. I wanted to do the same but I saw the Enable/Disable Journaling button is not enabled in Disk Utility. So, after searching I found a command to do that from command line. It is simple.

# diskutil disableJournal /Volumes/Macintosh HD

That’s it. It disabled journaling on that partition. Later on Ubuntu I mounted the drive and I could write on it.

More Info:

Mounting the partition on Ubuntu

sudo mount -t hfsplus /dev/sda2 /media/mac

Using prosperent.com API with PHP!


Currently I am working with Prosperent.com’s affiliate network and making an auto blog plugin for wordpress. The plugin is intended to fetch products from prosperent and create wordpress posts. You will earn commission from the sales through your affiliate link! The affiliate links will also be given by prosperent. So, you don’t need to think about it. You just need to requests their API with the API Key and they will mask the product URL with your affiliate ID so the impressions and clicks are accounted under your affiliate account.

Prosperent already provides a simple and beautiful PHP class that makes enjoyable while working with their API. You just need to write a few lines to get products from them.

Continue reading →