Pages

Thursday, January 12, 2012

How to install web service client application in windows server

This post based on my experience when try to install my web service client application created using delphi. I have no idea, why i was get error when fetching data from web service. The problem is setting of data execution prevention that must be enabled in windows server. The following is the steps to enable data execution prevention :
  1. Click Start, click Control Panel, and then double-click System.
  2. Click the Advanced tab. Then, under Performance, click Settings.
  3. Click the Data Execution Prevention tab.
  4. Click Turn on DEP for essential Windows programs and services only to select the OptIn policy.
  5. Click Turn on DEP for all programs and services except those I select to select the OptOut policy.
  6. If you selected the OptOut policy, click Add and add the applications that you do not want to use DEP with.

Wednesday, January 11, 2012

How to compile in linux

How to compile in linux

One benefit of using linux is it is open source. So if we have problem with our program, we can recompile it by our self. Actually, recompiling program is not difficult. We just need some steps as below :
  • Download source code
    We can download source code of our program from it's official web site. It is usually compressed using tar.gz or tar.bz2. For example, if we want to download apache source code, go to apache website
  • Extract downloaded file
    We can user tar -zxvf [file_name].tar.gz or tar -jxvf [file_name].tar.bz2. For example as below :
    # tar -zxvf httpd-2.0.49.tar.gz
    
  • Login as root
    # su -
    
  • Go to directory
    # cd httpd-2.0.49
    
  • Configure source code with option
    The configure option can be various, depend on software we want to compile. For example we want to compile apache with command as below :
    # ./configure --prefix=/usr/local/httpd --enable-so
    
  • Do Make
    After compiling, we need to make it using this command :
    # make
    
  • Install
    The last thing we need to do is install it using this command :
    # make install
    
If we want to change compiling option, recompile it with another option and add make clean after compiling.

Tuesday, January 10, 2012

How to install ntfs on rhel


Redhat Enterprise Linux (RHEL) is not automatically detect any hdd formatted with ntfs. So it can't be mounted. But now there is a way to make it detected, by using NTFS-3g.
NTFS-3G allows us to handle NTFS file systems of Windows OS. Its an open source read/write NTFS for Linux installations. It offers the capability to create, delete, rename, move files, directories, hard links, and streams. Special files such as the symbolic links, devices and FIFOs, ACL, extended attributes can be easily handled. Below are the steps to install ntfs-3g :
  1. Logged in as Root
    # su -
    
  2. Install ntfs-3g, we can use yum or rpm -ivh
    # yum install ntfs-3g
    # rpm -ivh ntfs-3g fuse-ntfs-3g-1.1004-1.el5.rf.i386.rpm
    
  3. Determine the name of an NTFS partition :
    # fdisk -l /dev/sdb  ;replace /dev/sdb with your own
    
  4. Load the fuse driver :
    # modprobe fuse
  5. Create a mount point
    # mkdir /mnt/ntfs
  6. Mount the ntfs partition
    # mount -t ntfs-3g /dev/sdb1 /mnt/ntfs
To unmount partition, simply using below command :
# umount /mnt/ntfs

Monday, January 9, 2012

How to handle exception in delphi

Almost in all programming language, there are mechanism to handle exception. So do in delphi. We can use try...except mechanism. The following is the example of exception handling in delphi :
var
  bagi, nol : Integer;
begin 
  try
    nol   := 0;
    bagi := 1 div zero;
    ShowMessage('1/0 = ' + IntToStr(bagi));
  except
    on E : Exception do
      ShowMessage(E.ClassName + ' error raised, with message : ' + E.Message);
  end;
end;
In that example, if the try clause generates an exception, it will the execute except clause that will display window showing what type of error generated. This is used to take alternative action when something unexpected goes wrong. Beside that, the other form of handle exception can be done as follow :
var
  bagi, nol : Integer;
begin 
  try
    nol   := 0;
    bagi := 1 div zero;
    ShowMessage('1/0 = ' + IntToStr(bagi));
  finally
    if bagi = -1 then
    begin
      ShowMessage('Number was not assigned a value - using default');
      bagi := 0;
    end;
  end;
