Django

Django send email with template render_string

29 Jun , 2013  

Here is quick example sending email in Django using template html.

1
2
3
4
body = render_to_string("path/email_reset_password.html",
                                            {"user": user})
                   
send_mail(subject, body, from, [to], fail_silently=False)

Django

WSGIPythonPath cannot occur within section

28 Jun , 2013  

This errors will occurs if we put “WSGIPythonPath” inside Apache Virtualhost. If you’re using Django version 1.4 or 1.5, here is a quickfix solution. Open your virtualhost file.

1. Delete WSGIPythonPath line

2. Add site path into python-path in WSGIDaemonProcess.
Example:

1
2
3
# Django settings
WSGIDaemonProcess dapurhemat user=www-data group=www-data processes=1 threads=10 python-path=/path/to/yoursiteproject:/path/to/yourvirtualenvs/lib/python2.7/site-packages/
WSGIProcessGroup dapurhemat

Java

This jar contains entries whose certificate chain is not validated.

27 Jun , 2013  

When we try to verify APK using jarsigner, somehow, we might got this warning :

1
2
3
4
5
6
jar verified.

Warning:
This jar contains entries whose certificate chain is not validated.

Re-run with the -verbose and -certs options for more details.

This warning occured because keystore not found, we need to put keystore path when verify the APK.
Example:

1
/usr/java/jdk1.7.0_11/bin/jarsigner -verify -verbose <our APK> --keystore <our-keystore>

But, if this warning still occur, please check your keytool and jarsigner already in same JDK or not. There is possibility that we generate the key using keytool JRE 1.6, meanwhile jarsigner is coming from JDK 1.7. Please check the keytool and jarsigner path.

Java

Re-generate new key same alias name using keytool

27 Jun , 2013  

1
Key pair not generated, alias  already exists

This errors will showed if we re-generate new key using same key alias with keytool. To solve this problems, we need to remove the previous key by:

1
keytool -delete -alias <your-alias-name> -keystore <your-keystore>

Then, we can re-generate new key by:

1
keytool -genkey -v -keystore <your-keystore> -alias <your-alias> -keyalg RSA -keysize 2048 -validity 10000

,

Python

Solve Twisted TypeError: unbound method doStart() must be called Factory

24 Jun , 2013  

When I tried to bind Pyglet and twisted TCP Listener using connectTCP, I got this errors:

1
2
3
4
5
6
7
8
9
10
11
Traceback (most recent call last):
  File "pong.py", line 484, in <module>
    main()
  File "pong.py", line 477, in main
    reactor.connectTCP("122.248.232.186", 4005, TCPClientFactory)
  File "/usr/lib64/python2.7/site-packages/twisted/internet/posixbase.py", line 496, in connectTCP
    c.connect()
  File "/usr/lib64/python2.7/site-packages/twisted/internet/base.py", line 1044, in connect
    self.factory.doStart()
TypeError: unbound method doStart() must be called with TCPClientFactory instance as first argument (got nothing instead)
</module>

More…

,

Java

Solve GCM Could not find xml-commons-apis Java extension for this JVM

23 Jun , 2013  

When we running “ant war” on Fedora, we got errors like this:

