Wednesday, May 25, 2011

Top 10 Programming Fonts

SkyHi @ Wednesday, May 25, 2011
I’m a typeface geek, and when it comes to selecting a font I’ll stare at all day, I tend to be pretty picky. Recently, when I discovered that a friend was using a sub par typeface (too horrible to name here) for his Terminal and coding windows, my jaw dropped, my heart sank a little, and I knew it was due time for me to compose this article.
What follows is a round-up of the top 10 readily-available monospace fonts. Many of these fonts are bundled along with modern operating systems, but most are free for download on the web. A few, notably Consolas, are part of commercial software.

A note about anti-aliasing

In the past, we’ve had to decide between tiny monospace fonts or jagged edges. But today, modern operating systems do a great job of anti-aliasing, making monospace fonts look great at any size. It’s not 1990 anymore. Give your tired eyes a break and bump up that font size.
If you have any doubt that anti-aliased fonts are apropos for code, note that even the venerable BBEdit — which for years has shipped with un-aliased Monaco 9 set as the default — has made the jump. The app now ships with a specially licensed version of the Consolas font from Ascender, bumped up in size, and with anti-aliasing on by default. Panic includes a special anti-aliased font (Panic Sans, which is actually just a version of Deja Vu Sans Mono) with its popular Coda application.
Unless otherwise noted, I’ve used a larger size font, 15-point in fact, for the examples here to illustrate their legibility at larger sizes and with anti-aliasing turned on.

10. Courier

All systems ship with a version of Courier (sometimes Courier New), and unfortunately, many have it set as the default font for terminal and editor windows. It does the job, but it’s a bit dull and boring, lacking style and class. I don’t recommend this font if you have any other choice — and fortunately, you do. If you use this font, please bump the size and turn on anti-aliasing.
Courier New
Figure 1 Courier New

9. Andale Mono

A bit better than the Courier family, Andale Mono is still relegated to the “default font” category as it ships with some systems, and you wouldn’t want to download or use it if it wasn’t already there. The character-spacing is a bit too clumsy and the letters are a bit too wide for my tastes.
Andale Mono
Figure 2 Andale Mono

8. Monaco

Monaco is the default monospace font on the Mac and has been since its inclusion in System 6. It’s a solid, workhorse font that really shines at smaller font sizes with anti-aliasing turned off. I loved this typeface back when my eyes could tolerate staring at a 9-point font for hours, but those days are behind me. This font looks great at 9 or 10-points (Figure 4), and doesn’t look too shabby anti-aliased at higher sizes (Figure 3).
As far as I know, you can only get Monaco as a part of Mac OS, but there are alternatives, so keep reading.
Monaco
Figure 3 Monaco
Monaco 9
Figure 4 Monaco 9-point, without anti-aliasing

7. Profont

Profont is a Monaco-like bitmap font available for Mac, Windows, and Linux (there’s also a modified version for Mac OS X called ProFontX by a different author). They’re best at smaller sizes, and make a great alternative to Monaco if you’re on a non-Mac platform and want really tiny fonts and the eyestrain that goes along with them.
Profont (and ProFontX) is intended for use at 9-points with anti-aliasing turned off.
Profont
Figure 5 Profont 9-point, without anti-aliasing

6. Monofur

Monofur is a unique monospace font that looks great anti-aliased at all sizes. It’s a fun font with a distinct look that is vaguely reminiscent of Sun’s OPEN LOOK window manager, which ran Solaris (aka SunOS) systems back in the late 80’s. If you’re looking for something a bit different, try this font, but make sure you have anti-aliasing turned on, even at small sizes.
Monofur
Figure 6 Monofur

5. Proggy

Proggy is a clean monospace font that seems to be favored by Windows users, although it works fine on a Mac. It’s a clean font intended to be used only at smaller points, and without anti-aliasing.
Proggy Clean
Figure 7 Proggy Clean at 15-point (yes, 15-point), without anti-aliasing

4. Droid Sans Mono

The Droid font family (available for download here) is a nice font family designed for use on the small screens of mobile handsets, like Android, and licensed under the Apache license.
Droid Sans Mono makes for a great programming font. It’s got a bit of flair, and stands out among the other monospace fonts I’ve listed, and its only real flaw is the lack of a slashed zero.
Droid Sans Mono
Figure 8 Droid Sans Mono

3. Deja Vu Sans Mono

The Deja Vu family of fonts are one of my favorite free font families, based on the excellent Vera Font family. The Deja Vu fonts have been updated with a wider range of characters while maintaining a similar look and feel to that of Vera.
This was my go-to font family for many years. It looks great at any size with anti-aliasing turned on.
Panic ships a font with it’s Coda application called “Panic Sans” which is based on this font. Gruber says via email that when he compared Panic Sans against Vera, he noted that “Panic had noticeably crisper punctuation chars” and that it seemed like they had improved the hinting on some characters as well.
Deja Vu Sans Mono
Figure 9 Deja Vu Sans Mono

