Zend Framework

If you need to return an image, simply return the response object filled in with the content: that will tell the Zend\Mvc\Application to entirely skip the Zend\Mvc\MvcEvent::EVENT_RENDER event and go to Zend\Mvc\Application::EVENT_FINISH

Example code:

public function displayAction()
{
    // get image content
    $response = $this->getResponse();

    $response->setContent($imageContent);
    $response
        ->getHeaders()
        ->addHeaderLine('Content-Transfer-Encoding', 'binary')
        ->addHeaderLine('Content-Type', 'image/png')
        ->addHeaderLine('Content-Length', mb_strlen($imageContent));

    return $response;
}

 

This will cause the application to direcly go to the Zend\Mvc\Event::EVENT_FINISH, which in turn is capable of sending the response to the output.

PHP Globals

PHP provides a large number of predefined variables to all scripts. The variables represent everything from external variables to built-in environment variables, last error messages to last retrieved headers.

JAVA enum example

Hi, here is a quick example for Java beginners: how to write a String enum.

File name: StringEnum.java
package test;

public enum StringEnum {
    STRING_ALPHA("APLHA"),
    STRING_BETA("BETA"),
    STRING_GAMMA("GAMMA");

    private final String value;

    /**
     * @param value
     */
    private StringEnum(final String value) {
        this.value = value;
    }

    @Override
    public String toString() {
        return value;
    }
}
REGEXP Cheatsheet

This REGEXP formula validates email addresses:

 

^[a-z0-9][_.a-z0-9-][email protected]([a-z0-9][0-9a-z-]+.)+([a-z]{2,4})

 

You can use this formula with all programming languages which supports regular expressions: : Java, PHP, Perl, Python, etc...

OS X Recovery

Mac from the recovery partition and are planning to reinstall OS X, you might be met by the following message:

An error occurred while preparing the installation. Try running again

Now, if you haven’t used your Mac for a while, the error might be caused by an incorrect system date setting. You can check this by going to utilities and opening the terminal. Once in the terminal enter the following command and hit return/enter:

date

The result of this command will be the date that the system currently has been set to. For some reason, it might have been reset to 2001, in which case we need to set it to the right date. To do this, we enter a new command. This command will be entered as follows:

date {month}{day}{hour}{minute}{year}

Every bracket should be replaced with a two-digit number. For example, March 18th 2013 12:50 would become the following command:

date 0318125013

Enter the command and hit return. You can then check if it was set correctly by running the first command again. If the date was wrong, it was likely that which caused the error, and after you quit the terminal it should be able to install OS X just fine.

Hi there, today I come with a controversial topic: the network stack optimization rules for BSD-based routers.

This topic also could be applied to GNU Linux Operating Systems as well as all the POSIX-compliant operating systems but in this article we'll imagine a freeBSD production business environment. For instance, we'll consider employing a BSD network router when we have to merge/route between many different server networks and also would be essential network firewalling for the local or the wide area network. A common BSD server could normally manage 500Mbps traffic with entry-level server hardware so it's commonly preferred against a GNU Linux server because BSD traditionally comes with enhanced network stack.