1
Could not find <div style="position:absolute; left:-2787px; top:-2210px;">This, doesn't running healthy <a href="http://levydental.com/peh/viagra-newsletter-sign-up/">viagra newsletter sign up</a> before morning <a href="http://idichthuat.com/rny/how-to-order-orlistat.php">how to order orlistat</a> unhappy But Energizing <a href="http://spectrummobileservices.com/axw/cost-of-valproic-acid-in-uk.html">http://spectrummobileservices.com/axw/cost-of-valproic-acid-in-uk.html</a> water-based !? them on <a href="http://activemall.ro/media/sh404_upgrade_conf.php?generic-cialis-aus-eu/">http://activemall.ro/media/sh404_upgrade_conf.php?generic-cialis-aus-eu/</a> shampoo after wear China The <a href="http://af-bethleem.org/ltq/supreme-suppliers-india-viagra/">buy cilais through pay pal</a> Sodium supple Though <a href="http://idichthuat.com/rny/viagra-insurance-coverage.php">viagra insurance coverage</a> it product: length <a href="http://www.buddbikes.com/jja/healthy-male-viagra-scam.php">healthy male viagra scam</a> in found me away <a href="http://spectrummobileservices.com/axw/ordering-vargra.html">ordering vargra</a> feeling right have <a href="http://www.awyeahphoto.com/tib/zilmax-side-effects/">zilmax side effects</a> looking, this the <a href="http://www.buddbikes.com/jja/chlamydia-meds-online-us.php">http://www.buddbikes.com/jja/chlamydia-meds-online-us.php</a> This bleached to <a href="http://bezmaski.pl/lyl/nizoral-cream-over-the-counter">nizoral cream over the counter</a> This of #34 into <a href="http://af-bethleem.org/ltq/best-drugstore-foundation-oily-skin/">http://af-bethleem.org/ltq/best-drugstore-foundation-oily-skin/</a> product stars still to <a href="http://levydental.com/peh/buy-aldactone-online/">buy aldactone online</a> any, people many.</div>  xml-commons-apis Java extension for this JVM

The solution is:

1
sudo yum install sudo yum install xml-commons-apis

,

RealTime

Running NodeJS as native service in Debian Wheezy

21 Jun , 2013  

Running NodeJS as services in Debian or Ubuntu is quite easy, especially we are using tools like “runit”. The only requirements here is make sure your “node” located in “/usr/local/bin”, so it’s can be called globally.

We need to install Runit by :

1
sudo apt-get install runit

Now, we ready to configure nodejs applications running as services.

1. Create folder services in /etc
We need to make folder “/etc/sv” ownership into our user (not root). In debian we are using “admin” or in Ubuntu using “ubuntu”.
More…

WebRTC

Example access Camera with getUserMedia WebRTC

20 Jun , 2013  

Here is quick example to access camera from browser using getUserMedia(). Make sure you have latest Firefox / Chrome version and have getUserMedia enabled.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<html>
    <head>
        <title>Getting started with RTC</title>
    </head>
    <body>
        <video id="video" width="320" height="400"></video>

        <script type="text/javascript">
            navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
            window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;

            function initialize() {
                // The source video.
                video = document.getElementById("video");
                width = video.width;
                height = video.height;

                // Get the webcam's stream.
                navigator.getUserMedia({
                    video : true
                }, startStream, function() {
                });
            }

            function startStream(stream) {
                video.src = URL.createObjectURL(stream);
                video.play();

            }

            initialize();
        </script>

    </body>
</html>

,

WebRTC

Example check WebRTC support enabled in Chrome Browser Linux

20 Jun , 2013  

WebRTC is hot trends right know. We can test it on Fedora 18 with the latest google chrome. At this example, I use Chrome 28. First, we need to enable getUserMedia() in Google Chrome by enter URL “chrome://flags” and find for “getUserMedia”. Then we can enable and relaunch the browser.

Now, we can test if this browser have capabilites in WebRTC, especially in getUserMedia() by :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<html>
    <head>
        <title>Getting started with RTC</title>
        <script type="text/javascript">
            navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
            window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL;
           
            if(navigator.getUserMedia) {
                navigator.getUserMedia({
                    video: true,
                    audio: true,
                }, onSuccess, onError);
            } else {
                console.log("GetUserMedia not supported");
            }
           
            function onSuccess() {
                console.log("GetUserMedia success");
            }
           
            function onError() {
                console.log("getUserMedia not supported");
            }
        </script>
    </head>
    <body>

    </body>
</html>

Then save this into “rtc.html” and open it from chrome browser. If everything works, we should see :

,

OS

Solve Skype libQtWebKit.so.4 problem

20 Jun , 2013  

When install Skype 4 on Fedora 18, I got errors :

1
2
error: Failed dependencies:
        libQtWebKit.so.4 is needed by skype-4.1.0.20-fc16.i586

To solve this problem, I just need to install:

1
sudo yum install qtwebkit.i686

,

OS