2. Consolas

Consolas suddenly appeared on my Mac after I installed Microsoft Office, along with a handful of other new fonts from Microsoft.
This font was designed by Luc(as) de Groot for Microsoft’s ClearType font family (there’s a nice write-up with samples of each of the new Microsoft fonts here). Consolas is a commercial font, but is bundled with many Microsoft products, so there’s a good chance you might already have it on your system.
You’ll absolutely want to have anti-aliasing turned on if you’re using Consolas, because it’ll look terrible without it.
Too bad it’s not free … if it was, it would be #1 on this list.
Consolas
Figure 10 Consolas

1. Inconsolata

Inconsolata is my favorite monospaced font, and it’s free. Shortly after discovering it, it quickly supplanted Deja Vu Sans Mono as my go-to programming font. I use it everywhere, from Terminal windows to code editors. It has a certain sublime style that’s unique without being over the top, and it looks fantastic at both large and small sizes. I use this font when I show code samples in a presentation, and it’s the font we use in Terminal and TextMate windows when filming PeepCode screencasts.
Inconsolata is designed to be used with anti-aliasing enabled, but it’s surprisingly legible even at very small sizes. A big thanks to Raph Levien for creating this font, and for making it free.
Inconsolata
Figure 11 Inconsolata

Thoughts?

Did I miss your favorite coding typeface? Think the list is out of order? Let me know. If there’s a typeface you think should be in this list, please let me know in the comments section below. If it meets my ridiculous standards, I’ll review it and include it in a follow-up article.


REFERENCES
http://hivelogic.com/articles/top-10-programming-fonts/

Tuesday, May 24, 2011

How-To: Managing services with update-rc.d

SkyHi @ Tuesday, May 24, 2011
Linux services can be started, stopped and reloaded with the use of scripts stocked in /etc/init.d/.
However, during start up or when changing runlevel, those scripts are searched in /etc/rcX.d/ where X is the runlevel number.
This tutorial will explain how one can activate, deactivate or modify a service start up.
When installing a new service under debian, the default is to enable it. So for instance, if you just installed apache2 package, after you installed it, apache service will be started and so will it be upon the next reboots.
If you do not use apache all the time, you might want to disable this service from starting up upon boot up and simply start it manually when you actually need it by running this command:
# /etc/init.d/apache2 start
You could either disable this service on boot up by removing any symbolic links in /etc/rcX.d/SYYapache2 or by using update-rc.d.
The advantage of using update-rc.d is that it will take care of removing/adding any required links to /etc/init.d automatically.
Taking apache2 as an example, let's examine how /etc/rcX.d is looking like:
# ls -l /etc/rc?.d/*apache2
lrwxrwxrwx 1 root root 17 2007-07-05 22:51 /etc/rc0.d/K91apache2 -> ../init.d/apache2
lrwxrwxrwx 1 root root 17 2007-07-05 22:51 /etc/rc1.d/K91apache2 -> ../init.d/apache2
lrwxrwxrwx 1 root root 17 2007-07-05 22:51 /etc/rc2.d/S91apache2 -> ../init.d/apache2
lrwxrwxrwx 1 root root 17 2007-07-05 22:51 /etc/rc3.d/S91apache2 -> ../init.d/apache2
lrwxrwxrwx 1 root root 17 2007-07-05 22:51 /etc/rc4.d/S91apache2 -> ../init.d/apache2
lrwxrwxrwx 1 root root 17 2007-07-05 22:51 /etc/rc5.d/S91apache2 -> ../init.d/apache2
lrwxrwxrwx 1 root root 17 2007-07-05 22:51 /etc/rc6.d/K91apache2 -> ../init.d/apache2
As you can see, for runlevels 0, 1 and 6 there is a K at the beginning of the link, for runlevels 2, 3, 4 and 5, there is a S. Those two letters stands for Kill and Start.
On Debian and Ubuntu, runlevels 2, 3, 4 and 5 are multi-users runlevels.
Runlevel 0 is Halt.
Runlevel 1 is single user mode
Runlevel 6 is reboot

1. Removing a Service

If you want to totally disable apache2 service by hand, you would need to delete every single link in /etc/rcX.d/. Using update-rc.d it is as simple as:
# update-rc.d -f apache2 remove
The use of -f is to force the removal of the symlinks even if there is still /etc/init.d/apache2.
Note: This command will only disable the service until next time the service is upgraded. If you want to make sure the service won't be re-enabled upon upgrade, you should also type the following:
# update-rc.d apache2 stop 80 0 1 2 3 4 5 6 .

2. Adding a service

2.1. Default priorities

