Month: November 2012

  • Create alphabet list in Android using GridView

    We will build a trivial android app that create alphabet list using GridView. Fyi, Gridview is under ViewGroup that contains several View. I use Android 2.3.3 in this example. So, we can start create a new project called “Demo” and use “MainActivity” as main class. src/com/yodi/demo/MainActivity.java 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051package com.yodi.demo; import android.app.Activity; import android.os.Bundle; import android.view.View; import […]

  • Be carefull when creating list in Python using bracket [] or list() method

    There are big difference between list() and [] in Python. The first one for list() it will seeking iterable objects and make the object into list. The second one will be just wrap the object into list type. The same object with same result: 1234a = list(1) b = [1] print(a) print(b)

  • Learning how to read pseudo algorithm code and apply into Python code : Insertion Sort

    Learning and applying algorithm in Python must be fun! In this example, we will try read Algorithm pseudo-code and applied into Python code. We will start with “Insertion Sort”. What is this algorithm? Basically in each repetition, it will remove the element and put it into correct position in “sorted list”. Here is visual example […]

  • Install LXML in Debian

    To install LXML python module in Debian, you need to install depedency packages : 1apt-get install python-dev libxml2 libxml2-dev libxslt1-dev libbz2-dev libssl-dev p7zip-full rar lha unrar unzip unace unp bzip2 gzip patch Then, you can install lxml by : 1pip install lxml

  • How to reverse variable array using pointer to pointer in C++

    Pointer to pointer is an reference that contain another pointer memory address. Remember, the reason it’s called pointer because it’s just pointing to another place that have “value”. Pointer is different with pointer to pointer. This is the simple explanation: 12345678910111213141516#include<iostream> #include<str using namespace std; int main() {     int customer = 1;   […]

  • How to counting array size and total element in C++

    Array in C++ is just same as variables that organized into one place. Basically, each element in array just stored sequentially in memory. To get the length of array, it just simple by get the size of array and divided it by the data type size. Since the way array stored the value sequentially, then […]

  • Pretty print dictionaries or another data in Python tricks

    Supposed we have a nested dictionary. We want to print the data inside dictionary in decent format. Example, we have dictionary: 1a = {1: ‘Hello’, 2: ‘World’, 3: {1: "Python", 2: "C++"}} We usually print this using print() and showing exact format. There is some trick to pretty print this data using JSON. Wait, JSON? […]

  • Static Method / Class Method example in Python

    Methods is sub-routine that associated with class. Usually, we can using the method inside a class from the instance objects. Static method / Class method is refering to accessing method using Class explicitly. That means to using method inside class, we’re using Class.. Let see the example of Class method in Python: 123456class Hello:   […]

  • Seeing the workflow of Class Inheritance in Java

    When it comes to Inheritances, that means we try using code reuse. In Java, Python, C++, Inheritance is a common thing since we want to reduce duplicate code and manage them easily. In Java, we can create a subclass by inheriting from parent using “extends”. Here is some trivial example: InheritanceImplementation.java 12345678910111213141516171819import java.lang.String; class Bank […]

  • Understanding assigment operator in Python from copying list or dictionary experience

    When it comes to copy a variable into new variable, a few begginer will found that something weird happen when they modified the new variable. Yes, the old variables state will get updated as well soon new variable edited. This is some basic example: 12345a = {1: "Hello"} b = a print(b[1])    # showing […]

  • Showing python module help or documentation inside Python Intrepeter in good display / format

    When we need to import some python modules, sometimes we need to read the documentation inside the python intrepeter. There are 2 ways to showing help / documentation of the module. 1. __doc__ We can see by print attribute “__doc__” from the module. Example, I use module “copy”: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051import copy print(copy.__doc__) Generic (shallow and deep) […]

  • Example of clone array in Java

    To making copy of array in Java, we can use method “clone” in the array objects. First step, we need to create one-dimensional array : 12// Create first array variable float[] floatArray = {5.0f, 3.0f, 1.5f}; This will create an array objects with 3 elements. We can clone this by: 12// Create clone variable float[] […]

  • Implementation of User-Defined data using Struct in C++

    There are two kind group of data type that needed to reserve amount memory, primitive data and user-defined data. Primitive data just like Int (4 byte), Char (1 byte), Double (8 byte) and so on. But what about we construct our custom data types, like a new data type that contains Int and Char? Then […]

  • Free Google Apps Mail for Domain

    Nowadays hard to find Google Free Apps Domain which used to be easy. But don’t worries, because Google still provide Free Version of Google Apps but in hidden menu. Here is to go Free Google Apps Mail for Domain

  • Grab Twitter Search JSON using simple JAVA bufferStream

    Open JSON files from twitter search using JAVA is easy. We can use simple buffer stream reader. Here is the example: 123456789101112131415161718import java.io.BufferedReader;  // 1 import java.io.InputStreamReader; import java.net.URL; public class OpenWebsite {     public static void main (String[] args) throws Exception { // 2     URL twitter = new URL("http://search.twitter.com/search.json?q=" +   […]

  • Django queryset filter equal or compared based on another column / fields within same models

    There will be a case when we want to filtering data that have “equal” between one fields with another fields (column) on same models. Given example, We have Django built-in user table called “auth_user” and user profile table called “user_profile”. The requirement is we want to get all users that not-logged and have status “GAMER” […]

  • Example using Map in Java

    The Map Interface in Java just like dictionaries in Python. It have function to create key – value data structure which each key must be unique. In Java term, this data structure create association between one object to another object. This is how to use Map() interface in Java: Filename: MapExample.java 123456789101112131415161718// I need to […]

  • Solve Firefox webdriver selenium Failed to dlopen /usr/lib/libX11.so.6 in Fedora

    I use Selenium for testing, usually I use ChromeDriver which more fast and smoothly than firefox. In case you have failed when using Selenium with Firefox WebDriver and got this issue : 1WebDriverException: Message: ‘The browser appears to have exited before we could connect. The output was: Failed to dlopen /usr/lib/libX11.so.6ndlerror says: /usr/lib/libX11.so.6: wrong ELF […]

  • Private in Python with double underscore instead of one underscore

    Updated that I was wrong about private variable in Python and get corrected by my friends : http://eugene-yeo.me/ I believe there are a few people thinking single underscore “_” is for create private variable in Python. Well, this is not right anyway. To make it easy for explaining, let see this socket modules in Python […]

  • Django admin execute action without selecting all objects

    There will be a task when you need to create a new action like “export to XML / CSV” and execute this action without selecting any objects / records. Technically, that’s mean how we doing response_action inside changelist_view() in Django admin without selecting any partial / all objects. This also will works if you using […]

  • Python map with two or more arguments

    Built-in Python function map() is best way to iterate and generate a new list from given list. Usually we using one arguments when passing objects into function inside map(), eg: 1map(show_records, list_records) At this example, x from list_records will passed into show_records(x). But, how to passing multiple arguments into map() ? Basically, it’s easy with […]

  • Django send email on localhost and using Template for content

    The most common things while developing django application is sending email. Django have built-in function for sending email called “send_email” under django.core.mail. When we using long text of emails content and testing in our local, then we need to set it working on localhost and templating. 1. Set up django send email on local We […]