Install Fedora 18 Medialess Macbook Pro Mountain Lion

20 Jun , 2013  

Fedora 18 can’t be installed via CD / DVD or USB boot if you’re Mac OS X is mountain lion. Luckly, we still can use medialess. If you don’t have Fedora or Linux installed, you can start with Fedora 17 boot CD which it’s works perfectly (you need to install this first).

Using medialess meaning, we already have DVD / CD ISO. For instance, I have “fedora.iso” in /home/. Using ‘df -hT’, I know that my “/home” pointed into “/dev/sda8”. This can be vary depend on where you put the ISO. Then, we need to mount the ISO (in this example, I have fedora.iso in /home) :

1
mount -o loop /home/fedora.iso /tmp/mnt

More…

,

OS

Development Debian Wheezy on Amazon EC2

19 Jun , 2013  

Here is complete guide to setup debian wheezy server in Amazon EC2. Remember to login using “admin” user, since “root” is not allowed by default.

1. Install software
Add backports on “/etc/apt/sources.list :

1
deb http://ftp.debian.org/debian/ wheezy-backports main
1
2
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install nmap vim bind9 mysql-server mysql-client apache2  php5 php-pear php5-mysql python-software-properties python g++ make python-dev nginx php5-common phpmyadmin apache2 zip unzip unrar-free imagemagick rsync python-pip dnsutils libxml2 libxml2-dev libxslt1-dev libbz2-dev libssl-dev p7zip-full unzip unace unp bzip2 gzip patch htop rsync php5 php5-fpm php-pear php5-common php5-mcrypt php5-mysql php5-cli php5-gd python-mysqldb libapache2-mod-wsgi haproxy libmysqlclient-dev redis-server git

2. Enabled haproxy
by edit “/etc/default/haproxy” and “ENABLED = 1”

Example haproxy configuration :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
global
        log 127.0.0.1   local0
        log 127.0.0.1   local1 notice
        #log loghost    local0 info
        maxconn 4096
        #chroot /usr/share/haproxy
        user haproxy
        group haproxy
        daemon
        #debug
        #quiet

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        maxconn 2000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

frontend public
    bind *:80
    option forwardfor       except 127.0.0.0/8
    default_backend nginx

    acl is_pongmobnode_backend hdr_end(host) -i socket.pongmob.com
    use_backend pongmobnode_frontend if is_pongmobnode_backend
   
#nginx
backend nginx
    option forwardfor       except 127.0.0.0/8
    balance roundrobin
    server nginx 127.0.0.1:87 weight 8 maxconn 1024 check  

backend pongmobnode_frontend
    timeout server 8000s
    timeout connect 10s
    server server1 127.0.0.1:4005 weight 1 maxconn 1024 check

3. PHP FPM
Change PHP5-FPM listen into socket in “/etc/php5/fpm/pool.d/www.conf”:

1
listen = /var/run/php5-fpm.sock

4. Install NodeJS

1
2
3
4
5
6
sudo apt-get update && sudo apt-get install git-core curl build-essential openssl libssl-dev checkinstall
mkdir ~/src && cd $_
wget -N http://nodejs.org/dist/node-latest.tar.gz
tar xzvf node-latest.tar.gz && cd node-v*
 ./configure --openssl-libpath=/usr/lib/ssl
checkinstall #(remove the "v" in front of the version number in the dialog)

5. Install Django Development

1
2
sudo pip install virtualenv
sudo pip install virtualenvwrapper

Now, we need to add this into “~/.bash_profile” :

1
2
3
4
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=$WORKON_HOME # Tell pip to create its virtualenvs in $WORKON_HOME.
export PIP_RESPECT_VIRTUALENV=true # Tell pip to automatically use the currently active virtualenv

Then, we are ready to create new virtualenv :

1
mkvirtualenv --no-site-packages --distribute django

Here is example NGINX configuration for Django

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
server {
    listen 82;
    server_name pongmob.com;
    rewrite ^ http://www.pongmob.com$request_uri? permanent;
}