Now, if you want to re-add this service to be started on boot up, you can simply use:
# update-rc.d apache2 defaults
Adding system startup for /etc/init.d/apache2 ...
/etc/rc0.d/K20apache2 -> ../init.d/apache2
/etc/rc1.d/K20apache2 -> ../init.d/apache2
/etc/rc6.d/K20apache2 -> ../init.d/apache2
/etc/rc2.d/S20apache2 -> ../init.d/apache2
/etc/rc3.d/S20apache2 -> ../init.d/apache2
/etc/rc4.d/S20apache2 -> ../init.d/apache2
/etc/rc5.d/S20apache2 -> ../init.d/apache2

2.2. Custom priorities

But as you can see, the default value is 20 which is pretty different than 91 ... a S20 link is started before a S91 and and K91 is kill before K20.
To force apache2 to be started with priorities 91 for both Start and Kill, we need to use the following command:
# update-rc.d apache2 defaults 91
Adding system startup for /etc/init.d/apache2 ...
/etc/rc0.d/K91apache2 -> ../init.d/apache2
/etc/rc1.d/K91apache2 -> ../init.d/apache2
/etc/rc6.d/K91apache2 -> ../init.d/apache2
/etc/rc2.d/S91apache2 -> ../init.d/apache2
/etc/rc3.d/S91apache2 -> ../init.d/apache2
/etc/rc4.d/S91apache2 -> ../init.d/apache2
/etc/rc5.d/S91apache2 -> ../init.d/apache2

2.3. Different priorities for Start and Kill

Alternatively, if you want to set different priorities for Start than for Kill, let say Start with 20 and Kill with 80, you will need to run:
# update-rc.d apache2 defaults 20 80
Adding system startup for /etc/init.d/apache2 ...
/etc/rc0.d/K80apache2 -> ../init.d/apache2
/etc/rc1.d/K80apache2 -> ../init.d/apache2
/etc/rc6.d/K80apache2 -> ../init.d/apache2
/etc/rc2.d/S20apache2 -> ../init.d/apache2
/etc/rc3.d/S20apache2 -> ../init.d/apache2
/etc/rc4.d/S20apache2 -> ../init.d/apache2
/etc/rc5.d/S20apache2 -> ../init.d/apache2

3. Specifying custom runlevels

Finally, if you only want to Start and Kill on specific runlevels, like for instance starting apache with priority 20 on runlevels 2, 3, 4 and 5 and Kill with priority 80 on runlevels 0, 1 and 6:
# update-rc.d apache2 start 20 2 3 4 5 . stop 80 0 1 6 .
Adding system startup for /etc/init.d/apache2 ...
/etc/rc0.d/K80apache2 -> ../init.d/apache2
/etc/rc1.d/K80apache2 -> ../init.d/apache2
/etc/rc6.d/K80apache2 -> ../init.d/apache2
/etc/rc2.d/S20apache2 -> ../init.d/apache2
/etc/rc3.d/S20apache2 -> ../init.d/apache2
/etc/rc4.d/S20apache2 -> ../init.d/apache2
/etc/rc5.d/S20apache2 -> ../init.d/apache2
Or, to start with priority 20 for runlevel 2, 3 and 4 and priority 30 for runlevel 5 and kill with priority 80 for runlevel 0, 1 and 6:
# update-rc.d apache2 start 20 2 3 4 . start 30 5 . stop 80 0 1 6 .
Adding system startup for /etc/init.d/apache2 ...
/etc/rc0.d/K80apache2 -> ../init.d/apache2
/etc/rc1.d/K80apache2 -> ../init.d/apache2
/etc/rc6.d/K80apache2 -> ../init.d/apache2
/etc/rc2.d/S20apache2 -> ../init.d/apache2
/etc/rc3.d/S20apache2 -> ../init.d/apache2
/etc/rc4.d/S20apache2 -> ../init.d/apache2
/etc/rc5.d/S30apache2 -> ../init.d/apache2 

 You could install sysvconfig package and then type:
$ sudo service samba status

Unfortunately, samba does not support the status option.
However, you can find out when a service is running by checking in /var/run or in /var/run/service/ for files with the extension .pid. For instance, samba stores its pid in /var/run/samba/nmbd.pid and /var/run/samba/smbd.pid .
The service command is pretty tight to red hat based distros. Debian does not have such a command out of the box and sysvconfig seems to be a port of te Red Hat tool.


Managing services in Debian

 

I’m used to System V style commands used in Red Hat / Fedora and derivatives as well as SUSE, so I found Debian service management methods unintuitive at first.
Below are a couple of personal notes I made on the subject to help myself out, as I was getting used to the Debian way of things…
List existing services:

ls /etc/rc2.d/S*

Manage services [start,stop,reload,etc]:

/etc/init.d/service command

Make service start on boot:

update-rc.d name defaults

