Extjs Static Combobox

This snippet show you a static combo

{
    xtype:'combo',
    fieldLabel:'Field Label',
    name:'theName',
    queryMode:'local',
    store:['1','2'],
    displayField:'Display Field',
    autoSelect:true,
    forceSelection:true
 }

Another alternative (1):

// The data store containing the list of statesvar 
pilihan = Ext.create('Ext.data.Store', {
    fields:['display','value'],
    data :[{"display":"Ya","value":"1"},
        {"display":"Tidak","value":"0"}]
    });

// Create the combo box, attached to the states data store
Ext.create('Ext.form.ComboBox',{ 
    fieldLabel:'Pilih', 
    store: pilihan, 
    queryMode:'local', 
    displayField:'display',
    valueField:'value', 
    renderTo:Ext.getBody()
});
 

Another alternative (2):

{
    xtype:'combo',
    fieldLabel:'Main',
    name:'main',
    queryMode:'local',
    anchor: '100%',
    store: Ext.create('Ext.data.Store', {
        fields: ['value', 'display'],
        data: [
            {
                "display": "Ya",
                "value": 1
            },
            {
                "display": "Tidak",
                "value": 0
            }
        ]
    }),
    displayField:'display',
    valueField: 'value',
    autoSelect:true,
    forceSelection:true
 }

Signing Your Android Applications

Yeah, it seems easy task for ‘real developers’ but not for beginner.
The easiest way to do this by Eclipse, so you must have an Eclipse before we start and ofcourse, you must have an Android project to signing. If you don’t have it, take a look into this tutorial.

 

(1) Start your Eclipse 😀

 

(2) File – New – Other – Android Project from Existing Code

sign01

 

 

(3) Choose your Cordova application that you made before with Netbeans

sign02

 

(4) You can see MyApp and MyApp-CordovaLib.

sign03

 

Right click at MyApp – Android tools – Export signed application package and follow the step

(5) * Create new keystore

** Location: Your location file to store your new keystore

** Password: A password for your keystore

 

* Key Creation

** Alias: Alias your application

** Password: your keystore password

** Validity (years): Your validity years application

** Firstname and Lastname: You already know it 😀

** […] Clear description and you can click next at the bottom of the form

 

* Destination apk: Fill with location and name for your apk and Finish.

sign09

 

Congratulation! you made it. You can upload MyApp.apk to your google play account.

 

Creating Android With Cordova 3.4.0 and Netbeans 8.0

Today, I just knew that Netbeans already have release version 8.0 and the other thing makes me happy is Cordova is easily configuring with this Netbeans.

In this post, I will lead you to create an Android application with Cordova 3.4.0 and Netbeans 8.0.

(1) Open your Netbeans 8.0 and File – New Project

(2) Choose an HMTL5 categories, Cordova Application project and next button.

cordova_01

 

(3) Fill in Project Name, Project Location, Project Folder and Next

cordova_02

 

(4) Choose Javascript Library and Next.

Notice; If you don’t add the JS library at this time, you can add later including it normally like creating an HTML project.

cordova_04

(5) Application ID, Application Name, Version and Finish

cordova_06

Wait for Netbeans upgrading Cordova platform.

 

(6) Run in Cordova Android Emulator

cordova_07

 

(7) Open your terminal in Netbeans. You can find it in Window – IDE Tools – Terminal.

Go to your Android SDK Linux tools folder

$ cd /home/kenzominang/android-sdk-linux/tools
$ ./android avd

cordova_09

 

(8) Choose one of AVD and start.

cordova_10

(9) And now you can build and start your Cordova application

cordova_12

 

That’s it. You have done creating an Android application with Netbeans.

If you have done developing it, you must sign in your application before uploading it into google play.

Updating Android SDK

Recently I am facing a problem when I create an Android application with Cordova platform. It happend when I execute $ cordova platform add android. The error line showing like this;

