Archive for the 'HowTo' Category

What is - Gmount-ISO


Why burn a disk when you could mount it? and who wants to remember such command to mount an ISO image

  1. mount -o loop -t iso9660 file.iso /mnt/test

not to mention the long list of mount parameters.

Well, I do want to remember such command but I don’t mind having an easy cool tool to mount ISO images.

Gnome ISO Mounter (Gmount-ISO) is a tool that ease for Desktop users the CD Image files (ISO) mounting/unmounting .

Gnome ISO Mounter (Gmount-ISO) package is available under Ubuntu 7.10 repository

  1. Package: <a href="https://launchpad.net/gmount-iso/">gmountiso</a>
  2. State: installed
  3. Automatically installed: yes
  4. Version: 0.4-0ubuntu2
  5. Priority: optional
  6. Section: universe/utils
  7. Maintainer: Ubuntu MOTU Developers
  8. Uncompressed Size: 168k
  9. Depends: python, python-central (>= 0.5.8), python-glade2, python-gtk2
  10. Suggests: nautilus
  11. Description: This is Gmountiso, a PyGTK GUI to mount your cd images
  12.  Gmount-iso is a small tool written using PyGTK and Glade. It allows you to easily mount your cd images. This is a frontend to the 'mount -o loop -t iso9660
  13.  foo.iso /mountpoint' command
  14.  
  15.  Homepage: http://www.crans.ens-cachan.fr/Syst%C3%A8meLinux/GmountIso

and can be easily obtained with aptitude.

  1. sudo aptitude install gmountiso

Wish you a very happy mounting

Tags: , , , , , , , , , , , , , , , , , , ,

Posted on Friday, December 28th, 2007
Under: HowTo, Linux, Software, ubuntu | No Comments »

Get it now and sync it later


Couple of days a friend of mine asked me to recommend a Linux distribution that would play nicely with his old laptop so as usual I recommended Ubuntu to him but I told him to wait couple of days until they release Feisty and that because he have 256 ADSL line but now with this tip he can get it now and sync it later!

Thanks to ubuntu blog for their nice tips and tricks.

UPDATE: Ok, Ubuntu blog removed that post because excessive load caused by rsyncing users would kill the rsync server

Tags: , , , , , , , , , ,

Posted on Wednesday, April 18th, 2007
Under: HowTo, Linux, ubuntu, unphpized | 1 Comment »

Postfix options


Last week I got call from one of my colleagues complaining about the amount of spam she’s receiving, so I installed SA and implemented some restricted options in postfix

  1. smtpd_recipient_restrictions =
  2.         permit_sasl_authenticated,
  3.         permit_mynetworks,
  4.         reject_unauth_destination,
  5.         reject_invalid_hostname,
  6.         reject_non_fqdn_hostname,
  7.         reject_non_fqdn_sender,
  8.         reject_rbl_client list.dsbl.org,
  9.         reject_rbl_client cbl.abuseat.org,
  10.         reject_rbl_client, dnsbl.sorbs.net,
  11.         reject_rbl_client spam.dnsbl.sorbs.net,
  12.         reject_rbl_client korea.services.net,
  13.         reject_rbl_client zen.spamhaus.org,
  14.         reject_rbl_client pbl.spamhaus.org,
  15.         reject_rbl_client sbl.spamhaus.org,
  16.         permit

but later she called complaining that she cannot send emails using our SMTP server so for me it was what the hell is going one? later I found that Postfix is picky about the order of your options so if you do reject_non_fqdn_hostname before permitting sasl authenticated users, those authenticated will not be able to send emails.

and this was new to me.

Tags: , , , , , , , , , , , ,

Posted on Tuesday, February 13th, 2007
Under: Code, HowTo, Linux | No Comments »

Testing your code


Perhaps no other coding practice is as important as testing your code. Also in the nature of Business Development, where parts of your code always change on the request of a client (including Management), or even when you want to make your code run with better performance, Automated tests are highly needed, you can’t just spread your print statements all over your code every time you need to test it.
With automated tests, you can just be sure that your interface is not broken after some change, you just run your tests, if they succeed, you know that you didn’t break your code (this means you should right good tests).
Let’s start by a simple example, Imagine that we have been asked to test PHP’s built-in Array. One bit of functionality to test is the function sizeof(). For a newly created array we expect the sizeof() function to return 0. After we add an element, sizeof() should return 1. (I know it’s not a big deal, but it’s just an example).
you can do it with simple print statements (i.e. print (1 == sizeof($myArray) ? "OK":"Failure").PHP_EOL; ), but here we are going to do it by using an assertion function.

  1. < ?php
  2. $fixture = Array();
  3. assertTrue(sizeof($fixture) == 0);
  4.  
  5. $fixture[] = "element";
  6. assertTrue(sizeof($fixture) == 1);
  7.  
  8. function assertTrue($condition) {
  9.   if (!$condition) {
  10.     throw new Exception("Assertion failed.");
  11.   }
  12. }
  13. ?>

