Thursday, January 19, 2012

Vi editor delete commands

x - delete single character under cursor  
Nx  --delete N characters, starting with character under cursor  
dw - delete the single word beginning with character under cursor  
dNw - delete N words beginning with character under cursor;
  e.g., d5w deletes 5 words
 
D - delete the remainder of the line, starting with current cursor position
dd delete entire current line
 Ndd or dNd - delete N lines, beginning with the current line;
  e.g., 5dd deletes 5 lines

Solution for 'not found in haystack' error in Zend


If you get a '%value%' was not found in the haystack' error when using select boxes in Zend, add the following to the form element:


$element->setRegisterInArrayValidator(false);

or directly when creating form:

$form->addElement('multiselect', 'elementname', array('RegisterInArrayValidator' => false));

how to run a php script using windows scheduler

Locate the php.exe executable on your system and pass it the name of the script file using the -f parameter.

Example:

C:\Xampp\php\php.exe -f C:\Xampp\htdocs\my_script.php

Close browser event

JavaScript: window.onbeforeunload Event - Show “Are you sure you want to leave this page?” Message


$(window).bind('beforeunload', function() {
return 'You have unsaved changes. If you leave the page these changes will be lost.';
});

How to restart centos from command prompt?

shutdown -r now
reboot now

svn commands for remote checkout and remote export

Commandline commands

svn checkout http://path/

svn export --force

Wednesday, January 18, 2012

How to handle dates beyond 2037

$date = '2040-02-01';
$format = 'l d F Y H:i';
$mydate1 = strtotime($date);
echo '

', date($format, $mydate1), '

';


you’ll see “Wednesday 1 February 2040 00:00″ displayed in your browser. If you’re seeing a date in the late 60′s or early 70′s, your PHP application may be at risk from the Y2K38 bug!

Fortunately, PHP introduced a new DateTime class in version 5.2 (experimental support was available in 5.1 and be aware that some methods were introduced in 5.3)…
view plainprint?


$date = '2040-02-01';
$format = 'l j F Y H:i';
$mydate2 = new DateTime($date);
echo '

', $mydate2->format($format), '

';

Friday, January 13, 2012

To select current year selected in an year dropdown

var d = new Date();
var curr_year = d.getFullYear();

$("#dropdownid option[value='"+curr_year+"']").attr('selected', 'selected');