Protect web pages with username/password

If there some web pages you want to protect with username/password, all you have to do is to create a file called .htaccess under the directory to protect with the following lines:

  1.  
  2. AuthUserFile /path/to/htpasswd/.htpasswd
  3. AuthGroupFile /dev/null
  4. AuthName "Restricted Directory"
  5. AuthType Basic
  6.  
  7. <Limit GET POST>
  8. require valid-user
  9. </Limit>
  10.  

Replace /path/to/htpasswd/ with the .htpasswd path.
Replace Restricted Directory with the text you want as title of the prompt window.

Then you have to create the .htpasswd file using the following command:

htpasswd -c .htpasswd user_name

Execute it under the directory to protect or add the full path to .httpasswd and replace user_name by the username you want to use, you will be asked to enter the password and the file will be created.

Notes: This instruction are for linux/unix systems using apache web server, the dot means hidden files on linux.

Prototype Compressed

I am a prototype user, but i want to save some bandwidth using a compressed version, so i start looking for it and i found a compressed version called
protopack it includes different versions, just spaces removed ( no eval required ), encrypted(eval required) and gziped version for both. i prefere the just spaces removed version since it dosen’t require use of eval.

Another good option is to use the Google AJAX Libraries API that serves a compressed version of prototype that will be cached by a year and sent with compression headers , you can include it using the full url or the Googles’s API

  1.  
  2. "text/javascript""http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js"
  3.  
  4. OR
  5.  
  6. "text/javascript""http://www.google.com/jsapi"
  7. "text/javascript"
  8. google.load("prototype", "1.6.0.2");
  9.  
  10.  
  11.  

You can find compressed versions of scriptaculous, jQuery, MooTools, dojo as well.
The bad thing is there are no https support so it wont work for secure sites.

Google Developer Day 2008 – Mexico City

Yesterday, Monday 23 2008 I have the opportunity to assist to the Google Developer Day Mexico City, the first two talks were about Google and the Mexican market and an overview of their new product for developers ( android, maps, open social, etc. ) this first two talks were in Spanish, after a launch it was a breakout with 4 different options, the talks i have the opportunity to go were:

  • Open Social introduction by Chris Schalk: Open Social is a technology that allow us to create applications for social networks with the advantage it will run on every platform that supports open socials ( Hi5, Orkut, IGoogle, Linkedin ) the talk was about Were Open Social is going, what can we do and what to expect from it, Google friend connect,, how to create some basic application and how to implement on our how servers.
  • IGoogle + gadgets by Bruno Bowden: IGoogle is you own personalized start page where you can add a lot of gadgets to it ( weather, jobs gmail, etc. ) This talk was about creating gadgets for IGoogle , and the new support of Open Social and the new canvas mode
  • Gears by Dion Almaer: this was the talk i like the most, i really like the idea that we can use gears to create an offline version or speed a site up like wordpress.com is doing, but when i got home and try to install gears on my machine i realized that Linux 64 bits is not supported :-(
  • Google Maps API Advanced by Pamela Fox: This talks was about using tile layers with Google maps so we can use our own maps, images or anything we want to zoom in using Google maps, right now i am using Zoomifyer for this purpose but i hope with this info move to Google maps. pretty cool!

Test your sites on IE from linux

I work all the time on Linux, but unfortunately there are some bugs that happened just for Internet Explorer so i used to reboot, test on windows, fix it, and then reboot and continue working on linux.

This process is annoying reboot, fix, test, etc. but thanks to Wine. We can install Internet Explorer on Linux, for that we can use:

IEs4Linux this script can install several versions of IE 5, 5.5, 6 even you can install IE 7 (not fully supported)

Here are some screenshots of the process and IE running

Another option is to use Wine-Doors, it’s an script that help us installing window’s software like Ares, Flash 8, Internet Explorer 6 etc.

wine-doors-3

With the previous options IE not always runs like on windows. There is another option running windows under Linux as a virtual machine for that purpose you can use virtual box, qemu, vmware.

My choose is Virtual Box Open Source Edition, here is a good tutorial on how to install it and some screenshots of my virtual box running IE6 and IE7

Virtual Box

Configure Apache to serve PERL pages ( Ubuntu )

I just reinstalled my ubuntu distribution, and have to configure apache to serve perl pages outside of the cgi-bin directory, after a little bit of googling i found the solution.

You have to edit the /etc/apache2/apache2.conf and add to it the following lines.

  1.  
  2. AddHandler cgi-script .cgi .pl
  3. <Files ~ "\.pl$">
  4. Options +ExecCGI
  5. </Files>
  6. <Files ~ "\.cgi$">
  7. Options +ExecCGI
  8. </Files>
  9.  

Stop apache showing incomplete urls

Apache was showing files even if i didn’t put the extension on the url, that behavior was messing with a mod rewrite rule i was working on. To solve this we just add the line below to the .htaccess file and that’s it apache will stop showing incomplete urls

  1. Options -MultiViews
  2.  

Show videos on your site using PERL and Youtube API

This tutorial uses an old Youtube API, after google acquired Youtube a new API was released

In this brief tutorial i will show you how to show videos from youtube on you web page using PERL and Youtube API, the idea of the script is that it will show by default the favorites videos of some users, and you will be able to navigate to the tags you specify.

For this script we will use some libraries from the CPAN:

  • CGI we will use to get the data send by GET
  • Template toolkit This is an excellent template library
  • XML:DOM this library will help us to parse the XML file that is returned by youtube
  • LWP::UserAgent This is needed by XML:DOM to parse the files in remote locations
  • Unicode::String We will use this to convert data to UTF8

Click here to see this script in action.

Download the code

index.pl this is the perl script.

  1. #!/usr/bin/perl
  2. # you have to sign up to get a developer id
  3. ‘developerid’;
  4. # we will show the favorites videos of this user as front page
  5. ‘someuser’;
  6. # this is an array of the tags we will allow to navigate throw
  7. ‘tlaxcala’=>‘Tlaxcala’,
  8.         ‘huamantla’=>‘Huamantla’,
  9.         ‘huamantlada’=>‘Huamantlada’,
  10.         ‘feria huamantla’=>‘Feria Huamantla’,
  11.         ‘cacaxtla’=>‘Cacaxtla’,
  12.         ‘apizaco’=>‘Apizaco’,
  13.         ‘tlaxco’=>‘Tlaxco’,
  14.         ‘feria tlaxcala’=>‘Feria Tlaxcala’‘action’"Content-type: text/html;charset=UTF-8\n\n"‘view’‘video’‘video’# here we start parsing the XML
  15. ‘http://www.youtube.com/api2_rest?method=youtube.videos.get_details&dev_id=FIq6LWxC3RE&video_id=’‘video’} );
  16.                 # we put this on eval to avoid errors
  17. # here i add all the commets to an array
  18. ‘comment’‘time’‘author’‘text’‘%r’‘%d-%m-%Y’, @date )
  19.                                 };
  20.                         }
  21.                        
  22.                         # here i format the video time
  23. ‘length_seconds’# here i create an array of the data i will use and show the page using template toolkit
  24. ‘video’‘title’‘author’‘rating_avg’‘tags’‘description’‘%02s:%02s:%02s’‘videos_view.tt’‘page’‘page’‘tag’‘tag’‘tag’ ) {
  25.                 # i show the favorites of the user
  26.                 $url=‘http://www.youtube.com/api2_rest?method=youtube.users.list_favorite_videos&dev_id=FIq6LWxC3RE&user=’‘page’}=‘1’‘page’);
  27.                 # here i get videos by tab
  28.                 $url=‘http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag&dev_id=FIq6LWxC3RE&tag=’‘tag’} . ‘&page=’‘page’} . ‘&per_page=20’;
  29.                 # since the api dosent support paging, i see if the next xml has data, to show next link
  30. ‘http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag&dev_id=FIq6LWxC3RE&tag=’‘tag’} . ‘&page=’‘page’} + 1 ) . ‘&per_page=20’# we put this on eval to avoid errors
  31. # here i create an array with the info for videos
  32. ‘video’‘author’‘author’‘id’‘id’‘title’‘title’‘length_seconds’‘length_seconds’‘rating_avg’‘rating_avg’‘rating_count’‘rating_count’‘description’‘description’‘view_count’‘view_count’‘upload_time’‘upload_time’‘comment_count’‘comment_count’‘tags’‘tags’‘url’‘url’‘thumbnail_url’‘thumbnail_url’‘video’‘tag’‘page’}
  33.         );
  34.         # i show the page using template toolkit
  35. ‘videos_list.tt’