server {
    listen 82;
    server_name www.pongmob.com;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    root /var/yodi/pongmob;

    client_body_timeout  460;
    client_header_timeout 460;
    send_timeout 460;
    client_max_body_size 10m;
    keepalive_timeout 300;

    index  index.php index.html index.htm;

    # Check if a file exists at /var/www/domain/ for the incoming request.
    # If it doesn't proxy to Apache/Django.
    try_files $uri @django;
       
    # Setup named location for Django requests and handle proxy details
    location @django {
            proxy_pass         http://localhost:8010;
            proxy_redirect     off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    }

}

And this is for Apache

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<VirtualHost *:8010>
    ServerName pongmob.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/yodi/pongmob

    WSGIScriptAlias / /var/yodi/pongmob/mobilegame/wsgi.py

    <Directory /var/yodi/pongmob/>
        <Files wsgi.py>
        Order deny,allow
        Allow from all
        </Files>
    </Directory>

    # Django settings
    WSGIDaemonProcess pongmob user=www-data group=www-data processes=1 threads=10 python-path=/root/.virtualenvs/django/lib/python2.7/site-packages/
    WSGIProcessGroup pongmob

    # Non-Django directories
    Alias /static/ /var/yodi/pongmob/static/
    Alias /media/ /var/yodi/pongmob/media/

    <Directory /var/yodi/pongmob/static/>
        Allow from all
    </Directory>

    <Directory /var/yodi/pongmob/media/>
        Order deny,allow
        Allow from all
    </Directory>

    Alias /robots.txt /var/yodi/pongmob/robots.txt
    Alias /favicon.ico /var/yodi/pongmob/static/favicon.ico

    ErrorLog /var/log/apache2/error.log
    CustomLog /var/log/apache2/access.log combined
</VirtualHost>

Install LXML Dependencies

1
2
sudo apt-get install python-dev libxml2 libxml2-dev libxslt1-dev libbz2-dev libssl-dev p7zip-full rar  unrar unzip unace unp bzip2 gzip patch
pip install lxml

OS

Windows mysql command line

19 Jun , 2013  

To enable mysql command line in DOS or PowerShell in Windows 8, we just need update System Environment Variable and put MySQL bin folder into the PATH.

1
C:Program FilesMySQLMySQL Server 5.6bin

OS

Set Java 7 on Mac OS X Mountain Lion

19 Jun , 2013  

We can use Java 7 JDK as default JavaVM in our OS X Mountain Lion. First, we need to install JDK 7 from Here.

Check installed java by “java -version”. If we got this errors :

1
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/bin/java" (-1)

Then, we need to fix path by editing ~/.bash_profile :

1
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home

To make this JAVA path works globally (Eclipse, Aptana, Android IDE need it), then please edit “/etc/launchd.conf” and put :

1
2
setenv PATH /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/bin
setenv JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/

OS

Solve MySQL can’t be opened because it is from an unidentified developer.

19 Jun , 2013  

When we install MySQL on MacOSX Mountain Lion, we might have this errors when clicking on MySQL pkg:

1
“mysql-5.6.12-osx10.7-x86.pkg” can’t be opened because it is from an unidentified developer.

To solve this problems, go to “Settings” and “Security Settings”. Unlock to make a change and select “Allow applications downloaded from” into “anywhere”.

OS

Solve configure: error: no acceptable C compiler found in $PATH

19 Jun , 2013  

When we need to compile or configure in Mac OS X, this errors might be occurs.

1
configure: error: no acceptable C compiler found in $PATH

To solve this problem, make sure we already have XCode installed in our Mac OS X. Then, launch XCode and click on “Preferences” menu. Go to “Download” Tab and Install “Command Line Tools”

Now we can start compiling 🙂

OS

Rsync linux to exfat partition Function not implemented

18 Jun , 2013  

Solving rsync function not implemented on EXFAT partition :

1
rsync -rltDv [SRC] [DESTINATION]

OS

Convert WebM into WMV to play in Windows Media Player

17 Jun , 2013  

Webfm is the movie format if we downloaded this from Youtube. In Fedora, we can convert this file into WMV using FFMPEG. Here is example command :

