2011 In Review

According to WordPress, I wrote a total of 190 posts in 2011. To see all the articles written in 2011, simply access:

http://ulyssesonline.com/2011/

This feature is possible using one of the nicest features in WordPress called permalinks, which is short for permanent links. With permalinks, you can customize your own URL structure the way you want it. I happen to use this format:

http://ulyssesonline.com/%year%/%monthnum%/%day%/%postname%/

which makes it easier for me to display articles by year, month and day. To access all articles written in 2011, I just provide the year and all articles written in 2011 will be displayed. Most WordPress users already use permalinks.

If you are not, do it early. Over the years, you’ll see the benefit of using such a structure.

Resize Images Using CSS

This is an older CSS trick that is worth repeating. Back in the days, resizing images was done via HTML height and width options. Here’s an example below. We will resize the image to 100 x 100 pixels.

HTML

<img src="example.jpg" width="100" height="100" alt="example" />

The problem with this approach is, first, we will lose image quality when resizing regardless of which direction we go, either up or down. The resized image is never going to be as good as the original. Second, there’s a good chance the image will NOT be proportioned. We have to be constantly be aware of image ratios when resizing images.

CSS

So, here comes CSS to the rescue. We will assign a class called “image” to our image.

<img class="image" src="example.jpg" alt="example" />

Next, we will apply CSS to our “image” class.

.image { width: 400px;height : auto; }
.image { width: auto;height : 600px; }

The result is, a well-porportioned image that is never going to be wider than 400px or taller than 600px. In addition, we maintain the standard dimension for all images using the “image” class.

CodeIgniter Form_Dropdown

I had a little problem using CodeIgniter’s form_dropdown the other day. Form_dropdown produces an output similar to HTML’s form select option. I was trying to retrieve data queried from a database and display the result in a form. Well, after several test and trials, I finally got the script to work. Here’s how I did it.

Form_Dropdown

The form_dropdown function typically has 3 options. The first option is the fieldname. The second option is the option data usually laid out in an array. The third is the selected data.

form_dropdown(‘name’, array(1?=>’one’,2?=>’two’,3?=>’three’),1);

This produces:

<select name=’name’>
<option value=”1? selected=”selected”>One</option>
<option value=”2?>Two</option>
<option value=”3?>Three</option>
</select>

CodeIgniter

In CodeIgniter, I have a simple script that stores bookmarks. I categorize my bookmarks using tags. When adding bookmarks, I call on the get_dropdown_tags function in Models to retrieve all the tags and display them in array that I can use with form_dropdown. Here are my CodeIgniter entries.

Controller:

$data['tags'] = $this-&gt;links_model-&gt;get_dropdown_tags();

Models:

function get_dropdown_tags() {
  $tags = $this-&gt;db-&gt;query('select distinct tag from links');
  $dropdowns = $tags-&gt;result();
  foreach ($dropdowns as $dropdown) {
    $dropdownlist[$dropdown-&gt;tag] = $dropdown-&gt;tag;
  }
  $finaldropdown = $dropdownlist;
  return $finaldropdown;
}

Views:

In views, I’m simply calling the form_dropdown function using the $tags array passed on by the controller. It’s a pretty neat way to recall data from a database and outputting them in form_dropdown.

<?=form_dropdown(‘tag’,$tags);?>

Finally, a dropdown list that works.

Aptana Studio 3

I finally took the plunge and downloaded Aptana Studio 3. Aptana is an open-source IDE or integrated development environment for web developers. The IDE supports all the latest web technologies including HTML5, CSS3, JavaScript, Ruby, Rails, PHP and Python.

It’s impressive despite having only a couple of hours playing with it. I really like the ‘code assist’ feature that comes with the IDE. I haven’t use all the features yet, but the deployment wizard, git integration, and the built-in terminal, sounds very, very inviting.

The learning curve isn’t steep. It’s just the right level for someone who may be tempted to try using an IDE. Aptana reminds me of Eclipse and a little bit of Textmate. The program does require Java, which my Ubuntu desktop already has installed.

Some people had issues with Git commits and some complaints about the program being resource hungry. I can’t comment on those yet since I’ve only been using it for a couple of hours. My first impression of Aptana Studio 3 is very good.

Str_replace

