The index is being built, here are some Linux and Programming articles meanwhile =)

How to backup your DreamHost account and download the backup easily

I normally do a DreamHost backup every month, along with other things that I backup, and then I download all of the files. It is part of my backup strategy, I backup when I do something important to backup, or the normal monthly backup, which is for me and I call it a value added thing for the people whose sites I host.

I don’t enjoy downloading all of the files one by one of course, I rather leave it downloading as I sleep. And I do not handle one single DreamHost account.

What is color space in images

When I create thumbnails of images or when I scale them, I utilize several parameters and not just the size.

This has to do with the color space of the image. What am I talking about?

There are two ways in which the information of an image is saved.

Using rsync and cron to automate incremental backups

Data loss is a serious concern to both individuals and companies that rely in the use of computers for their every day life or operations. Those who have a Unix based system count with powerful tools to prevent this, such as rsync to backup the information, and cron to make the backup process automated. In previous posts I wrote about the basics of rsync and it's usage as a daemon, as well as the basics of cron. In this post the focus is on the backup functionality of rsync, and its conjoint usage with cron to automate the backup process.

Vim and the x11 clipboard

We can access the clipboard of x11 (the graphical system over which most desktop environments run, such as Gnome and KDE) to share text between Vim and other graphical applications.

x11 have two different global areas where it stores content to be shared between applications, one is known as the "cut-buffer", this is the location where the text that we copy or cut is stored, this is what most people associate with system clipboard. And the other is known as "selection", in x11, whenever we select something with our mouse, we can paste this selection in the location of the mouse cursor by pressing the middle button. Vim can access the content of both storages, get the text from this global storages, or put text on them.

Configure the syntax highlighting in Vim

When we enable syntax highlighting (by using :syntax enable), Vim will take into consideration the extension of the file to determine the appropriate syntax highlighting rules, and if this fails it will search the contents of the file for specific patterns in order to determine the file type. But if we are working in a temporary file that we don't intend to save, or if we opened, e.g., a file with HTML extension but we find that it contains PHP code in it, we can change the rules of the syntax highlighting.

Configure unrecognized keys in Linux

Occasionally I am presented with keyboards that contain keys that are not recognized by default in Linux. In most cases the fix consist in select a different keyboard layout, modern Linux distributions cover a wide variety of keyboards, but some times there is no keyboard layout available that matches our keyboard and the functionality of some keys is lost. In this post I write about how to detect and map unrecognized keys. I am making the assumption that you are working in a graphical environment and that you want to give it some functionality to the key there.

Using cronjobs in Linux

cron is a daemon that allow us to schedule the launching of programs and scripts. This allow us to automate the execution of diverse tasks in our computer. cron is launched when we boot our computers and stays running in the background.

Running rsync as a daemon

If the host computer is not running SSH (or RSH), we can configure and run rsync as a daemon in this computer. This would have rsync listening to the port 873 for incoming connections from other computers utilizing rsync. While this is not recommended for the transfer of files across unsecured networks, such as the Internet, because the actual data transfer is not encrypted, we can use this to keep information synchronized between different computers in internal networks, as well as perform backups.

Making better use of the Caps Lock key in Linux

How frequently do we really use the Caps Lock key?, This is one of the best positioned keys in our keyboard, as it rests next to the A key, however, in this space we have this Caps Lock key that we seldom utilize. For those who type without looking at the keyboard it is an even more important space, as it is readily available with a minor movement of the left pinky. I am sure that there are people who do utilize it in a daily basis, but it is my understanding that this is a minority.

But this can be easily changed in Linux. And believe me, you wont regret this change once you grow accustomed to it. For a Vim user there is no question about what to do with this key, we can swap it for the Escape key, or turn it into a second Escape key, although I personally didn't want to lose the functionality so I just swapped it. Other possible uses are to turn it into another Backspace key, or into a Control key, we can even give it the functionality of a multimedia key.

My most used htaccess settings

The file .htaccess allows us to change some of the settings of a server for a particular directory and it's subdirectories. While it is preferable to make this type of configurations in the server configuration file itself by the use of a <Directory> section, sometimes we simply don't have access to this configuration file, specially when we have a shared hosting account. Most shared hosting providers allows us to make changes to the behavior of the server only in this way.

Synchronizing folders with rsync

In this post I cover the basics of rsync, in preparation for a subsequent post that will cover backups and it's use in conjunction with cronjobs to automatize the backup process. From the copying and synchronization of local files and folders, to it's use for transfer information among computers. Its use as a daemon when SSH is unavailable was moved to it's own section.

Installing Slackware in an encrypted LVM

Introduction

When a laptop is lost or stolen (or it may be a desktop computer, but this is more likely to happen with a computer that we carry around), at first we may resent the price of the machine itself (and the personal data on the machine if you do not back-up frequently, which you really should, specially if you move your computer around a lot), until we realize that whomever is in possession of the computer posses access to all of our information: our photos, our documents, our media, all of our browser history, and, to make things worst, he/she may have access to sensitive information such as our credit card and log in information of the websites that we visit. If this lost computer used to belong to a corporate user, things are even worst, as whoever took possession of the computer may have obtain sensitive information about the company or about the clients of the company.

How to create a reverse SSH tunnel

Sometimes that we need to connect via SSH into another computer, we find out that this computer that we intend to SSH into (which we are going to call "destiny") may be utilizing NAT and therefore it doesn't count with a public IP address that we could use to connect to it, or it may be behind a firewall that won't allow access from the outside.

