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!

  • Share/Bookmark
0 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.

Continue Reading »

  • Share/Bookmark
1 Comment

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.

Continue Reading »

  • Share/Bookmark
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.

Continue Reading »

  • Share/Bookmark
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

  • Share/Bookmark
0 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.

  • Share/Bookmark
0 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!

  • Share/Bookmark
0 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

  • Share/Bookmark
0 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>

  • Share/Bookmark
3 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);
	}
}

  • Share/Bookmark
2 Comments