The str_replace function in PHP, is similar to the find and replace function that you’ll find in most text editors. Microsoft Word, Google Docs, Notepad, WordPad, Gedit, and a gaggle of other text editors, all have the find and replace function. It’s a very neat feature that comes in very handy when doing wholesale changes to a document.

In PHP, I use the str_replace function mostly to filter unwanted characters, like commas, quotes, etc from a certain string. The string can originate from a form or database. It doesn’t really matter. In this example, I have a string called $a. I will use the str_replace function to search for a word ‘foo’ and replace it with the word ‘bar.’

Replace Foo With Bar

$a = 'foo, is a great word.';
$b = str_replace('foo', 'bar', $a);
echo $b;

The result: ‘bar, is a great word.’

Remove Commas

$a = 'foo, is a great word.';
echo $b = str_replace(',', ' ', $a);

The result: ‘foo is a great word.’

Notice I used a shortcut to echo the string $b, while assigning to it the str_replace function. You can use str_replace to filter and replace a character, a word or a group of words from within a string.

FIFA 12

Last night, I finally received in the mail, FIFA 12 for the Xbox 360. I ordered it through Amazon since it was $10 cheaper. Shipping was free, but I have to wait 5-7 days for it.  It was worth it. I think.

One the reasons I bought this game was, because EA turned off the online servers for FIFA 10. I can no longer play online games, which takes the fun out of it. So, on to the next release, or two.

I went with FIFA 12. I never considered buying FIFA 11, because I think it nuts to buy the same game every year. Plus the older games are usually supported for a minimum of 2 years.

I probably missed out on all the fun with FIFA 11, but I’m all caught up now. I think. FIFA 12 needs some serious relearning on my part. Playing defense is an entirely different game. You can no longer call for help on defense as much with FIFA 10.

The animation is great. The players moves are more realistic than previous versions. The wild celebrations after a goal is a little overdone. Rooney keeps on getting caught up inside the goal netting, like a shark caught in a fisherman’s net.

Overall, I like the game. It will take a little use to get better with this game. Playing online will come later, when I get better.

Problem With CodeIgniter Form_Radio

I was trying out CodeIgniter’s Form Helper the other day. I came across one issue with form_radio. I could not get the submitted results to display properly. I’m using radio buttons to show a priority with a range that goes from 1 to 5. I tried several suggestions from the CodeIgniter’s Forum, but none of them seem to work. This article discusses an alternative way to get form_radio to display submitted data properly.

First of all, let’s go through the basics.

The Basics

To load CodeIgniter’s Form Helper, we will add this code to our controller.

$this->load->helper(‘form’);

Once the form helper is loaded, we can now start using the built-in functions like:

echo form_open(’email/send’);

which is similar to:

<form method=”post” action=”http:/example.com/email/send” />

Form_Radio

Here’s the form_radio function:

echo form_radio(‘var’, ‘1’, TRUE);

Which is similar to:

<input type=”radio” name=”var” value=”1″ checked=”checked” />

My Code

echo form_radio(‘var’, ‘1’, set_radio(‘var’, ‘1’));
echo form_radio(‘var’, ‘2’, set_radio(‘var’, ‘2’));
echo form_radio(‘var’, ‘3’, set_radio(‘var’, ‘3’));
echo form_radio(‘var’, ‘4’, set_radio(‘var’, ‘4’));
echo form_radio(‘var’, ‘5’, set_radio(‘var’, ‘5’));

But, this code doesn’t seem to display the submitted value properly.

Suggestions

Here’s a couple of suggestions from the User Guide:

echo form_radio(‘var’, ‘1’, set_radio(‘var’, ‘1’));

Or

<input type=”radio” name=”var” value=”1″ <?php echo set_radio(‘var’, ‘1’, TRUE); ?> />

Both examples didn’t work for me. I ended up using the code below.

Solution

By the way, the variable “$row->var” is the submitted data.

<input type=”radio” name=”var” value=”1″ <?php if ($row->var==’1′) echo ‘checked=”checked”‘; ?> />1

I could use a ternary as well …

<input type=”radio” name=”var” value=”1″ <?php echo ($row->var==’1’) ? ‘checked=”checked”‘ : ”; ?> />1

Final Code

Here’s my final code.

