API to get screenshots of url

Just discovered a quick way to do a screenshot based on a url

http://www.websnapr.com/

They even have a cool and easy to use api!

No Comments


Hands on Usage of ZF 1.8.x

Well that was fast, new maintenance release of Zend Framework is now out! Checking out the changelog, noticed this little gem: Addition of module generation capabilities to Zend_Tool; I posted about that in my initial thoughts of ZF 1.8 post.

I started using 1.8 on a new project recently, while actual hands-on usage of the new stuff (Zend_Application, Zend_Tool) and the documentations are great, there are still some confusion with regards to how the Resource Autoloader works, there are some conflict with the quick-start tutorial from Zend and the actual reference documentation. According to the documentation, Resource Autoloader should work automatically when using Zend_Application, but according to the quick-start tutorial, you have to initialize it in the Bootstrap. Maybe i’m missing something, but I’ve decided to go with the quick-start tutorial for the time being since it works. I’ve also noticed that there are some new view helpers like ($this->cycle for one) minor stuff but very helpful!

Using Zend_Form is still an exercise in frustration, especially the decorators. I love the way symfony handles the form layouts, it just passes the form object as an array to the view layer and gets out of the way, allowing designers to actually do the form design. Zend_Form just seems counter-intuitive. They got majority of the stuff correct, but laying out the forms to display how you want them is very hard. Let the view layer handle the layout stuff, allowing the Form object to be more flexible and reusable.

,

No Comments


Apache 2: Self-Signed Certificates

Self-signed certificates are very useful when doing testing on your local machine. The following was tested using a unix based environment.

Generate the Key and Certificate

First we generate the private key


openssl genrsa -des3 -out server.key 1024

Then we create a certificate signing request


openssl req -new -key server.key -out server.csr

We make sure that everytime we start the apache server, we don’t have to type the passphrase


cp server.key server.key.org

openssl rsa -in server.key.org -out server.key

Lastly we self-sign the certificate


openssl x509 -req -days 365 -in server.csr -signkey server.key -out               server.crt

Configure the Apache Server

Edit your apache’s httpd.conf and uncomment the following lines (just search it in the file)


LoadModule ssl_module modules/mod_ssl.so

#PATH MAY DIFFER TO YOUR SETUP

Include conf/extra/httpd-ssl.conf

Next edit your apache’s httpd-ssl.conf, search for the following configuration item: SSLCertificateFile & SSLCertificateKeyFile, change it to where your server.crt and server.key files are located respectively (absolute path!)

Finally if you’re using VirtualHost it is important to declare two NameVirtualHost (one for port 80 and port 443). Example:


NameVirtualHost 127.0.0.1:80

NameVirtualHost 127.0.0.1:443

<VirtualHost 127.0.0.1:80>

ServerName local.example.com

DocumentRoot /path/to/your/example.com/www

</VirtualHost>

<VirtualHost 127.0.0.1:443>

ServerName local.example.com

DocumentRoot /path/to/your/example.com/www

SSLEngine on

SSLCertificateFile /path/to/your/server.crt

SSLCertificateKeyFile /path/to/your/server.key

</VirtualHost>

Save and restart your Apache server!

, ,

1 Comment


Thoughts on the new Zend Framework 1.8

Been playing around with the new version of Zend Framework (1.8). The command line Zend_Tools has alot of potential and is very useful for newbies, but still lacks a lot of functionality (support for modules in the command line would be pretty cool!). I loved the Application/Bootstrap approach this puts a lot of much needed structure to a very flexible framework. It also centralizes plugins to the front controller and of course custom initializations using _init methods in the Bootstrap file. Although missing in the reference documentation are examples when using a more modular approach when using the Zend_Application.

Also the quick-start tutorial from Zend’s website has been updated! It includes a very nice approach to models (much needed overhaul in the next version of ZF). Overall a very solid release from the community. Looking forward to using it in new projects.

,

1 Comment


Bash script to backup mysql database

This is the first bash script I wrote, I used crontab to periodically backup and compress a mysqldb in a shared hosting environment

#!/bin/sh
user=testdbuser
password=testdb
dbname=testdb
location=~/db_backups
ts=$(date '+%Y%m%d-%H%M')

mysqldump -u$user -p$password --opt $dbname > $location/temp-$ts.sql
cd $location
tar -cvzf $dbname-db-$ts.tar.gz temp-$ts.sql
rm -f temp-$ts.sql

,

No Comments


5 ways to pissed off your teammates

These are all speaking through experience

  1. Stubbornly kept on using deprecated code knowing that it will be remove from the code base in the next version, thereby hindering a smooth transition.
  2. Violating all of the company’s coding and naming standards making things difficult to trace for bugs when you go on leave all of a sudden!
  3. You raise a shitstorm once you find a bug in other people’s code regardless of how minor it is. While we quietly fix your mess and continue with the development, because we are already behind schedule because of your incompetence.
  4. Design patterns apparently don’t mean much.
  5. While trying to resolve SVN conflicts, you immediately resolve it using your copy without even looking what has changed that caused the conflict.

,

No Comments


Something’s cookin’

I’ve been experimenting with different ways to manage releases (major and maintenance) and this resulted in a very good solution which i’ve been using for several weeks now. This is a fantastic tool for small to medium software companies and freelancers looking for a really cheap release management software to help their clients manage the intricacies and confusion that comes with releasing a software.