Well, we could know if something went wrong if some Exception was raised, of course assertTrue is not the only thing you want to do, UnitTesting has gone far beyond that, usually UnitTesting frameworks provide a whole lot of features that you need for your testing.
Lot’s of Testing frameworks are available for PHP, I’m going to point to 2 of them, the first one is SimpleTest (http://simpletest.org/), it’s written in PHP 4 (Although they are going to migrate to PHP 5 when they reach version 2), so you can use it on both PHP 4 and 5 programs, also it includes a nice HTML reporter for some good looking html results the same test above could be written using this framework as:

  1. < ?php
  2. require_once 'simpletest/unit_tester.php';
  3. require_once 'simpletest/reporter.php';
  4.  
  5. class TestingFixtureArray extends UnitTestCase {
  6.   function TestArray() {
  7.     $this->UnitTestCase("Testing Fixture Array");
  8.     $fixture = Array();
  9.     $this->assertTrue(sizeof($fixture) == 0);
  10.  
  11.     $fixture[] = "element";
  12.     $this->assertTrue(sizeof($fixture) == 1);
  13.   }
  14. }
  15.  
  16. //run the Test
  17. $test = new TestingFixtureArray();
  18. $test->run(new HtmlReporter());
  19. ?>

Another Well know testing framework is known as PHPUnit2 (http://www.phpunit.de/), it’s available through the PEAR Repository, you can install it as
$ pear install PHPUnit2
It’s written in PHP 5, and is so widely used within PHP Developers, a good resource for learning how to use it is the free available online book PHPUnit Pocket Guide (http://www.phpunit.de/pocket_guide/index.en.php), the same example could be:

  1. < ?php
  2. require_once 'PHPUnit2/Framework/TestCase.php';
  3.  
  4. class ArrayTest extends PHPUnit2_Framework_TestCase {
  5.   public function testNewArrayIsEmpty() {
  6.     // Create the Array fixture.
  7.     $fixture = Array();
  8.  
  9.     // Assert that the size of the Array fixture is 0.
  10.     $this->assertEquals(0, sizeof($fixture));
  11.   }
  12.  
  13.   public function testArrayContainsAnElement() {
  14.     // Create the Array fixture.
  15.     $fixture = Array();
  16.  
  17.     // Add an element to the Array fixture.
  18.     $fixture[] = 'Element';
  19.  
  20.     // Assert that the size of the Array fixture is 1.
  21.     $this->assertEquals(1, sizeof($fixture));
  22.   }
  23. }
  24. ?>

and you can run it on command line as
$ phpunit ArrayTest

Additional benefits that you can realize by thoroughly testing your code:

  • Testing forces you to write code that is easily testable. This leads to looser coupling, flexible designs, and good modularity.
  • Writing tests forces you to explicitly clarify your expectations of how your code is to behave, distilling your design into sharper focus from the beginning. Writing tests forces you to consider the universe of possible inputs and the corresponding results.
  • Tests are very explicit way of communicating the intent of your code. In other words, test cases act as example and documentation, showing exactly how a given class, method, or function should behave. A test case defines how code works in a non-ambiguous way.

Finally, if your test suite - your set of test cases - is very thorough, you can say your code is complete when all of your test pass. Interestingly, that notion is one of the hallmarks of Test Driven Development.
Test Driven Development (TDD), also referred to as Test First Coding, is a methodology that takes testing one step further: you write your tests before you ever write any code. A nice, brief summary of the tenants of TDD is available at http://xprogramming.com/xpmag/testFirstGuidelines.htm, and a good introductory book on the strategy is “Test Driven Development: By Example” by Kent Beck. (The book’s examples are in Java, but it’s a quick read and gives you a very good overview and introduction to the subject.)

Agile Development
Recently, unit testing - in particular Test Driven Development - has been associated with agile Development methodologies such as Extreme Programming (XP)g that focus on rapid iterations of releasing functional code to customers and welcoming changing customer requirements as a natural part of the development process. Some good online resources for learning about agile development include:

Tags: , , , , , , ,

Posted on Tuesday, December 12th, 2006
Under: Code, HowTo, PHP | 8 Comments »

Advanced Caching Technique - Block Randomization


Introduction

I’m currenlty working on a site where I want to improve performance of dynamic pages. One of the greatest techniques to do is to cache dynamic content and serve the generated output (HTML).

It’s not as easy as we all want it to be when you have all sorts of weird blocks on the page: User login area, random content, ..etc

As I had a very pleasent experience with eZ components last week, I decided to take a look at the components, but then i remembered it works on PHP5. This project is on PHP4, I had to look for an alternative and decided to use PEAR::Cache_Lite.

Read the rest of this entry »

Posted on Monday, August 21st, 2006
Under: Code, HowTo, PEAR, PHP | 3 Comments »