Priority of PCB lines routing

Here is an order I think is a good practice to route lines on a Printed Circuit Board (PCB).

1) Differential lines and other very important signals
2) Multiple parallel signals (such as those coming from a CMOS camera)
3) Long distance signal lines
4) Short distance signal lines (let’s say from one Resistor to the other)
5) Power lines
6) Ground lines

The first is the most important while the last in the least important.

Jan27

Update a Twitter status using Zend_Service_Twitter

$access = new Zend_Oauth_Token_Access();

$access->setToken('TOKEN')
	->setTokenSecret('SECRET');
	
$params = array(
	'username' => 'Promo_City',
	'accessToken' => $access,
	'consumerKey' => 'CONSUMER KEY',
	'consumerSecret' => 'CONSUMER SECRET'
);
	
$twitter = new Zend_Service_Twitter($params);
$result = $twitter->statusUpdate('Hello world!');

You will find all tokens when registering for an API developper key.
The TOKEN/SECRET pair is in the “My Access Token” section while the CONSUMER KEY/SECRET is in the “Application details” of the app (under “OAuth 1.0a Settings”).

Jan16

Zend Pdf merge two PDF in PHP

With the 1.11 release of the Zend Framework, we are finally able to merge different PDF documents into one. Here is how to proceed to fusion PDF1 and PDF2:

1) Create a PDF by loading PDF1

$pdf1 = Zend_Pdf::load(pdf1.pdf'); 	

2) Create a second PDF object with PDF2 in it

$pdf2 = Zend_Pdf::load(pdf2.pdf'); 

3) Load PDF Resource Extractor

$extractor = new Zend_Pdf_Resource_Extractor();

4) Use PDF Resource Extractor to extract the info from PDF2 (only page per page, here page 1)

$pdf2_content = $extractor->clonePage($pdf2->pages[0]);

5) Add PDF2 (page 1) into PDF1

$pdf1->pages[] = $pdf2_content;

That’s it! You now have PDF2 in PDF1. If PDF2 has more than one page, just repeat step 4) and 5) for ever page.
An example is also shown here (under page cloning): http://framework.zend.com/manual/en/zend.pdf.pages.html

Dec19

Generate a random letter in PHP

The easy-to-understand way:

function randomLetter()
{
    $int = rand(0,51);
    $a_z = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $rand_letter = $a_z[$int];
    return $rand_letter;
}

The geeky, very efficient way:

function randomLetter(){
  return chr(97 + mt_rand(0, 25));
}

Oct24

A PHP VAT validation module for Zend_Validate

Here is a simple way to validate VAT / TVA numbers from Europe Union (EU) countries using Zend_Validate.

Please feel free to comment!

<?php
class My_Validate_VAT extends Zend_Validate_Abstract
{
    const VAT_LENGTH = 'VATLength';
    
    private $locale = null;
    private $VAT_min = null;
    private $VAT_max = null;
    
    public function __construct(){
        $this->locale = Zend_Registry::get('Zend_Locale');
    }
    
    protected $_messageTemplates = array(
        self::VAT_LENGTH    => "The VAT code length is incorrect",
    );
    
    private function setLength(){
        switch($this->locale->getRegion()){
            case 'FR': $this->VAT_min = 13; $this->VAT_max = 13; break;
            case 'BE': $this->VAT_min = 11; $this->VAT_max = 12; break;
            case 'CH': $this->VAT_min = 0; $this->VAT_max = 12; break;
            case 'DE': $this->VAT_min = 11; $this->VAT_max = 11; break;
            case 'UK': $this->VAT_min = 5; $this->VAT_max = 14; break;
            case 'NL': $this->VAT_min = 14; $this->VAT_max = 14; break;
            default: $this->VAT_min = 10; $this->VAT_max = 15; break;
        }    
    }
    
    /**
     * Defined by Zend_Validate_Interface
     *
     * Returns true if and only if $value is a valid IP address
     *
     * @param  mixed $value
     * @return boolean
     */
    public function isValid($value)
    {
        $this->setLength();
        $length = new Zend_Validate_StringLength($this->VAT_min, $this->VAT_max);
        
        $filter = new Zend_Filter_Alnum();
        $VAT = $filter->filter($value);
        
        if($length->isValid($VAT) and substr($VAT,0,2) == $this->locale->getRegion()){
            return true;    
        } else{
            $this->_error(self::VAT_LENGTH);
            return false;
        }
        
        return true;
    }

}

Sep24

MySQL database dump / upload

Another very useful thing I need all the time to backup / upload a database:

To dumb and save as a file:
mysqldump -h hostname -u user –password=password databasename > filename

To restore the database in the MySQL server:
mysql -h hostname -u user –password=password databasename < filename where filename is for example 2010.sql Blog

Sep13

A simple way to initiate Zend_Mail configuration automatically

You simply extend the Zend_Mail class and:

Class My_Mail extends Zend_Mail {
  public $_transport = null;

  public function setup() {
  
    $config = array('auth' => 'login', 'username' => 'yourmail@here.com', 'password' => 'password', 'ssl' => 'tls', 'port' => 25);

    $transport = new Zend_Mail_Transport_Smtp('your.provider.smtp', $config);
    Zend_Mail::setDefaultTransport($transport);
 }
} 

Then:

$mail = new My_Mail();
$mail->setup();

Sep13

Welcome

Welcome to my new blog about geek stuff that you really want to know.

Whether I am going to talk about technology, science or entrepreneurship, this blog will be dedicated to notes that might interest you. For me, it is going to be a depository for various thoughts I have when working on my projects: Internet, Software, Hardware, etc. Whenever I’ll find somthing interesting, I will post it here.

So stay in touch with my blog and see you soon!

Mike

Sep12