<input type=”radio” name=”var” value=”1″ <?php if ($row->var==’1′) echo ‘checked=”checked”‘; ?> />1
<input type=”radio” name=”var” value=”1″ <?php if ($row->var==’2’) echo ‘checked=”checked”‘; ?> />2
<input type=”radio” name=”var” value=”1″ <?php if ($row->var==’3’) echo ‘checked=”checked”‘; ?> />3
<input type=”radio” name=”var” value=”1″ <?php if ($row->var==’4’) echo ‘checked=”checked”‘; ?> />4
<input type=”radio” name=”var” value=”1″ <?php if ($row->var==’5’) echo ‘checked=”checked”‘; ?> />5

The end result is, only one radio button is selected based on submmited data. There is nothing like using some old-fashioned PHP and HTML markup to display submitted data properly.

The Reasons Why I Dont Use Internet Explorer

Every now and then, I use Internet Explorer just to see how an application behaves with the dreaded browser from Microsoft. The results at times are surprising, to say the least. Using IE usually involves using Windows, which I don’t use that often. But, I have my old, trusty Windows XP, running in Virtualbox.

Inside Windows XP, I have a slightly older Internet Exporer 7. I want to upgrade to IE9, but there is a slight problem. When I headed over to Microsoft’s website, I learned that I can’t run IE9 on Windows XP. Microsoft suggests that I upgrade to Windows 7. No thanks. So, the best I can do with this Windows XP, is go with IE8. I guess I can do that, but I need another computer to test IE9.

In the meantime, I decided to blog just a little. I logged in to WordPress using IE7. Guess what? WordPress complained that I’m using an insecure browser the moment I logged in to the WordPress Dashboard. The message is right up there on top of the page, inside a bright red background. You can’t miss it.

So, I decided to write a quick blog, and then the unimaginable happened. The IE7 browser disappeared. It’s gone in a puff of smoke, right before my eyes. Where did it go? It crashed! It’s a good thing, I pressed ‘Save Draft’ just moments before its disappearance. So, now I’m using Google Chrome to complete this post.

Oh, what fun. And I still have to test that dreaded application with IE7, IE8 and IE9. I can’t wait what’s in store for me.

USB Devices Unavailable in Virtualbox

If your USB device is not available in a virtual machine within Virtualbox, the most likely culprit is that you have a permission problem. You can easily fix this by adding your username to the ‘vboxusers’ group. You can do this by launching System > Administration > User and Groups. Click Manage Groups. Find the ‘vboxusers’ group. Make sure to check the checkbox to add your username to the ‘vboxusers’ group.

If you prefer the Terminal, you can run the command:

sudo usermod -a -G vboxusers username

You will need to restart your computer and rerun Virtualbox. Launch your virtual machine again. Your USB device should now be available for usage. Cool beans.

Boot Virtualbox From ISO

There are many advantages to having Virtualbox. One such advantage is having the ability to try out any Linux distro that you want, without deleting or touching one file or program on your Desktop computer. You can keep your desktop environment intact, and at the same time, play with a brand new Linux distro.

Trying out a new distro usually requires downloading the ISO from a project’s website, whether it’s from Ubuntu, Fedora, Linux Mint or openSuse. This whole process can get tedious after a while, not to mention all the wasted CDs and DVDs, each time a new distro comes out.

There is a way where you can avoid burning CDs and DVDs, and still be able to install a new Linux distro in a Virtualbox. So, instead of booting a distro from a CD or DVD drive, you will have to tell Virtualbox to boot from a virtual disk file or ISO.

Let’s say, you created a brand new virtual machine. You go through the process of assigning the appropriate resources, e.g. CPU, RAM, diskspace, etc. Once you are done, you will be asked to start the virtual machine.

The virtual machine, by default, looks for a bootable CD or DVD. Since you don’t have one CD or DVD on hand, it will complain that there is no bootable partition. You can now tell Virtualbox to use a virtual file instead of a CD or DVD.

You can do this by going to Devices > CD/DVD Devices > Choose a virtual CD/DVD disk file. Point it to your downloaded ISO file. Mine resides in my Downloads folder in my home directory. Here’s a snaphot of how to assign the CD/DVD drive to a virtual file.

Once you have the ISO selected, you will need to restart the virtual machine, to get it to boot from the ISO. The virtual machine should now boot with the latest distro you just downloaded. You can now proceed with the install of your latest Linux distro.