If "destiny" can successfully establish a SSH connection to another computer that is accessible, we can utilize this second computer to establish a reverse SSH tunnel to our "destiny" computer, we are going to call this second computer "origin" (even if it is not actually the computer that we are going to use to manage "target" remotely, but only a bridge).

Create a KTouch lecture from a list of words

Since I didn't find any lecture that I liked for KTouch, at least not one that allowed me to simply practice typing with a large number of random words, I thought it would be useful to create one based in random words taken from one of the lists of words usually located in /usr/share/dict, although this very same procedure can be use with any list of words. It didn't take to long to do it, but nevertheless it was interesting.

I include at the end the lecture that results from this procedure, as well as a lecture based in the words from the book The Adventures of Sherlock Holmes.

Detecting and changing the encoding of text files

When you receive and need to handle multiple text files that use characters that are not natural to the English language, you may run into the problem that is dealing with different character encodings. This is particularly noticeable in websites, where if the browser try to interpret the text file with an encoding that differs from the actual encoding that the file is using, we can see strange symbols where this characters were supposed to show, but it is not limited to websites, any program that is made to work with languages other than English may present a similar problem if it is not appropriately handled.

Defining SSH servers

If we need to log in often to the same SSH server(s), instead of type the entire connection command every time that we do it, since a connection command that may go something like this:

ssh -p 34567 username@subdomain.domain.tld

We can create a SSH configuration file that would allow us to define the parameters of a server, and then start a connection to it by simply typing the name that we gave it.

Passwordless SSH using digital signatures

When we log in via SSH to a server, a way to authenticate with it that does not require the use of a password is the use of digital signatures. What we do in this case is to generate a key pair (a public key and a private key), and then add our public key to the list of authorized keys in the server that we want to be able to log into.

Some regular expressions and how to use them in PHP

This isn't a guide about how to create regular expressions (although I would like to make one). These are a few regular expression that I made some time ago, when I had access to a list of names, addresses, phone numbers, etc. They were formatted in very different ways (special the phone numbers) so, the simpler regular expressions that I was using before that, had to be improved. I also talk about to use this regular expressions to validate input fields in PHP scripts.

Prepared MySQL statements in PHP (object oriented examples)

I find sad how many online systems are out there unprotected against even the simplest type of attack, SQL injections. This is a guide and a set of examples about the use of prepared MySQL statements in PHP. If you want to see how an SQL injection attack works you can read the previous article An SQL injection attack. There is a similar guide to this but using the regular structured functions from the MysqlI library at Prepared MySQL statements in PHP (structured examples).

Prepared MySQL statements in PHP (structured examples)

I find sad how many online systems are out there unprotected against even the simplest type of attack, SQL injections. This is a guide and a set of examples about the use of prepared MySQL statements in PHP. If you want to see how an SQL injection attack works you can read the previous article An SQL injection attack. There is a similar guide to this but using the object oriented interface of MysqlI in the examples at Prepared MySQL statements in PHP (object oriented examples).

An SQL injection attack

Since I wrote two different guides about the use of prepared MySQL statements in PHP, and one of the reasons for use this is to prevent SQL injection attacks, I am going to write a little about these attacks that many websites has suffer and continue to suffer even today. More than define what this attack is, the objective is to show how it works.

The confusing prefixes for binary multiples

Expressing sizes in informatics can be confusing at times, this is due to the lack of standardization among hardware manufacturers, programs and operating systems regarding the use of prefixes (K, M, G) when expressing binary multiples. A standard does exist, this is what ISO/IEC 80000-13:2008 is about, it defines a standard for the use of prefixes for binary multiples, however, it has not been widely adopted as of the writing of this post.

This confusion originates from the early days of informatics. In computing, the most basic unit of information is the bit, which could be think of as a switch, it has only two states, on and off (1 and 0). Because you can't store but a certain state (on or off) in a bit, a bigger unit was created, the byte, which is just a group of bits. A byte consists of 8 bits, and this allows to represent a value, from 0 to 255.

The SI (International System of Units) defines that K (Kilo) denotes 1000, and M (Mega) represents 1000×1000, this is based in our base-10 numeric system. Originally 1 kilobyte meant 1000 bytes (103) and there was no confusion. However, in the world of computing, because everything is based on the bit, the numeric system in use is base-2. People noticed the convenience of denote 1 kilobyte as 1024 bytes (210), and one megabyte as 1024×1024 (220); instead of the SI Kilo and Mega convention, which denotes 1KB as 103 bytes, and 1MB 106 bytes.

Managing MySQL from the command line

If our hosting service offer us a SSH shell and have MySQL installed, or if we have MySQL installed in our computer, we can administer a database from the Command Line Interface. If we develop programs that require the use of a MySQL database, most likely we are already familiarized with SQL statements. By the use of the mysql command we can send this queries to the database.

How to create scaled thumbnails in PHP

It's always a good idea to generate as many different sizes of thumbnails as are required in a web based system, right after an image is uploaded. Some of the advantages of generating and storing the thumbnails are that you can reduce the processing time that your server needs to use if you generate the thumbnails on demand, and of course you can reduce the consumed bandwidth by not sending the full size image when this is not necessary.

Working with UTF-8 in PHP, MySQL and Apache

As I have previously posted in this website, I believe it is a good idea to standardize in one character encoding across all parts of a system, and as my preferred character encoding is UTF-8, when I create a PHP system I check the following things:

  • That the browser receives and interprets the output of my PHP scripts as UTF-8.
  • That the (X)HTML forms accept UTF-8.
  • That PHP treats the data received from a MySQL database as UTF-8.