HowTo clear subclipse plugin for Eclipse IDE and subversion password on windows xp/vista

This method works if subclipse plugin for Eclipse is setup to use JavaHL , open cmd with administrative privileges in %APPDATA%\Subversion\auth\svn.simple , there is files with auth settings for each repository , remove the necessary , also in some cases you should clear keyring cache :

cd %APPDATA%\Subversion\auth\svn.simple
C:\Users\someuser\AppData\Roaming\Subversion\auth\svn.simple>del *
cd %ECLIPSE_FOLDER%\configuration\org.eclipse.core.runtime
del .keyring

Don’t forget to restart eclipse .

How to get first and last day of the month with php

Using PHP’s mktime function , the last day of any given month can be expressed as the “0″ day of the next month , therefore :

$lastDayOftheMonthTimestamp = mktime(0,0,0,$currentMonthNumeric + 1,0,$currentFullYear);

Full example :

$currentTime         = time();
$dateTime            = getdate($currentTime);
$currentFullYear     = $dateTime["year"];
$currentMonthNumeric = $dateTime["mon"];
$firstDayOfTheMonth  = date('Y-m-d',mktime(0,0,0,$currentMonthNumeric,1,$currentFullYear));
$lastDayOfTheMonth   = date('Y-m-d',mktime(0,0,0,$currentMonthNumeric + 1,0,$currentFullYear));
 
   echo $firstDayOfTheMonth.PHP_EOL;
   echo $lastDayOfTheMonth .PHP_EOL;

Result :

2009-02-01
2009-02-28

MD5 hash validation with PHP

preg_match('/(?<![a-z0-9])[a-f0-9]{32}(?![a-z0-9])/i', '123456789024567d890f123456789012',$result);

Result :

Array
(
    [0] => 123456789024567d890f123456789012
)

Howto make pages controller like in CakePhp with Zend_Action_Controller

CakePhp framework comes with controller class extension called PagesController , this extension serves very productive propose , it checks what actions was called and renders view template with same name .

For example if user accesses url http://micrub.info/pages/examples/ , the controller should search for view template in PagesController views directory , like app/views/pages/examples.ctp , if page isn’t found 404 headers should be returned to the browser .

This approach is very MVC oriented , person which is responsible to add new static content to a view layer doesn’t depends on programmer , he simple adds or removes a new pages without any need to have access to the businesses logic layer , working with which demands much deeper understanding of the web development field .

One of the first things that I have done when started to work with Zend Framework was to create same future within Zend Framework based project template .

In order to provide such a future , Zend_Controller_Action class was extended , magic php function __call() was overwritten in order to create proxy method which checks for existing view template and handle exceptions like :

Why is __call() function was overwritten ?

When Zend_Controller_Action extended class is dispatched and action function isn’t defined in it , php’s magic function __call() is called . Its default implementation throws Zend_controller_Action exceptions and if front controller bootstrapped not to throw exceptions )( $front->throwExceptions(false); ), ErrorController is set , a proper HTTP statuses can be returned to the browser for PagesController exceptions .

require_once 'Zend/Controller/Action.php';
 
class PagesController extends Zend_Controller_Action {
 
    /**
     * Checks if view template file is found in one of script paths for this controller .
     */
    protected function checkScript($name)
    {
		$paths = $this->view->getScriptPaths();
        foreach ($paths as $dir) {
        	$path2script = $dir . str_ireplace('/',DIRECTORY_SEPARATOR,$name); <strong>// for some reason , without this one action name isn't compatible on winXP </strong>
            if (is_readable($path2script)) {
                return true;
            }
        }
		return false;
    }
 
    /**
     * Proxy for undefined methods.  Default behavior is to throw an
     * exception on undefined methods, however this function was
     * overridden to provide run-time dispatching.
     *
     * @param string $methodName
     * @param array $args
     */
    public function __call($methodName, $args)
    {
        if ('Action' == substr($methodName, -6)) { // Zend_Controller_actions methods name must be formatted like this "exampleAction".
            $action = substr($methodName, 0, strlen($methodName) - 6);
            $script = $this->getViewScript($action);
            if(!$this->checkScript($script)){
            	throw new Zend_Controller_Action_Exception(sprintf('Pages Action script "%s" does not exist and was not trapped in __call()', $script), 404);
            }
        }else{
            throw new Zend_Controller_Action_Exception(sprintf('Illegal action name "%s" was called and not trapped in __call()', $action), 500);
        }
    }
}

Get powerful word processor with Ubuntu

In some cases you don’t need the monolith office software suite , you need only good word processor software that have best of your current editor futures .

It’s called AbiWord and you install it via Ubuntu’s Synaptic Package Manager , it will cost you something like 25 MB of your hard drive , it’s operable with common word processing software formats like Microsoft Word , Word Perfect , Open Office , Html files and many more and has plenty of most required word precessing futures.

HowTo: set sun’s java enabled on Ubuntu

In order to enable sun’s java after installation through synaptic check list of ubuntu’s java alternatives :

1
sudo update-java-alternatives -l

You should get something like this :

1
2
java-1.5.0-sun 53 /usr/lib/jvm/java-1.5.0-sun
java-gcj 1042 /usr/lib/jvm/java-gcj

Now enable your preferred java alternative :

1
sudo update-java-alternatives -s java-1.5.0-sun

Ensure that it’s enabled :

1
2
3
4
:~$ java -version
java version "1.5.0_16"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b02)
Java HotSpot(TM) Client VM (build 1.5.0_16-b02, mixed mode, sharing)

Send an email with Zend_Mail using Gmail’s smtp services

SSL support on your http server must be enabled .
Before you continue , in php.ini used by your http server enable openssl extention and restart the http server .

Now in your application bootstrap file use next code snippet :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
try {
 
$config = array('auth' => 'login',
          'username' => 'your@gmail.com',
          // in case of Gmail username also acts as mandatory value of FROM header
          'password' => 'gmail_password','ssl' => 'tls','port' => 587);
 
          $mailTransport = new Zend_Mail_Transport_Smtp('smtp.gmail.com',$config);
          Zend_Mail::setDefaultTransport($mailTransport);
          // defines gmail smtp infrastructure as default for any email message originated by Zend_Mail.
 
} catch (Zend_Exception $e) {
         // Here you can log an Zend_Mail exceptions</strong>
}