Get Your OwnCloud

There are several free cloud services available out there. Dropbox, Google Drive, Ubuntu One, JustCloud, ZipCloud, to name just  a few. They’re all great. They all have one thing in common, they store and share files and documents on the cloud.

If there’s one thing that bothers people about cloud services, it’s privacy. People worry about placing sensitive data on the cloud. How about running your own cloud? Well, get your own cloud with OwnCloud. OwnCloud is an open-source cloud software solution that you can install yourself.

You can install it on your own desktop, your server at home, your VPS server on the Internet, or anywhere there is a PC or computer. You decide where you want it. The best thing about ownCloud, no one has access to your sensitive data. Just you.

I’ve been running ownCloud for about a month now. It’s great. I am able to upload and share any files that I want, from pictures, videos and documents.  I can access these files from any computer, from any location around the world. There is no need for me to carry a USB stick anymore. All I need to do, is access my browser and access my files online.

In addition, OwnCloud allows me to play music and movies online. It organizes my pictures into galleries. It has a calendar, contacts, and a host of other applications that can be installed with just one click of a button. So, get your own cloud with OwnCloud.

Linode Kicks Ass

Get a web server running within minutes. Choose a Linux distro, resources, and node location. That’s essentially Linode in a nutshell. I signed up with Linode about two weeks ago. I’ve been playing around with it since then. I can happily say that I’m very impressed with Linode. It has exceeded my expectations.

If you want total control of your web server, Linode VPS is really the way to go. You will be asked to choose server size when you sign up. They come in many configurations. I chose Linode 512. You also need to choose a data center location. There are six data centers worldwide. I choose the one in Fremont since I live in California.

So far, I’m loving the guaranteed server resources. My websites are running faster . I chose Ubuntu 12.04 LTS 32 bit because it’s a Linux distro I am very familiar with. Apparently, 57% Linode users have chosen Ubuntu as well. I already transferred a couple of domains over to Linode. The websites are screaming.

I plan to migrate more websites later. If you are curious about how Linode works, here is a short list of features to get you started:

  • Full ssh and root access
  • Guaranteed Resources
  • 4 processor Xen instances
  • Out of band console shell
  • Dedicated IP address, premium bw
  • Six datacenters in the US, Europe, and Asia-Pacific
  • HA and Clustering Support
  • Bandwidth pooling
  • Managed DNS with API

PHPVirtualBox

PHPVirtualBox is a web-based program that allows you to control a remote Virtualbox GUI. PHPVirtualBox is ideal for systems that don’t have remote GUI access. Access is done via a browser. Remote virtual machines can be started and stopped, shutdown, and rebooted. In addition, snapshots can be taken, deleted and restored remotely via the browser. Howtoforge.com goes over the installation of PHPVirtualbox in this short article.

Validate IP Addresses in PHP

Let’s say you were given a task to validate an IP address in a custom script. One approach is to use regular expressions and use pattern matching to see if user input is correct or not. In this example, we will use a regular expression below to validate IP addresses.

We assume user input is done via a form. First things first, we need to sanitize the input. Once sanitized, we can then test the input against the regular expression using a PHP function called the ereg().

// the regular expression for valid ip addresses
$reg_ex = '/^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$/';
// sanitize input from form
$ip_address = addslashes(htmlspecialchars(strip_tags(trim($_POST['ip_address']))));
// test input against the regular expression
if (ereg($reg_ex, $ip_address)) { 
   // ip address is valid
} else {
   // ip address is not valid
}

The result is, we now have a facility to check the validity of IP addresses. We can now perform additional steps when the IP address is valid, or display errors if the IP address is invalid.

MySQL mysql_connect new_link

I want to share a database connection access problem I had last week, while working with a custom PHP script inside WordPress. I had created this WordPress Page Template containing some PHP code that needs access to the database. The problem was that the database connection for my custom script overwrote the WordPress database connection that was previously establish, causing certain parts of WordPress to not display properly.

It took me a while to figure out that it was the newer database connection of my custom PHP script that was causing the previously established WordPress database connection to disappear. Hence, certain parts of the WordPress page were not displayed. Little did I know, that the fix was quite simple. So, here’s a sample of my mysql_connect code. Prior to this line, I’ve already set the variables.

Mysql_connect

$db=mysql_connect($host,$username,$password);

The Fix

Simply add a fourth parameter called new_link and set it to TRUE.

$db=mysql_connect($host,$username,$password,TRUE);

What this does is basically telling mysql_connect to establish a new connection, while keeping the older mysql_connect connection around, in case we need to access it at a later time. It’s amazing how one little switch in a command can make a huge difference to this seemingly simple code. Anyways, adding a fourth parameter and setting it to TRUE was the solution.

Calculating Dates in PHP

Displaying dates in PHP is a no brainer. You simply echo the date() function to display the current date. For example, echo date(‘Y-m-d’) will display the current date in the ISO date format of ’2012-02-27.’ However, calculating dates in the past or in the future is a tiny bit more tricky. For accuracy, I recommend that you use mktime(), which converts time to Unix timestamp. You can then perform date calculations in Unix timestamp which is much more accurate. You do have the option to change the format back to ISO, if you desire. Here are a few examples.

Display the current date:

echo date('Y-m-d');

Output: 2012-02-27

Convert to mktime:

$t = mktime(0, 0, 0, date("m"), date("j"), date("Y"))

Display the start of the current month:

echo date('Y-m-d', mktime(0, 0, 0, date("m"), 1, date("Y")));

Output: 2012-02-01

Display the end of the current month:

echo date('Y-m-d', mktime(23, 59, 59, date("m")+1, 0, date("Y")));

Output: 2012-02-29

Display the start of last month:

echo date('Y-m-d', mktime(0, 0, 0, date("m")-1, 1, date("Y")));

Output: 2012-01-01

To display the end of last month:

echo date('Y-m-d', mktime(23, 59, 59, date("m"), 0, date("Y")));

Output: 2012-01-31

Display the start of next month:

echo date('Y-m-d', mktime(0, 0, 0, date("m")+1, 1, date("Y")));

Output: 2012-03-01

Display the end of next month:

echo date('Y-m-d', mktime(0, 0, 0, date("m")+2, 0, date("Y")));

Output: 2012-03-31

This code is very flexible. If you like to display the dates to any other format, you can change the date format to any format that you like. Check out all the different date formats. I hope this was helpful.

Demand For Mobile Developers

The number of users accessing the Internet will double by 2016. The driving force behind the numbers are the emerging markets. Most of these new users will access the web via mobile phones.

Currently, there are 3 billion Internet users, according to Google. There are 200 million new Internet users every year. About 80% of the new users access the web via mobile phones.

What this means is, there are plenty of opportunities for mobile developers. Remember the good old days when blocks of ice were sold by the thousands by ice manufacturers. They made a handsome profit back then.

But, the arrival of the refrigerator forever changed the landscape. Companies simply folded and moved on to something more profitable. It will be the same story for many technologists today.

The shift is on. Mobile development will be on the rise. There will be a huge demand for mobile developers. It’s time for many of us to change gears.

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.