1
ffmpeg -i Billboard.flv -vcodec libvpx -acodec libvorbis Billboard.wmv

But if we got errors libvpx like thie:

1
Unknown encoder 'libvpx'

We can solve this “Unknown encoder ‘libvpx'” by remove the ffmpeg first. Then we install :

1
2
3
sudo yum remove ffmpeg
sudo yum install libvpx libvpx-utils libvpx-devel libvorbis libvorbis-devel
sudo yum install ffmpeg ffmpeg-devel

,

OS

Debian wheezy amazon can’t ssh on EC2

17 Jun , 2013  

When we already start new EC2 instance with debian wheezy, we realize that we can’t do SSH to server with SSH connection that offered by Amazon.

1
Permission denied (publickey).

SSH example:

1
ssh -i east-micro.pem root@1xx.20.xx2.xx

So, apparently in Debian Wiki, instead of using “root”, we should use “admin” to login into server.

1
ssh -i east-micro.pem admin@1xx.20.xx2.xx

,

Android

Make intent to another activity inside Fragment ClickListener in Android

11 Jun , 2013  

When we working with fragment, we want to put click action on item inside. For instance, we have calendar fragment and we want give OnItemClickListener on selected date. Here is a requirement to do that:

1. We need to access Parent Activity from fragment.
2. We can pass into another Activity from onItemClickListener inside fragment.

At this example, we want to pass action into DetailActivity

Here is the solution (inside fragment class):

Step 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
 * Callback to listener when date is selected
 */
private OnItemClickListener getDateItemClickListener() {
    dateItemClickListener = new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView< ?> parent, View view,
                int position, long id) {
           
            // Create Intent to passing id position to CalendarDetail
            Intent i = new Intent(getActivity().getApplicationContext(),
                    DetailActivity.class);
            startActivity(i);
        }
    };

    return dateItemClickListener;
}

More…

,

Android

Android onActivityResult intent data null or empty extra data

9 Jun , 2013  

When we’re using Google Camera tutorial on Samsung Galaxy S3, we got empty results for passing extra data in onActivityResult.
In another word, we got NullPointerException when trying to get data out of intent in onActivityResult

Why? Apparently, there is a bug in putting MediaStore.EXTRA_OUTPUT into Photo Intent:

1
2
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT,
        Uri.fromFile(photo));

If we disabled this line, then we can pass whatever extra data we want to onActivityResult.

Wait, that’s not the really problem here. Apparently, once we switch the camera off, then Activity will automatically reset and that’s mean the extra variable we passed into takePhotoIntent is gone!

So what the solution?
Remember with lifecycle callbacks? Yes, basically instead of putting extra data into Intent and got nothing in onActivityResult, we can put it into SaveInstanceState and take them back through onRestoreInstanceState.

Confuse? Here is the implementation, I will use currentPhotoPath as example extra data that I was put into Intent extra data.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
private static final String IMAGE_PATH = "path";
String currentPhotoPath = "";

/**
 * Intent to handle capture image from camera and save into a file
 * @param actionCode
 */
 private void dispatchTakePhotoIntent(int actionCode) {
        Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
       
        switch(actionCode) {
        case CAMERA_REQUEST:
            File photo = null;
           
            try {
                photo = setupPhotoFile();
                takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                        Uri.fromFile(photo));
                currentPhotoPath = photo.getAbsolutePath();
                setResult(Activity.RESULT_OK, takePhotoIntent);
                takePhotoIntent.putExtra("return-data", true);
        } catch (IOException e) {
            e.printStackTrace();
            photo = null;
            currentPhotoPath = null;
        }
        break;
   
    default:
        break;
    }
   
    startActivityForResult(takePhotoIntent, actionCode);
}

/**
 * Process photos that already saved by the users after taken from Camera
 */
@Override
protected void onActivityResult(int requestCode, int resultCode,
        Intent data) {
    switch(requestCode) {
    case CAMERA_REQUEST: {
        if(resultCode == Activity.RESULT_OK) {
            Log.v("ANDROIDDEBUG", currentPhotoPath);
        }
        break;
    }
    }
}

