Uploading huge files (i mean huge ones, like 5Gig and upwards). No PHP :P

Filed Under (General) by Wenbert on 27-05-2008

Tagged Under : , ,

Okay, here is an interesting find.

Although I have never had a client who asked me to upload files larger than 10MB :P , i have always wondered if there was a better way to do it without using PHP. The biggest file I was able to handle using PHP was zipping a directory with lots of files. The zip file created is about 2Gig. PHP ate up a lot of memory! It gobbled up the 4gig ram of the server :P But I found a way around it by using system() calls. I got the list of directories and ran tar inside the system() call. Worked like a charm.

Now back to the large file uploads, the post recommends using Tramline - but I have doubts because it is still in its earl stages. Does know of other solutions to uploading huge files aside from using Tramline?

Bored.

Filed Under (General) by Wenbert on 27-05-2008

Tagged Under :

Booklet Creator :)

Filed Under (General) by Wenbert on 23-05-2008

Tagged Under :

http://bookletcreator.com/ There!

A Simple Recommendation System in MySQL

Filed Under (General) by Wenbert on 23-05-2008

Tagged Under : ,

I am posting this because I know I will need this soon or later.

I have built a simple recommendation for one of the websites I work with. It is only based on social relationships and does not take into account other parameters. The basic idea is if I like an item, select other items liked by people who also like this item and it can be used to build lists of similar items as seen on Amazon or YouTube. If we use as an example people who like movies (tables Person, Movie and many-to-many relationship PersonMovie), this can be expressed in SQL using several joins:

  1.  
  2. SELECT DISTINCT Movie.*, COUNT(Person.ID) AS PersonCount
  3. FROM Movie
  4. JOIN PersonMovie ON Movie.ID = PersonMovie.MovieID
  5. JOIN Person ON PersonMovie.PersonID = Person.ID
  6. JOIN PersonMovie AS PersonMovie1 ON Person.ID = PersonMovie1.PersonID
  7. JOIN Movie AS Movie1 ON PersonMovie1.MovieID = Movie1.ID
  8. WHERE Movie1.ID = 1 AND Movie.ID != Movie1.ID
  9. GROUP BY Movie.ID
  10. ORDER BY PersonCount DESC
  11.  

First we join movies to people and then backwards to the specific movie with ID = 1 that we want to get similar movies for. PersonCount is the relevance factor — the higher it is, the more people like the movie.

Morph Exchange to offer PHP

Filed Under (General) by Wenbert on 22-05-2008

Tagged Under : , , , ,

Morph Exchange brought by Mor.ph is “Software as a Service” company that provides applications spaces/platforms for Ruby on Rails and just recently Java. A few weeks back, I emailed them if they have support for PHP. And guess what, they have plans. But they did not give me a specific time when the release date will be — no month, no date, no year — they just said that they will.

But my sources tell me that Morph will release PHP support early next year. Next year is such a long wait! They better come up with PHP support faster or else (*ahem* maybe)  Heroku will beat them to it. PHP has such a wide user-base that whoever comes up with something for it like RoR appspaces in Morph will have lots of users jumping into their band-wagon. Most advanced PHP developers are not satisfied with shared-hosting shit. We want appspaces and SVN. Manual FTP upload is dead.

More info on Mor.ph

Zend Framework and Dojo Javascript Toolkit Partners

Filed Under (General) by Wenbert on 22-05-2008

Tagged Under : , , ,

This has been out like crazy in the PHP Community. All my RSS Feeds for PHP have like 2 or 3 links related to the ZF and Dojo partnership so you have probably heard of this post.

I have known about Dojo a few years back before MVC frameworks were going mainstream. I think Dojo was the  obvious choice for the Zend Framework Team. Dojo is very mature and it has lots of components. I have no idea how bloated it is though. Personally, I would have selected jQuery because I use it :P and second, I love it’s small size and functionality. It is about time is tag along with the others and start using Dojo too :D

Zend Framework How To: Handling checkboxes using Zend_Form and jQuery

Filed Under (General) by Wenbert on 20-05-2008

