Tuesday, August 24, 2010

Running a c pgm in unix

step 1:create a c file in your directory.


step 2:compile it using cc -o programname sourcefile.c.This makes a file named programname in the same directory.(or) compile it using gcc sourcefile.c.This makes a file named a.out in the same directory.


step 3:Run it using ./programname (or) ./a.out.

Thursday, August 5, 2010

How to separate a string using explode in php

ex:
$st= explode('-', date('Y-m-d',strtotime('2010-01-01')));
result:
Array
(
[0] => 2010
[1] => 01
[2] => 01
)

Tuesday, August 3, 2010

How to reset a single file in git

If you have changed a file in your working copy,but not commited yet,then you can restore that file to the version in the HEAD revision using,
git checkout HEAD hello.js

Monday, August 2, 2010

How to sort an two-dimensional array with respect to an element

$item_arr=Array
(
[0] => Array
(
[resourceid] => 854
[refno] => 268475
[fax] => +61 2 6198 3333
[phone] => +61 2 6198 3300
)

[1] => Array
(
[resourceid] => 750
[refno] => 268476
[fax] => +61 8 8233 5858
[phone] => +61 8 8233 5888
)

[2] => Array
(
[resourceid] => 675
[refno] => 268477
[fax] => +91 40 4033 9999
[phone] => +91 40 4033 9900
)

[3] => Array
(
[resourceid] => 522
[refno] => 268478
[fax] => +86 10 8520 0110
[phone] => +86 10 8520 0000
)

[4] => Array
(
[resourceid] => 647
[refno] => 268479
[fax] => +86 21 6103 7070
[phone] => +86 21 6103 7000
)

)
to sort above array with respect to refno,

function sorter($a, $b) { return $a["refno"] > $b["refno"]; }
usort($item_arr,"sorter");