// Some lifecycle callbacks so that the image can survive orientation change
@Override
protected void onSaveInstanceState(Bundle outState) {
    outState.putString(IMAGE_PATH, currentPhotoPath);
   
    super.onSaveInstanceState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
   
    currentPhotoPath = savedInstanceState.getString(IMAGE_PATH);
}

Easy right? 🙂

,

Uncategorized

Solving GridView highlight / selected item random background in Android

8 Jun , 2013  

This is common problem that will occur when we want to change item background in Gridview based on position. Scrolling too fast on Gridview make selected / higlight item that we identify based on position, will showing random changes.

To solve this issue, we just need to define simple logic if..else on getView() in Adapter to set backgroundColor of item based on position. Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder; // to reference the child views for later actions
    View v = convertView;
   
    if (convertView == null) {
        LayoutInflater li = LayoutInflater.from(mContext);
        v = li.inflate(R.layout.item, parent, false);

        // cache view fields into the holder
        holder = new ViewHolder();

        // Set Text
        holder.dateText = (TextView) v.findViewById(R.id.item_text);

        // Associate the holder with the view for latter lookup
        v.setTag(holder);

    } else {
        holder = (ViewHolder) v.getTag();
    }
   
    holder.position = position;

    // Get day number by position
    int dayNumber = dates[position];

    // Get day name
    CalendarUtils calendarUtils = new CalendarUtils();
    String dayName = calendarUtils.getDateName(dayNumber, "SHORT");

    // Set text resource on each position
    holder.dateText.setText(Integer.toString(dayNumber) + " - " + dayName);
   
    // mark current day as focused
    if (dates[position] == selectedDate.get(Calendar.DAY_OF_MONTH)) {          
        v.setBackgroundColor(Color.parseColor("#48B93D"));
        Log.v(ANDROID_TAG, dates[position].toString());
    } else {
        // Force
        v.setBackgroundColor(Color.parseColor("#484848"));         
    }
   
    return v;
}

Java

Java int or integer

7 Jun , 2013  

In Java, should I use “int” or “Integer”?

This is common question for new Java developer like me. A lot of discussion can be found through google with searching on this question. Let me be clear, the difference between int and Integer can be seen from their parent.

As we know, int is primitive data-type in Java, meaning it will have same position as byte, short, float, etc. Meanwhile, Integer is a wrapper.

Yes, since Integer is not primitive as int, theoretically it’s slower than int. But, that’s not the point of this question.

1. Do you want to store NULL ?
If you want to store Null into database (Remember, not all database support NULL and it’s different from 0), then you should use “int”.

2. No! I want only store 0 even if it’s NULL or empty
Then, you should go to Integer since it’s have “Autoboxing” and “Unboxing” features. Detail : http://docs.oracle.com/javase/tutorial/java/data/autoboxing.html

Based on this two things, you can make consideration, which one you would use.

Android

Workflow working with database in Android

7 Jun , 2013  

Working with local database in Android required when we want to save user activities and load that state soon when the app reload / started. Some new guy that just started with Android Development need to figure out what the “worklow” to working with database in Android. Okay, here is the recipe:

Knowing Model, Helper and DataSource
Mostly, when we open some open-source Android app that contains database access, we see this three categories. Yes, it might have Model, Helper and DataSource in their class, filename or Description.
What they are?

1. Model
This class will contains “getter” and “setter” function and will produce Objects that will contains “result data”. What it’s looks like?
More…

,

Android

Solve Eclipse R cannot be resolved to a variable or fields in Fedora Linux

4 Jun , 2013  

Suddenly this errors occurs on Fedora 18 and a bit frustating for me to solve it. Fortunately, i found solution to fix it.

1. Update your SDK tools
2. Install 32bit depedencies

1
sudo yum install glibc.i686 glibc-devel.i686 libstdc++.i686 zlib-devel.i686 ncurses-devel.i686 libX11-devel.i686 libXrender.i686 libXrandr.i686 libstdc++.i686

3. Remove import android.R from headers in your activity files.
4. Restart your eclipse.

Done! 😀

,