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:

1
2
$ 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:

1
/home/adrian/www/site.dev/.htaccess 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:

1
sudo a2enmod rewrite

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

1
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:

1
dir

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:

1
2
3
4
5
6
7
8
9
10
11
12
C:\Adrian\Batch>examplebatch.bat

C:\Adrian\Batch>dir
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

Creating and applying patches with git

Creating and applying patches using git is a task relatively easy to do. I will show how it all works using an example scenario.

Let’s say we have a main repository with just one commit on it:

1
2
adrian@laptop:~/repository$ git lg
* ff4c135 - (HEAD, master) first commit (2012-04-12 19:14:39 -0700) <Juanito>

That repository has been copied by other people that are working on the same project. Now lets say that I am the one that cloned the main repository and did some work on it:

1
2
3
4
adrian@laptop:~/copy$ git lg
* be3ec44 - (HEAD, origin/master, origin/HEAD, master) Third commit (2012-04-12 19:16:28 -0700) <Adrian>
* 1551977 - second commit (2012-04-12 19:16:00 -0700) <Adrian>
* ff4c135 - first commit (2012-04-12 19:14:39 -0700) <Juanito>
Read More

Python Sequences - Part 2

This post is a continuation of Python Sequences.

Concatenating Sequences

You can concatenate sequences using the plus (+) operator:

1
2
>>> [1, 2] + [3, 4]
[1, 2, 3, 4]

Multiplying Sequences

You can multiply a sequence by an integer number to repeat it the specified number of times:

1
2
>>> [1, 2] * 3
[1, 2, 1, 2, 1, 2]
Read More

Python Sequences

Sequences is the name that python gives to a data structure that contains a “sequence” of elements, each with a numeric consecutive index. The sequence is very similar to an array in other programming languages. The first index number is 0 and they increment by one as elements are added.

Sequences can contain numbers, strings, other sequences, etc…

Creating a sequence

You can define a sequence like a list of elements separated by commas and listed inside square brackets ([]):

1
ages = [13, 15, 22, 23, 56, 12, 33]
Read More

Python strings

Python has a lot of ways to represent strings, so it is useful to be familiar with them in case you ever find them in any python program.

Ordinary Strings

These are probably the most commonly used strings on python. You can enclose them using single or double quotes (‘ or “) and you can use a backslash to escape characters or to print special characters like a line break:

1
2
3
4
5
6
7
8
9
10
print "Hello\nWorld"
Hello
World

print 'Hello\nWorld'
Hello
World

print 'This is a backslash: \\'
This is a backslash: \
Read More

FileSync: File Synchronization plugin for notepad++

I want to start by thanking Mike Foster (http://mfoster.com/npp/SessionMgr.html) because with out his well written notepad++ plug-in and his instructions to compile it I wouldn’t have been able to develop this plug-in. I thank also François-R Boyer for helping me when I was stuck(http://sourceforge.net/projects/notepad-plus/forums/forum/482781/topic/4977590)

What the plug-in does

This is a really simple plug-in that copies a file to another location at the moment you save it. The reason I needed this extension is because I need to deploy my PHP applications using maven to download dependencies so the folder where my version controlled application lives is different than the folder where my executable application lives. Having this extension allows me to work always on my version controlled folder and having the changes immediately applied on the executable application folder.

Read More