Archive

Author Archive

Grep/Find all php short tags

March 22nd, 2012 No comments
grep -rn "<?[^p]" *
Categories: Uncategorized Tags:

Reset a phpStorm project

December 5th, 2011 No comments

I had a problem upgrading to phpStorm 3.0. Needed to kill the project data, for phpStorm to reset.

$> rm -rf .idea

to clear the project data.

Categories: Uncategorized Tags:

Hosting with Apache and SVN

November 18th, 2011 No comments

I have a requirement to not serve SVN meta data with the project, once deployed on a server.

So what can I do?
Prevent Apache from serving the content:

Put an apache directive:

<DirectoryMatch .*\.svn/.*>
Deny From All
</DirectoryMatch>

 

or:

Remove all the SVN metadata altogether

While in the *nix prompt:

find . -name ".svn" -type d -exec rm -rf {} \;
Categories: Uncategorized Tags:

Mac MAMP setup

June 17th, 2011 No comments
  1. install:
    1. mysql: http://www.mysql.com/downloads/mysql/
    2. macports: http://www.macports.org/install.php
  2. run the following:
    1. $> sudo port selfupdate
    2. $> sudo port install apache2 tidy curl curl-ca-bundle php5-apc php5-curl php5-eaccelerator php5-gd php5-iconv php5-imagick php5-mbstring php5-mcrypt php5-mysql php5-soap php5-tidy php5-unit php5-uuid php5-xdebug php5-xmlrpc php5-xsl php5-zip wgetpro
    • Go for a coffee/beer now… this will take a little time.
  3. edit the following files:
    1. edit /opt/local/apache/conf/http.conf
      1. enable mod_rewrite
      2. enable http-vhosts.conf
      3. enable php5
    2. edit /opt/local/apache/conf/extra/httpd-vhosts.conf
      1. ensure that target folder is group with “staff”, and readable.
      2. note the following vhost entry, and the <directory>
      • <VirtualHost *:80>
      • ServerAdmin webmaster@dummy-host2.example.com
      • DocumentRoot “/Users/llleung/Projects/sample”
      • ServerName sample.localhost.com
      • ErrorLog “logs/sample.localhost.com-error_log”
      • CustomLog “logs/sample.localhost.com-access_log” common
      • <Directory /Users/llleung/Projects/sample>
      • Options FollowSymLinks
      • AllowOverride All
      • </Directory>
      • </VirtualHost>
        • Assumptions:
        • llleung is the user home folder
        • Projects, is where you house all the websites you want to deal with.
    3. edit /etc/hosts
      1. add custom urls referenced inside vhosts
      • 127.0.0.1 sample.localhost.com
    4. edit your ~/.profile file, to run your instances of mysql, and apachectl
      • alias mysql=”/usr/local/mysql/bin/mysql”
      • alias apachectl=”sudo /opt/local/apache2/bin/apachectl”
edit:
Had to remove eacellerator, as it was conflicting with the latest APC.
Categories: PHP Tags:

Magento DB transaction commit rollback sniplet

January 18th, 2011 3 comments

Took me a while to find out how to do this… as there was no good examples on the web.
So, here it is… so I can find it again.

keywords:
db database transaction rollback commit magento zend.

try {
    $write = Mage::getSingleton('core/resource')->getConnection('core_write');
    $write->beginTransaction();

// do stuff here

    $write->commit();
} catch (Exception $e) {
    mage::log(__METHOD__ . ':' . __LINE__ . ': Rollback happened.');
    $write->rollback();
}

Please drop a line if you found this useful. Thanks!

Categories: Uncategorized Tags:

linux find the last modified file in directory

October 22nd, 2010 No comments

ls -tr | tail -n 1

Categories: Uncategorized Tags:

Symfony 1.4 quick commands

October 8th, 2010 No comments

I always forget these commands… so I’m posting it here, so I can find them again easily.

Getting a value out of a loaded yaml config file.

[project root]/app/frontend/config/app.yml

all:
.general:
api_key: ASDFASDFASDFASDF

sfConfig::get(‘app_api_key’);
will return “ASDFASDFASDFASDF”;

Categories: Uncategorized Tags:

Build PHP 5.3.3, on centos 5.5

October 1st, 2010 1 comment

I’m assuming you have a fresh install of centos 5.5.


$> yum groupinstall "Development Tools"

$> wget http://us.php.net/get/php-5.3.3.tar.bz2/from/www.php.net/mirror

$> tar xvf php-5.3.3.tar.bz2
$> yum install mysql-server httpd-devel-* libxml2-devel-* openssl-devel* xmlsec1-openssl-devel-* libpng* libjpeg* curl-devel libmcrypt* mysql-devel* mysql.*

$> cd php-5.3.3
$> ./configure --with-mysql=shared --with-openssl --enable-pdo --with-pdo-mysql=shared --with-mhash=shared --enable-soap=shared --with-config-file-path=/etc/ --with-apxs2 --with-mysqli --enable-zip --enable-shared --with-curl --enable-mbstring=all --enable-maintainer-zts --with-jpeg-dir=/usr/lib/ --with-libdir=lib64 --enable-soap --with-pdo-mysql --with-gd --with-mcrypt

$> make; make install;

$> service httpd restart

and there you go… php 5.3.3 on the box…

Categories: Uncategorized Tags:

Check list

April 29th, 2010 No comments

[are/did] you:
1.) backed up the file
2.) backed up the RIGHT file
3.) editing the right file
4.) editing the right file on the right server/environment
5.) are you viewing cached data, or live?
6.) does the input/output validate?
7.) did you remove all exit/die statements?

If someone else looked at it, how many WTF per minute will there be?

Categories: General Programming Tags:

Reusing a edit/create form

March 5th, 2010 No comments

As a web developer, you have to deal with web forms. Why would you make a new form, and an edit form, which is basically the same.

How to handle this would be to use this design pattern:

1.) load the get item to load, if it exists. Lets call it $dataObject
2.) if $dataObject is empty/does not exist, start a new dataObject. Lets call it $dataObject
3.) dataObject is now instantiated.
4.) Do what needs to be done — for example “title” of the page, being “editing XXX”, or “new dataObject”. Whatever frontend reflections need to happen, based on if it’s new object or editing an old object.
5.) populate the form, accordingly. If the object is blank, it’ll just be populated with the default values.

6.) onSubmit()… check to see if an ID value was submitted, and the appropriate security checks, and deal accordingly. If there was no ID value, start a new dataObject, to be populated with the data submitted.

7.) $dataObject->save();

The above described is how symfony admin generator handles form reuse. While the admin generator is useful for most cases, sometimes you need to just do “more” customizations, than using the generator.

For example, you need to handle a collection of both NEW and Prior saved objects… to do batch edits, it’s easier to do it manually, instead of using the symfony-admin-generator.