Tuesday, November 3, 2015

David Beazley - Modules and Packages: Live and Let Die!

If you are Python developer don't miss this section from PyCon 2015 by David Beazly. This section is important for every python developer.
Why it's important? if you don't know about how python module, namespace and packaging in general manner you will die :-).
This section not talk about how to create package, but more general about what is package and module it self.
Good explanations by David, this section also compare which one that should and shouldn't do by developer.
for more information you can watch PyCon 2015 By David Beazley - Modules and Packages: Live and Let Die!

Monday, November 2, 2015

Android HTML5 App, how really it's?

In this post I just want to share HTML5 development, it's not using framework like apache cordova or something else. I just want to share how to communicate or interfacing between javascript and android java native code.

When I wrote this post, I use Android Studio Version 1.4.

For complete project you can download from this link  https://www.dropbox.com/s/02mor7925l1l3bg/MyApplication.zip?dl=0

Create new project with no activity using android studio

Tuesday, October 27, 2015

Python Access Java Through JNIus


Can python access java library or class?, yes it's possible. There are some project to do this, the popular one is PyJNIus and this project under Kyvi project https://github.com/kivy/pyjnius.

How it's work? PyJnius wrap java using JNI call so python can call it, don't worry if you don't know about it. Me to :-)

To install PyJNIus, we need to install
  1.  Java JDK installed (OpenJDK will do)
  2.  Python 3.4 (In this case I use 3.4 version)
  3.  Setup JAVA_HOME environment
  4.  Setup JRE_HOME environment

After install python, we need to install cython, use pip or easy install. In this case I use pip.
$ sudo pip install cython
After cython installed, then install PyJNIus through  php or easy install. In this case I use pip
$ sudo pip install PyJnius
After PyJnius installed then try import jnius from python, and let learn little thing about calling java from python.

On linux should be no problem when importing jnius,
Python 3.4.3 (default, Mar 10 2015, 14:53:35)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from jnius import autoclass
>>> 
But on OSX we sometime meet this error when import jnius
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/barry/anaconda/envs/ovation-testing/lib/python2.7/site-packages/ovation/__init__.py", line 8, in <module>
    from jnius import autoclass, cast, JavaException
  File "/Users/barry/anaconda/envs/ovation-testing/lib/python2.7/site-packages/jnius/__init__.py", line 12, in <module>
    from .jnius import *
ImportError: dlopen(/Users/barry/anaconda/envs/ovation-testing/lib/python2.7/site-packages/jnius/jnius.so, 2): Library not loaded: @rpath/libjvm.dylib
  Referenced from: /Users/barry/anaconda/envs/ovation-testing/lib/python2.7/site-packages/jnius/jnius.so
  Reason: image not found
If you found that problem, you need to add this to .profile in your home file, and add this line then restart your terminal then try again to import jnius.
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$(/usr/libexec/java_home)/jre/lib/server
now you can import jnius on python interpreter.

On windows, I have no luck to install PyJnius through pip or easy install using MinGW as compiler. But I still struggling with it :-(.

now let's test to access some java library
Python 3.4.3 (default, Mar 10 2015, 14:53:35)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import jnius
>>> from jnius import autoclass
>>> Stack = autoclass('java.util.Stack')
>>> stack = Stack()
>>> stack.push('hello')
'hello'
>>> stack.push('world')
'world'
>>> stack.pop()
'world'
>>> stack.pop()
'hello'
>>> System = autoclass('java.lang.System')
>>> System.out.println('Hello World')
Hello World
for more learning stuff you can refer to:
http://pyjnius.readthedocs.org/en/latest/
http://kivy.org/planet/2012/08/pyjnius-accessing-java-classes-from-python/

with this project, it's possible to develop android app using python. To create android package we can use http://python-for-android.readthedocs.org/en/latest/

Sunday, October 25, 2015

How to make android emulator run faster?

Android emulator running too slow? this is main problem when develop android application :-). I always trying to find other solution rather than using original google android emulator.

After do some googling and learn little about virtualization technology, I got little knowledge how to run android emulator using intel virtualization technology (VT) this feature must be activated through BIOS.

We need to access bios and activate intel virtualization technology, keep in mind that not all processor and motherboard support intel virtualization technology. But if intel virtualization technology exist in your bios setting you can use it to run android emulator using x86 image.

If your processor and motherboard support intel virtualization technology install haxm through android sdk manager


But if your computer doesn't support inter haxm don't worry just skip haxm installation step, then go to android sdk installation folder and goto extra/intel/Hardware_Accelerated_Execution_Manager then install using silent_install.bat must be using command prompt with administrator mode:
D:\SDK\android-sdk-windows\extras\intel\Hardware_Accelerated_Execution_Manager>silent_install.bat -m 512
-m parameter is memory will be used by haxm manager, don't use memory more than 1024MB, after installation succes you will get message in command prompt will return success message.

Next step install image x86 both, x86 image system and x86 google api image system.


Then setup your android virtual device (AVD), setup using one of x86 image system, don't forget to Use GPU Host


That's it, and let you got fast android emulation.

Tuesday, October 20, 2015

Python LinkedIn REST API Implementation

LinkedIn using OAuth Version 2.0 it's different process compare with OAuth Version 1.0. Newer version is more easy to implement we don't really need to create parameter with oauth_ prefix and generate signature on client side, for more information about oauth version 2.0 we can refer to official oauth page http://oauth.net/2/.

All request should use https protocol and redirect url must be accessible if not we can't get code for generate access token. The step is simple just 2 step only.

1. Generate grant access url, from here we will redirected to our redirect url and we will get code for authorization code
2. Generate access token using that code with POST method and we will get token access with specific time expired

We can use that token access to call API to provider. Token access will expired in specified time and we need to renew access token with both step.

You can grab pyLinkedinAPI from my github repository https://github.com/amru-rosyada/pyLinkedinAPI

Please if you use it, don't forget to give us feedback. Next project I will try to implement Facebook, G+, Instagram and Flickr as far as I have little time to make it :D