Interchangeable Functions and Methods in Go

When you declare a method on a struct, you would typically write something like this.

However, did you know that there are 2 ways to invoke say() ?

Receiver methods also have the function signature func(*Cool, string) and can be used interchangeably with any function pointers of the same signature.

 

Proxy Android device network over USB

Are you frustrated by changing your test device’s proxy host name whenever your device is assigned a new IP address? Say you plan to work at 5 different coffee shops today, did you know that there is a way to set the proxy host name once, and the device will be able to proxy network at all 5 coffee shops with just a USB cable?

Here is what you will need to do

  • Connect your Android device to your computer with a USB cable
  • Open your computer’s terminal and run $ adb reverse tcp:8888 tcp:8888 
  • Set the device’s “Proxy Host Name” to localhost  and “Proxy Port” to 8888

Voila, your device is now sending its network packets to your computer! You should now see logs for both Charles Proxy and Fiddler.

What’s New in Android Studio 2.0 Preview

Christmas came early this year to Android developers around the globe. The Android Developer Summit blew everyone away with amazing new tools, optimizations, and so much more. Google sure ain’t kidding around when they drop a major version increment!

New dexInProcess Flag

There is now a new build flag called android.dexOptions.dexInProcess available in Android Studio 2.0. However, due to its experimental nature, it is not yet enabled by default. Michael Bendowski says it will make a huge difference! But he wants you to let him know if it works for you. (As opposed to the contrary, letting him know if it doesn’t work for you… I kid! I kid! I believe in Michael!)

You can enable the experimental flag by adding this to your build.gradle file.

New Resource Shrinker

When your debug builds go over the infamous 65k method count limit, you can ask Proguard to shrink compilation resources. However, Proguard is non-incremental and disables pre-dexing, meaning it will make your build time as fast as a snail. Every. Single. Debug. Build. The tools team addresses this problem by creating a new shrinker that is dex-friendly. It aims to be both incremental and supports pre-dexing; as a stretch goal, it hopes to improve multi-dex times when targeting pre-L devices.

You can enable the experimental shrinker by adding this to your build.gradle file.

Continue reading

Announcing Permission Nanny 0.1.1

Permission Nanny 0.1.1 is officially out! By the time you read this, the app and the SDK should be available on the Google Play Store and Bintray respectively.

What’s New in Permission Nanny 0.1.1

With a faster database engine and two important features, this release increments increments one minor version.

Don’t Ask Again

This release implements the “Don’t Ask Again” feature in Marshmallow; users can now ask Permission Nanny to always accept or deny permission requests directly from the dialog by checking the “Remember my preference” check box.

permission nanny 0.1.1

Deep Links

In addition, Permission Nanny now expose deep link endpoints; developers can now directly deep link into Permission Nanny. This can be useful when a user has denied a crucial permission to an app and would like to guide the user to Permission Nanny to revert his/her choice.

What’s Next

So last time I said the next release would be about documentation and tests, unfortunately I had to postpone that until the next release. Look, I even made a milestone to track that!

Dissecting Plaid – Mighty Morphin Search Icon

Nick Butcher, an Android Developer Advocate at Google recently released a Material Design reference application called Plaid on GitHub. It’s a beautiful gallery app that displays content from Designer News, Dribbble and Product Hunt. After getting Plaid to run on my emulator, the slick transition animation from Home to Search caught my attention.

That morph animation from Search to Back and vice versa! That full screen ripple emanating from Search! That circular reveal exit at the end! I just had to know how they were implemented! Let’s dissect the source code to find out, starting with the Mighty Morphin Search Icon.

Continue reading

Let’s Watch – Android for Java Developers (Big Android BBQ 2015)

Chet Hasse’s portrait is like the Wagyu A5 Seal of Approval; no matter blogs, podcasts, or videos, any media with him in it is guaranteed to be informative and rich in knowledge. This talk is no exception, Chet covers many performance related topics in this video, but he not only gives out dos & don’ts, but also answers why we should adopt the aforementioned practices with insightful commentary on how the Android operating system works internally, shedding light on the mystery machine.

Continue reading

Announcing Permission Nanny 0.0.6

Permission Nanny 0.0.6 is officially out! By the time you read this, the app and the SDK should be available on the Google Play Store and Bintray respectively.

What’s New in 0.0.6

This release marks a significant milestone. Permission Nanny now supports all the APIs in LocationManager through LocationRequests; in addition, it also adds support for all the APIs in AccountManager through AccountRequests. This means that other than CAMERA, RECORD_AUDIO, READ_CALL_LOG, WRITE_CALL_LOG, ADD_VOICEMAIL, USE_SIP, PROCESS_OUTGOING_CALLS and BODY_SENSORS, all other permissions considered dangerous in Marshmallow 6.0 are now implemented and supported in Permission Nanny, allowing developers to add Runtime Permissions features to their own apps in versions prior to Marshmallow 6.0!

What’s Next

Permission Nanny is still not 1.0 software. Moving forward, I am going to add more support for the few remaining dangerous permissions. After that I’m going to focus on complete Javadoc for all public classes. Finally, I will tackle testing and stability.

Creating Reusable Test Resources

Beginning with Android Gradle plugin version 1.1, developers can now write unit tests that run on the JVM in addition to the existing test framework that requires an emulator to execute. Running tests on the JVM is blazing fast compared to emulators; however, JVM tests interface with a mocked version of the Android operating system instead of a real one, so components such as databases and network cannot be fully tested with JVM tests. Hence developers often find themselves writing both sets of tests – JVM tests and Android tests.

When I’m writing tests for an application module, I often find myself duplicating the exact same set of test classes such as mocks or helpers for both Android and JVM tests. Suppose I have an Android test utility class which contains static helper methods that set up mocks’ expectations using when(mock.doSomething()).thenReturn(expectation) . However, these utilities cannot be accessed anywhere from JVM tests because their class paths are completely different –  /test vs  /androidTest. You could put these test resources in  /main  with your app code, but it is bad practice to mix test code with app code. Wouldn’t it be great if there were a location developers could place test resources that could be shared by both tests? Continue reading

Permission Nanny, app that ports Android M’s Runtime Permissions back to Gingerbread

After a good three and a half months, my permission management app – Permission Nanny – is officially on the Play Store. The process was very tiring, with lots of late-night coding, but I’m pretty proud of myself to be able to release an Android app in such a short amount of time! It’s completely open source too!

Check out the app on the Google Play!

Read the source on Github!

Nginx Configuration for WordPress

This article is about editing Nginx’s sites-enabled configuration to deploy a WordPress blog in a subdirectory.

Let’s say you decided to install WordPress in its own subdirectory.

The starting point for WordPress is /wordpress/index.php. We need to modify the default server block to direct requests to that location for processing. Luckily, DigitalOcean provided a detailed guide on how to install a LEMP server on Ubuntu. Based off their work, I made a few modifications to their configuration.

Continue reading