at /home/admin/.cordova/lib/android/cordova/3.3.0/bin/lib/check_reqs.js:87:29

This error message clear to me because when I opened check_reqs.js file, I found an information what I must do. Yeah, updating Android SDK or configuring Android SDK Path. But on this post, I will show you how to update The Android SDK;


$ cd android-sdk-linux/tools
$ ./android update sdk --no-ui

For further discussion, take a look at this

Concenate Array String Using StringBuilder in Java

My recent project is converting a PHP application into Java. I have found this code in PHP. I think this piece of code is interesting because I have found this code a lot from the application.

Below code used for tricky query block in PHP

$nu_filters = preg_replace('/[^a-zA-Z0-9]+/', ' ', $filter);
$search_words = explode(" ", $nu_filters);
$thisWhere = "";
 foreach($search_words as $sword)
 {
     $thisWhere .= " content_all like '%".$sword."%' $operator_concat ";
 }
$thisWhere_count = strlen($thisWhere);
 //echo $thisWhere;
$where = " (".substr($thisWhere, 0, $thisWhere_count - 4).") ";
return $where;

And this is the Java code using StringBuilder:

public class TheQuery {
    public StringBuilder secondWhereLogic(String filter, String operator_concat) {

        String nu_filter = filter.replaceAll("/[^a-zA-Z0-9]+/", " ");

        String[] search_words = nu_filter.split(" ");

        StringBuilder newStr = new StringBuilder();

        for(int i = 0; i < search_words.length; i++) {
            newStr.append(" content_all like '%"+search_words[i]+"%' or ");
        }
        return newStr;
    }
}

Thats it… 🙂

Laravel 4.x setting in production and development

Surely, in production use you don’t want to show any error to the user. In simple way, you can set debug to false:
/app/config/app.php

return array (

'debug' => false,

[...]

)

For complete setting for development and production, you can try;
/app/bootstrap/start.php

$env = $app->detectEnvironment(array(
	'local' => array('localURL.com'),
	'production' => array('productionURL.com')
));

Define your file/folder configuration for every situation (development/production):

app
app/config
app/config/local
app/config/local/app.php
app/config/local/database.php
app/config/production
app/config/production/app.php
app/config/production/database.php

Easiest way to write library in Laravel

Sometimes you have change a lot in your Laravel configuration and folder. This will avoiding running composer again.

First, just open your /app/start/global.php. Add a folder libraries (whatever you want):

app_path().'/commands',
app_path().'/controllers',
app_path().'/models',
app_path().'/database/seeds',
app_path().'/libraries',

And now you can add any file in your libraries folder.

Example:

<?php

/* File: Bantu.php */

class Bantu {

    public static function write( $message ) {

        echo $message;

    }

}

Non Alpha Numeric Regex with Javascript

Using javascript regular expressions to stop users from entering non-aphanumeric characters or white spaces

Say you want to stop users from entering non-aphanumeric characters or white spaces.

Using regular expressions would be the easiest method:

Here is my javascript code:

<script language="Javascript">
function alphaNumericCheck(){
    var regex=/^[0-9A-Za-z]+$/; //^[a-zA-z]+$/
    if(regex.test(document.add_data.password.value)){
        alert("Good")
        return true;
    } 
    else {
        alert("Please fix: password")
        return false;
    }
}
</script>

For numbers only use /^[0-9]+$/

For mixed text and numbers, with spaces /^[0-9a-zA-Zs]+$/

Here are more useful regular expressions:

[a-zA-Z] any letter
d any number; same as [0-9]
D any NOT number; same as [^0-9]
w any alphanumeric character; same as [a-zA-Z-0-9_]
W any NON-alphanumeric character; same as [^a-zA-Z0-9_]
s any whitespace (tab, space, newline, etc...)
S any NON-whitespace
n newline
t tab

To view a full html sample of the above code click the links below using regular expressions in JavaScript