Introduction to Object Oriented Programing in Python

In this post I am going to explain the syntax for Object Oriented Programming in Python. I am assuming you have already done it in other languages so if you have not done Object Oriented Programming previously you should probably look for another article about it’s principles.

At the beginning when I started learning python I found some things that I felt kind of weird, like the lack of braces and semicolons. Now that I started learning their syntax for OOP I realize that doing things weirdly is their standard. Python (kind of) allows you to implement all the principles of OOP but their syntax is not similar to the one of Java, C++, or PHP that I am familiar with. Anyway so far I don’t see any problem with their different way of doing things so I will just explain how things are done in Python.

Read More

Gradient background, the CSS 3 standard way

In this article I am going to explain the CSS 3 standard way of achieving a linear-gradient background. Using only this technique is probably not going to give the cross browser behavior that you are expecting.

Linear gradient

The definition of a linear gradient from W3C documentation:

A linear gradient is created by specifying a gradient line and then several colors placed along that line. The image is constructed by creating an infinite canvas and painting it with lines perpendicular to the gradient line, with the color of the painted line being the color of the gradient line where the two intersect. This produces a smooth fade from each color to the next, progressing in the specified direction.

So, to set a linear gradient for a div or another DOM element we would need to imagine a straight line that goes through the object at an specific angle touching the center of the element. Then define the colors we which at specific points in the line.

Read More

Creating functions with Python

We can create functions on Python using the def keyword.

def printSomething():
    print "something"

Functions in python can have arguments and return statements as in most languages.

def addNumbers(number1, number2):
    return number1 + number2
Read More

Contributing to OpenHatch project

What is OpenHatch? is a website where you can find ways to contribute to open source projects, mentor people who want to contribute to a project, or give a little more visibility to your open source project so people can help you.

In my opinion the most interesting features are the classification of some bugs as bitesize, which are good bugs for people who want to help but don’t have much experience. This is an awesome place to start. The other interesting feature is the ability to offer yourself as a mentor to fix a bug. If you are an expert on a subject but you don’t have time to fix an specific bug you can list yourself as a mentor and help other people get a bug fixed.

Read More

Rounded corners, the CSS 3 standard way

In this article I am going to explain the CSS 3 standard way of achieving rounded corners. Using only this technique is probably not going to give the cross browser behavior that you are expecting.

Border radius properties

It doesn’t matter which way you specify the radius you want for your corners, the browser is going to compute it in four different properties:

Read More

Pushing and deleting remote branches with git

Creating new branches and deleting them locally is an easy task with git, but when it comes to doing it for a remote repository, happily, it is very easy too.

Pushing a branch

If you have a new branch named mybranch on your local repository and you want to push it to a remote so other people can see it you can do:

git push remotename mybranch

Most of the time you will probably want to push to the origin remote, so the command will be something like this:

git push origin mybranch
Read More

sudo: unable to resolve host

Today out of the blue (or at least that is what I thought when I first saw it) I started seeing this message everytime I issued a command using sudo:

$ sudo ls
sudo: unable to resolve host adrian

After a little investigations I found out that it actually didn’t come out of nowhere, but I was the one who made this happened. What happens is that you usually have an entry in the file /etc/hostname where you specify the name of your host. So when you use the sudo command it tries to connect to the host computer to check for permissions. This can get really complicated, but if you are only working on your computer your host is usually the local host.

Read More

Enabling mod-rewrite on Ubuntu

I recently reinstalled the operating system on my computer and thus had to re-install all my applications and development environments.

While I was configuring my web environments I was getting some weird errors when I was trying to access one of my local sites. The error wasn’t really descriptive of the problem, but looking at the error logs I found this:

/home/adrian/www/ Invalid command 'RewriteEngine' perhaps misspelled ...

At first it was a little confusing, because I know that RewriteEngine is a valid command, but then I remembered that it is included by the mod-rewrite module that doesn’t come by default with apache. Installing it on Ubuntu is very easy, you just need to input this command on a terminal:

sudo a2enmod rewrite

And you will need to restart apache for the changes to take effect:

sudo /etc/init.d/apache2 restart

Now RewriteEngine is a recognized command for your .htaccess files.

Read More

Creating a batch file on windows

It is well known that creating a batch file in Linux is an easy and enjoyable task, but right now I find myself in the necessity of automating some tasks on windows so I will need to learn how to do this on windows.

In windows batch files generally have a .bat extension, so I will start by creating a file: examplebatch.bat and trying a very simple command:


Now if I navigate to the folder where my batch file is (let’s say C:\Adrian\Batch) I can execute the batch file and the dir command will be executed:


Volume in drive C is OSDisk
Volume Serial Number is C252-78D4

Directory of C:\Adrian\Batch
04/18/2012  08:42 PM    <DIR>          .
04/18/2012  08:42 PM    <DIR>          ..
04/18/2012  08:43 PM                 3 examplebatch.bat
               1 File(s)              3 bytes
               2 Dir(s)  186,052,022,272 bytes free
Read More