videos_list.tt The template where we see the list of videos.

  1.  
  2. "videosList"
  3. [% FOREACH videos %]
  4.  
  5.   "index.pl?action=view&amp;video=[% id %]""[% thumbnail_url %]"
  6.   "index.pl?action=view&amp;video=[% id %]"[% title %]
  7.   [% description %]
  8.  
  9. [% END %]
  10.  
  11.  
  12.  
  13. "center"
  14.  [% IF tag || ( page>1 && total>0 ) %]
  15.  [% IF ( page > 1 ) %]
  16.   <a href="index.pl?tag=[% tag %]&amp;page=[% (page – 1) %]" alt="Previous" title="Previous">Previous
  17.   [% END %]
  18.   [% IF total>0 %]
  19.    "index.pl?tag=[% tag %]&amp;page=[% (page + 1) %]""Next"‘Next’Next
  20.   [% END %]
  21.  
  22.  
  23.  
  24.  [% END %]
  25.  
  26.  [% IF tag == ” %]Favorites[% ELSE %]"index.pl"Favorites[% END %]
  27.  [% FOREACH key = tags.keys %]
  28.   || [% IF tag == key %][% tags.$key %][% ELSE %]"index.pl?tag=[% key %]"[% tags.$key %][% END %]
  29.  [% END %]
  30.  
  31.  

videos_view.tt The template where we see a specific video.

  1.  
  2. [% title %]
  3.  
  4. "center"
  5. "425""350""movie""http://www.youtube.com/v/[% video %]""wmode""transparent""http://www.youtube.com/v/[% video %]""application/x-shockwave-flash" wmode="transparent""425""350"
  6.  
  7.  
  8. Author: "http://www.youtube.com/user/[% author %]""_blank"[% author %]
  9.  
  10. Rating: [% rating_avg %]
  11.  
  12. Tags: [% tags %]
  13.  
  14. Time: [% time %]
  15.  
  16.  
  17. [% description %]
  18.  
  19.  
  20. [% IF comments.size > 0 %]
  21.  Comments
  22.   [% FOREACH comment=comments %]
  23.    ‘textoComentarios’[% comment.text %]
  24.  
  25.    ‘pieComentarios’
  26.    | By ‘http://www.youtube.com/user/[% comentario.author %]’[% comment.author %] | [% comment.date %] | [% comment.time %] |
  27.  
  28.  
  29.  
  30.  [% END %]
  31. [% END %]
  32.  

WordPress 2.5

Wordpress 2.5 have been released, and i have just upgraded this blog to use this new version, i really like it! it looks a lot cleaner, includes built in gallery support, and a lot of new features that you can read
here

Wordpress 2.5

Force download in apache

if you want to force certain kind of files to pop up the save as dialog box, you have to add the AddType directive with the value application/octet-stream to the .htaccess file like this:

  1.  

and that’s all, now everything works fine