The ‘defaults’ value makes the service start in runlevels 0123 and stop in 456. Alternatively, you can specify which runlevels the service will start and stop in with:

update-rc.d name start runlevel stop runlevel

To remove service from starting on boot:

update-rc.d name remove

BTW, for a really excellent breakdown of update-rc.d options, check out this well written post.
If you install sysvconfig (apt-get install sysvconfig) you can also use System V style commands to start/stop services:

service name command

Unfortunately, even having installed sysvconfig in Debian, the command to list all services with status (e.g. running, unused, etc) is still missing. In SUSE, you’d run it with:

service -s

And would get a nice little list like this:
serv1ce-s.png
In the absence of the above, you could just list running processes with ‘ps’.. Another option is to list files in /var/run whose filename ends with ‘pid’, as each of those corresponds to a service:

find . /var/run | grep pid

Yet another option, with sysvconfig installed on Debian, is to just run:

sysvconfig

…which produces a clean and simple ncurses GUI which allows to manage service startup and edit runlevels:
sysvc0nfig.gif

 


REFERENCES

How to Use GNU Screen

SkyHi @ Tuesday, May 24, 2011
On UNIX, GNU Screen is a utility that i cannot live without. I know many console users share the same point of view with me.
What is GNU Screen? it is a terminal multiplexer and you can run multiple console-based applications simultaneously. The best part of it is that you can leave it running on remote machines and come back to pick up your console sessions. It’s like VNC or Remote Desktop but for UNIX console. As you know that on UNIX if you run something on a shell and you got disconnected from it then your sessions will also stop. All work will be gone.
With that feature GNU Screen is indispensable when it comes to do console sessions on low speed connection. If you got disconnected then all you have to do is reconnect and continue with your work. Or if you do something that takes a long time to finish, say maybe archiving and backing up many files, then simply launch it from GNU Screen session then detach from it and disconnect. Later on you can come back and reattach again to check the progress.
Anyway, here are some most useful features of GNU Screen that i use most of the time.
GNU Screen Most Used Commands
Commands What It Does
Ctrl-a ? (question mark)
GNU Screen's help pagehelp page
Open the help page. Also remember that “man” and “info” is your friend. By typing “man screen” and “info screen” you’ll get a lot of informations regarding Screen.
Ctrl-a d
resuming GNU Screen's sessionresuming session
Detach from the current Screen session and leave the process running in the background. Use “screen -r” to resume the session. If there are several Screen sessions running then add the session ID to the end of it. Ex: “screen -r 1088“. What really nice is that means you can login from anywhere to start your Screen session then later on continue the session again from different place.
Ctrl-a k
trying to kill a window in gnu screenkill a window
Kill current window. If you have another window active then Screen will move on to that window. If this is the only window to it then Screen will kill the window and exit, therefore ended the session.
Ctrl-a c Create a new window. By default it creates a new shell instance according your system setup (usually 90% of the time this is either bash or tcsh).
Ctrl-a A (capital A)
set title of current window in gnu screenset title
Rename current window. If you have so many windows running then i would suggest you name them so you won’t be lost.
Ctrl-a ” (double quote)
gnu screen showing list of active windows in current sessionlist of active windows
Show list of active windows in the current session.
Ctrl-a n, Ctrl-a p If you have multiple windows running then this command will do the flipping between the next window (using “Ctrl-a n”) and the previous window (using “Ctrl-a p”).
Ctrl-a h
gnu screen telling that it's logging to a file01. logging to a file
log file from a gnu screen window02. the log file
Create a running log (history). It will says “Screen image written to …” (see image 01). The file actually resides in your home directory (see image 02)
Ctrl-a ESC, Ctrl-a ]
entering gnu screen's copy modeA. entering copy mode
highlight the selection before copy it into gnu screen's bufferB. highlight the selection
gnu screen copied text into bufferC. copied into buffer
pasting text from gnu screen's bufferD. pasting text
Press “Ctrl-a ESC” will makes you temporary enter the copy buffer mode (see image A). You can tell when it says “Copy Mode …”.
In copy buffer mode you can move the cursor freely using directional keys. In this example i’m “cat”-ing the content of the Message of the Day (/etc/motd) in my Ubuntu machine. Next step is to highlight the block that you want to copy to the buffer. Move your cursor to the beginning of the block that you want to copy then press enter. That will mark the start point of the block. Then move your cursor toward the end of the block that you want to copy (see image B). In this example i’m copying the text “System Information …” from Ubuntu’s MOTD
Press enter again to copy the highlighted block into the buffer. This will end the “Copy Mode” and put you back to the active screen. You can tell when it says “Copied # characters into buffer” (see image C)
Use “Ctrl-a ]” to paste whatever is in the buffer (see image D). As you can see i’m pasting the text “System Information …” from the Screen’s copy buffer.

REFERENCES

 http://www.phacks.net/how-to-use-gnu-screen/