Watch out for this, will be launching a beta version soon!

, ,

No Comments


Venture Diary: Initial thoughts and questions about hosting

Ever since i’ve starting working in the consulting business, and now in product development with a Fortune 20 company, i’ve always dreamt of having an online business. I’ve always hated the 8 hour grind everyday for 5 days a week, although the pay is great, but there’s something really exciting with working for yourself whether it be freelance consulting or starting an online business; creativity is the only limiting factor. The hardest part of an online business is the idea, well we all know that, once an idea has been solidified the easiest part is execution of said idea which the only limiting factor (for me) has been the lack of time.

W’ve been steadily developing some ideas right now, and we’ve also finalized the revenue stream and from the looks of things it will be very feasible. Right now i’m very much interested on how other ventures started, did they rely on shared hosting services, or did they just rolled their own solution (own hardware). From our own assessment we would be using shared hosting services until we reached a certain milestone (number of users), and from there on will be rolling our own hardware.

Post your thoughts on the matter in the comments section

,

No Comments


Zend Framework Model Based Validation Part 1

I’m not really a big fan of Zend_Form, too verbose and less flexible. I’ve been using this little base class for several of my freelance projects. It basically allows you to define validation rules for your model’s columns. This is a very basic version that I’m planning to enhance soon with custom validation functions.

Download version 0.1

USAGE EXAMPLE

Model

<?
class User extends AbstractModelValidator {
	protected $_name = 'users';
	protected $_primary = 'id';
	protected $_rules = array(
		array('name'=>'firstname', 'class'=>'NotEmpty', 'message'=>'Required Field (Firstname)'),
		array('name'=>'firstname', 'class'=>'StringLength', 'options'=>array(0, 50),'message'=>'Max length is 50 (Firstname)'),
		array('name'=>'lastname', 'class'=>'NotEmpty', 'message'=>'Required Field (Lastname)'),
		array('name'=>'lastname', 'class'=>'StringLength', 'options'=>array(0, 50),'message'=>'Max length is 50 (Lastname)'),
	);
}

Controller

<?
class UsersController extends Zend_Controller_Action {
	public function addAction() {
		$this->view->req = $this->_request;
		if($this->_request->isPost()) {
			$u = new User();
			if($u->isValid($this->_request->getParams())) {

			}
			else {
				$this->view->errors = $u->getValidationMessages();
			}
		}
	}
}

View

<html>
	<head>
		<title>Add User</title>
	</head>
	<body>
		<? if(isset($this->errors) && sizeof($this->errors) > 0): ?>
			<ul>
				<? foreach($this->errors as $e): ?>
					<li><?=$e?></li>
				<? endforeach; ?>
			</ul>
		<? endif; ?>
		<div>
			<form action="<?=$this->url()?>" method="post">
				<div>Firstname:</div>
				<div><?=$this->formText('firstname', $this->req->getParam('firstname'), array('size'=>20))?></div>
				<div>Lastname::</div>
				<div><?=$this->formText('lastname', $this->req->getParam('lastname'), array('size'=>20))?></div>
				<div><?=$this->formSubmit('submit', 'Submit')?></div>
			</form>
		</div>
	</body>
</html>

2 Comments


Simple Pagination

I use alot of Zend Framework for my freelance projects and prior to version 1.6 they have no pagination class to do the dirty work. I know what you’re thinking right now, why didn’t I just reused some of the many pagination scripts in the internet and/or in PEAR. I just really needed something simple that I can quickly reuse all over my web-app and here it is

To get the offset for your sql query just do this:

$offset = $numOfItemsPerPage * ($page - 1);

Here’s the code for the pagination, take note that the logic can be use regardless of the programming language, i’ve also use this in some of my java webapps

<?php
class Paginator {
	const NUM_TRAIL_LEAD_LINKS = 5;

	public static function generate($url, $total, $current = 1, $numPerPage = 5, $var = 'page', $separator = ' ') {
		$totalNumberOfPages = ceil($total / $numPerPage);

		$linksArray = array();
		$isFirstLinkDone = false;
		$i = 1;
		if(($current - self::NUM_TRAIL_LEAD_LINKS) > $i) {
			$i = $current - self::NUM_TRAIL_LEAD_LINKS;
		}

		for(;$i<=$totalNumberOfPages;$i++) {
			if(!$isFirstLinkDone && $current > 1) {
				$linksArray[] = '<a href="'.$url.'/'.$var.'/1">First</a>';
				$linksArray[] = '<a href="'.$url.'/'.$var.'/'.($current-1).'">Prev</a>';
				$isFirstLinkDone = true;
			}

			if($i == $current) {
				$linksArray[] = '<span style="font-weight:bold">'.$current.'</span>';
			}
			else {
				if(($current + self::NUM_TRAIL_LEAD_LINKS) < $i) {
					break;
				}

				$linksArray[] = '<a href="'.$url.'/'.$var.'/'.$i.'">'.$i.'</a>';
			}
		}

		if($current < $totalNumberOfPages) {
			$linksArray[] = '<a href="'.$url.'/'.$var.'/'.($current+1).'">Next</a>';
			$linksArray[] = '<a href="'.$url.'/'.$var.'/'.$totalNumberOfPages.'">Last</a>';
		}
		return implode($separator, $linksArray);
	}
}

2 Comments


SetPageWidth