At this time, a company website normally should have blog to post some business activity or related activity with website themes. Wordpress is the best blog framework (CMS) that i ever used. When i was build web application under my own php framework, i wasn’t worried about integrating wordpress into my website. It would has separated setting with main application.
However, now i am using cakephp framework. And if we need to put file or folder, it need to be put inside app/webroot folder. So if i need to install wordpress blog in http://www.balistupa.com/blog, i need to put the blog folder inside /app/webroot/.
The problem is about the url, with standard setting the blog would be redirected to http://www.balistupa.com/app/webroot/blog/ not to http://www.balistupa.com/blog/. This is not look good for visitor and also for seo. Because the folder structure is to deep.
(more…)
Actually there is no Thread.sleep method on javascript that work on Threading. Moreover there is no true threading in javascript. So everybody that want to deal with threading need to emulate it. In this article i would like to show you some method that emulate sleep method for waiting on a process. Each of this method has each own disadvantage, so you need to choose which is suitable for your case.
First method is sleep using javascript loop. This is first method that come to my mind when emulate sleep method on javascript. We wait for the process by checking the time in the loop.
function wait(millisecond) {
var date = new Date();
var current_date = null;
do { current_date = new Date(); }
while(current_date-date < millisecond)
}
// do something
wait(1000); // wait 1000 millisecond
// do something
(more…)
Sometime we need to handle or do something when user closing a browser windows or page. Maybe we want to ask user if they really want to close the page or it was a mistake click. This procedure all can be done using javascript.
There are two condition or event that you can intercept before it really happen, first when user close the browser windows and second is when browser windows will be closed without any way to abort it.
For first condition we can handle it using window.onbeforeunload event.
function closeHandler() {
return “Are you sure you want to close this page?”;
}
window.onbeforeunload = closeHandler;
(more…)
Sometime we need to print the structure data that return by a function. I was work on a task for google map and need to print object properties of Placemarks object on javascript. I need to analyze what kind of structure data return by geocoding function. The code below is a short function to print object properties in javascript
function isObject(obj) {
return obj.constructor == Object;
}
function print_object(object, level){
var tab = “”;
if(level > 0){
for(i = 0; i < level; i++) tab += “\t”;
}
var str = “”;
for(prop in object) {
if(!isObject(object[prop])) str += tab + prop + ” value :” + object[prop] + “\n”;
else str += tab + prop + “\n” + print_object(object[prop], level + 1);
}
return str;
}
and how to use this function is really simple approach
address = addresses.Placemark[0];
alert(print_object(address, 0));
in this scenario, i would like to print first placemark object return by geocoding function. Parameter level is use to make nice print view using tab character.
Before June 2008, there is no clean implementation for GROUP BY. commonly people code with CakePHP will put GROUP BY sintak on conditions, something like this
$this->Product->find(’all’, array(‘conditions’ => ‘1=1 GROUP BY Product.category_id’));
Now CakePhp have a clean sintak for GROUP BY by new additional paramater on find function. We can use ‘group’ to define GROUP BY on cakephp. For example
$this->Product->find(’all’, array(’fields’ => array(’Product.category_id’, ‘COUNT(Product.hotel_id) as total’), ‘group‘ => array(’Product.category_id’)));
How if we want to have HAVING sintak on query? i ussually use this solution for new cakephp
$this->Product->find(’all’, array(’fields’ => array(’Product.category_id’, ‘COUNT(Product.hotel_id) as total’), ‘group’ => array(’Product.category_id HAVING COUNT(Product.hotel_id) > 1′)));
Sometime we need to pass data or parameter to another Activity on Android. Only one activity is active at once. An activity open new activity for result and opened activity need parameter to set their interface or another option based on request. So it is important a system can handle sending and retrieve parameter between two Activity.
To open an activity and wait for a result, we can use this sintax
Intent newIntent = new Intent(this.getApplicationContext(), ActivityClass2.class);
startActivityForResult(newIntent, 0);
ActivityClass2 is the class name of activity that we need to create and then open it from current activity. startActivityForResult is a method to run newActivity. Later we can have the result by add this function on current Activity (more…)
By default, belongsTo and hasOne using LEFT JOIN relation between parent and child table or model. We can forcing the relationship to use either INNER JOIN or LEFT JOIN based on our need. Cakephp has add new option when binding model, name type: value is LEFT or INNER.
For example we have parent table Author and hasOne Post, we can set INNER JOIN relation by default on model class or in controller using bindModel. In this example the hasOne relation set on model class
<?php
class Author extends AppModel {
var $name = ‘Author’;
var $hasOne = array(’Post’=>array(’type’=>’INNER’));
}
?>
and running on controller
$this->Author->find(’all’);
cakephp will generate query for author table.
SELECT `Author`.`id`, `Author`.`name`, `Post`.`id`, `Post`.`post_id`, `Post`.`title` FROM `authors` AS `Author` INNER JOIN `posts` AS `Post` ON (`Post`.`post_id` = `Author`.`id`) WHERE 1 = 1
I want to show you a situation that probably happen to you when build a mysql query. The situation can be vary but basically same condition. For example we have places table to store all beautiful places around the world. And a categories table to classify our places data. The rule is a place can be put on one or some categories. To achieve this function we just add a field into places table that save category id list.
So places table will have id, name, categories fields. and categories table have id, name. We want to save category list into categories field on places table. The data will look like this ‘2,3,4,5,6,7,8′. A question will come to your mind about how to grab or find a matching id inside this categories, for example we want to show all place with category id 5.
We cannot use LIKE in this example because it cannot match perfectly on many digit number. So i found a solution that easy to do. The query to find all data inside mysql Array field is
SELECT * FROM places WHERE FIND_IN_SET(5, categories)
Another solution is by adding new table to save category list for place. But my solution look nice, right?
You can use any text editor to write a java code for android, and then compile using JDK tools. Create android package (APK) using android sdk tools and then install and run application on emulator. But we need a tool to automatic all android development process. One android IDE that commonly used by android developer is eclipse. Using eclipse you can have an integrated development environment for android through Android plugin, such as
- write or code java source for android application
- good overview for your project inside project manager
- user friendly interface to create new android project
- compile and debugging is as easy as desktop application development
- nice java source code editor with high text editing functionality for developer
- setting emulator also easy with good overview using DDMS perspective
- run android application inside emulator with simple click
There are many more advantage using eclipse as your IDE for android. Believe me it makes you enjoy coding android with their nice interface and automatic process.
(more…)
For whom that doesn’t know yet the android, it is a new platform that basically run on gphone mobile device. GPhone stand for Google Phone, i think google want to spread their business to mobile device technology. But android is not for gphone only, at least nokia will have android on their device in future. So for developer it is a good market to make an application run on android platform. Best thing is android give developer a software development kit (SDK) that based on java programming language. And this SDK is open to all developer and has big community. This article is about installing android sdk on your windows machine.
First of all you need a java library installed on your machine. It can be a JRE or JDK, but i suggest you to install JDK as we want to develop a java application on our machine.
(more…)