Tagged Under : , ,

I am sharing this because it took me a while to figure out how to handle checkboxes using jQuery.

First off, let us create a checkbox using Zend_Form.

  1.  
  2. class forms_CoolForm extends Zend_Form
  3. {
  4.     public function __construct($options = NULL)
  5.     {
  6.         parent::__construct($options);
  7.         $this->setName(‘cool_form’);
  8.  
  9.         $content = new Zend_Form_Element_Textarea(‘notes’);
  10.         $content->setLabel(‘Content’)
  11.                 ->setAttrib(‘class’,‘my_textarea’)
  12.                 ->setAttrib(‘id’,‘textarea_id’)
  13.                 ->addValidator(‘NotEmpty’)
  14.                 ->setRequired(true);
  15.                
  16.              
  17.         $submit = new Zend_Form_Element_Button(‘button’);
  18.         $submit->setLabel(‘Go’)
  19.                ->setAttrib(‘class’,‘my_submit’)
  20.                ->setAttrib(‘id’,’submit_id’);
  21.        
  22.         $ispublic = new Zend_Form_Element_Checkbox(‘is_public’);
  23.         $ispublic->setLabel(‘Allow anyone to view this post?’)
  24.                  ->setAttrib(‘id’,‘is_public’);
  25.  
  26.         $this->addElements(array($content, $ispublic, $submit));
  27.     }
  28. }
  29.  

The code for the Zend_Form_Element_Checkbox above will generate something like this:

  1.  
  2. <input type="checkbox" value="0" id="is_public" name="is_public"/>
  3.  

Notice that the value is always Zero? Usually, in jQuery, we get used to getting the value of inputs using:

  1.  
  2. $(‘#is_public’).val();
  3.  

With that we can do all sort of things. But .val() will always return “0″. So the trick is, you need to check if the checkbox is “Checked” using something like this:

  1.  
  2. if($(‘#is_public’).is(‘:checked’)) {
  3.     temp_public = ‘yes’;
  4. } else {
  5.     temp_public = ‘no’;
  6. }
  7. //then you send temp_public to other functions — AJAX stuff or DOM modification
  8.  

That’s about it. Basically it just the .is() in jQuery.

Zend Framework How To: Creating your own validator for confirm passwords and emails

Filed Under (General) by Wenbert on 14-05-2008

Tagged Under : , ,

Last night I was working on the registration page of my pet-project. I am using Zend_Form for it but I had difficulties creating a validator to confirm 2 fields in the form. I chatted around #zftalk and checked the ZF Documentation but I could not understand anything. I needed a concrete working example.

Today I found this. It has more or less a complete coverage with sample source-code and some explanation.

My “register user” form consists of four elements:

  • Email
  • Confirm email
  • Confirm password
  • Password

Exactly what I was looking for ;)

Very nice syntax highlighting for Aptana

Filed Under (General) by Wenbert on 10-05-2008

Tagged Under : ,

I found this really nice syntax highlighting for Aptana — its called Green Chaud. The color is similar to Zenburn for Vim.

It’s been a few months since I planned to make public my Aptana color theme. After the lasts tweaks, here it is, the “Green Chaud” Aptana color theme !

It’s a light on dark theme, which is easier on the eyes than the standard theme.

PHP: Ternary Operator

Filed Under (General) by Wenbert on 07-05-2008

Tagged Under : ,

This is one my favorites. Sometimes I use this when I come around “short” conditions in variable assignments.

Instead of writing something like this:

  1.  
  2. if (isset($myvar)) {
  3.     $temp = $myvar;
  4. } else {
  5.     $temp = ""; //i need to set this so that when I echo this, it won’t show a warning
  6. }
  7.  

I just use the ternary operator to make things easier to read by doing something like this:

  1.  
  2. $temp = isset($myvar)?$myvar:"";
  3.  

Now how does it work? Basically, the syntax of the ternary operator is:
(condition)?“execute when true”:“execute when false”
On first glance it is confusing to use, but trust me, once you get the hang of it, you won’t be able to live without it.