end;
In a try...finally construct, the finally statement will be executed absolutely whether thereis error or not. It is normally used to allow cleanup processing, such as freeing memory etc. Both kind of construct cannot be combined together using try..except..finally. So, the question is how to handle exception while we want to execute a set of clean up statements, in other words, how to tricky combine both except and finally ?? This can be done with nested try statements, as construct below :
Try
  Try
    ...
  Except
    ...
  End;
Finally
  ...
End;
Need to be noticed that when you want to test exception handling, don't do it using F9/Run. But do it by execute application (ctrl+f9 then double click application.exe created)

Sunday, January 8, 2012

How to convert date to char in oracle

In every dbms, conversion is something that almost always happen. In oracle, if we want to convert date to char we can use to_char() function. otherwise, if we want to convert char to date we can use to_date() function.
Below is the sample to_char() and to_date() usage in oracle :
select to_char(sysdate, 'DD/MM/YYYY HH24:MI:SS') from dual; select to_date('29/03/2012 08:18:45', 'DD/MM/YYYY HH24:MI:SS') from dual;
The first result will be the current date time of your database server
The second result will be '29/03/2012 08:18:45'.

Saturday, January 7, 2012

How to install pear modules in xampp

Below is the step to install pear in xampp :
  1. Search the path of executable pear
    usually it is in 'C:\xampp\php\pear.bat'
  2. Run the following command, for example we will install MDB2 module :
    pear install MDB2
    Below is the look like :



Friday, January 6, 2012

How to insert post programmatically in wordpress

Sometimes, we need to insert post to our blog through code. This case occur in condition for example when we need to insert more than 1 post in 1 time.
Here is the code to do that :
  // Create post object
  $my_post = array();
  $my_post['post_title'] = 'My post';
  $my_post['post_content'] = 'This is my post.';
  $my_post['post_status'] = 'publish';
  $my_post['post_author'] = 1;
  $my_post['post_category'] = array(8,39);
  
  // Insert the post into the database
  wp_insert_post( $my_post );

Thursday, January 5, 2012

How to create xml document in PHP

Using domdocument, we can create xml document as we wish. Combined with the how-to-create-xml-in-php we will create xml directly in browser.
Here is the code to create xml from php :
$domDocument = new DOMDocument('1.0', "UTF-8");
  $domElement = $domDocument->createElement('field','some random data');
  $domAttribute = $domDocument->createAttribute('name');
  
  $domAttribute->value = 'attributevalue';
  
  $domElement->appendChild($domAttribute);

  $domDocument->appendChild($domElement);

  header("Content-type: text/xml");
  echo $domDocument->saveXML();
 
Here is the screenshot of the code above :

Wednesday, January 4, 2012

How to create xml in php

To create xml in php you can do the following step :
  1. You can use domdocument or create string in form of xml.
  2. Create header xml as code below :
    header("Content-type: text/xml");
    

Tuesday, January 3, 2012

How to get list files of a directory in delphi

Dear reader. Sometimes we need to get list of file names of a directory. This procedure below will do that for us :
procedure GetFilenames(Path: string; Dest: TStrings);
var
  SR: TSearchRec;
begin
  if FindFirst(Path+'*.*', faAnyFile, SR) = 0 then
  repeat
    Dest.Add(SR.Name);
  until FindNext(SR) <> 0;
  FindClose(SR);
end;
 
To use that function, for example you need to create a form with a button and listbox, we name it button1 and listbox1. Here is the code to use that procedure
procedure TForm1.Button1Click(Sender: TObject);
var
  path:string;
begin
  path := 'C:\Movies\';
  GetFilenames(path, ListBox1.Items);
end;
Here is the result when we click on button 'Get List Files Name'
get list files name in delphi

Monday, January 2, 2012

How to substring in delphi

There is almost in every programming language function to substring a string. As well as delphi. To substring a string in delphi use 'copy' function as below :
var s : string;
begin
  s:='Embarcadero';
  s := Copy(s,6,5);
  ShowMessage(s);
 
It will display message 'cader' as below :

Sunday, January 1, 2012

Adsense v3 app doesnot appear in firefox

Have you ever got a problem that adsense app page doesn't appear when open it using firefox? or have you ever got image as below when accesing adsense app page


if it's so, the problem is your adblock plugin. To enable that page do the steps below:
  1. check your adblock plugin (in my computer, i am using adblock plus)
  2. choose 'Disable on this page only'
  3. refresh your browser
Don't Forget To Join Our Community
×
Widget