Smokes your problems, coughs fresh air.

Category: Technology (Page 43 of 47)

Change ext3’s reserved block count and gain Gigabytes

Wiebe was looking over my shoulder while I was running df to check the disk space that was still available on my Lenovo ThinkPad:

# df -h /dev/sda2
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              90G   79G  7.3G  92% /

He noticed that there was a huge gap between the total space (79 used + 7.3 available = 88.3) and the actual size of the file system. According to him this was due to the reserved block count, which is set to five percent by default in ext2 and ext3 file systems—clearly a legacy from a time where disks were smaller.

# dumpe2fs /dev/sda2|grep -i 'reserved block count'
dumpe2fs 1.40.8 (13-Mar-2008)
Reserved block count:     1196559

# dumpe2fs /dev/sda2|grep 'Block count'
dumpe2fs 1.40.8 (13-Mar-2008)
Block count:              23931180

# echo 'scale = 2; 1196559 / 23931180'|bc
.05

I changed the reserved block count with tune2fs:

# tune2fs -m 1 /dev/sda2
tune2fs 1.40.8 (13-Mar-2008)
Setting reserved blocks percentage to 1% (239311 blocks)
# dumpe2fs /dev/sda2|grep -i 'reserved block count'
dumpe2fs 1.40.8 (13-Mar-2008)
Reserved block count:     239311
# df -h /dev/sda2
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              90G   79G   11G  88% /

Now, the reserved blocks take up roughly 934 MiB; I’ve freed 3.7 GiB with this little file system tweak. ๐Ÿ™‚

Update 14 nov 2010: I finally fixed two errors in my final calculations spotted by Den. He noticed that the numbers (700 MiB and 13 GiB) were wrong. Thanks, Den!

png2ico: converting favicons to Windows’ ICO format

Even though, strictly speaking, I should be using favicons in anything but Windows’ ICO format and refer to them from a <link>-tag at any location other than /favicon.ico, I sometimes like to help Microsoft break the web by putting an ICO file at the location that they reserved for it (/favicon.ico).

My tool of choice for converting PNG’s to ICO is Matthias Benkmann’s png2ico. To generate an ICO file with this program, you just need to feed it one or more PNG files. The possibility to include differently sized PNG files can help you make sure that the icon will steal look good when being dragged to the desktop or some other non-miniature context.

$ png2ico
png2ico 2002-12-08  (c) Matthias S. Benkmann
USAGE: png2ico icofile [--colors ] pngfile1 [pngfile2 ...]

Here’s an actual example which creates an ICO file from a single PNG file:

$ file favicon.png 
favicon.png: PNG image data, 16 x 16, 8-bit/color RGBA, non-interlaced
$ png2ico favicon.ico favicon.png 

Of course, we should discourage browsers from doing useless requests for /favicon.ico by actually telling them when it is available: (as if…)

<link type="image/x-icon" rel="shortcut icon" href="/favicon.ico" />

Now we can go back to pretending that: No, we’re not encouraging the practice of link squatting. We just happen to have put our favicon in that location.

For the less tech savvy

Update 30 sep 2012: There’s a free online service to convert PNG to ICO: www.pngtoico.com. It doesn’t require you to do anything complicated (like installing Unix stuff). Just pick your original and get the converted image. ๐Ÿ™‚

Decoding djvu files on the command line

So, you have djvu files on a remote machine that you have SSH access to, and the local machine you’re working on doesn’t have djvu tools. What do you do? Simple, use ddjvu to decode the djvu files to images.

And that’s all. I kept forgetting the name of the tool, so, now I won’t anymore…

PostgreSQL back-end for Ruby on Rails confusion

I just need to add a quick summary of what postgres back-end tool our Ruby on Rails application uses, and how we’ve configured it, because it’s quite confusing…

There are four postgresql backends:

  • ruby-postgres. This version is no longer maintained. This is the version we used when the project began.
  • postgres-pr. This is a pure ruby implementation, which is not interesting for us.
  • postgres. This is the continuation of the unmaintained ruby-postgres. This version includes such fixes as that it can be compiled against libpg-8.3.
  • ruby-pg. It is said that this one is now the official postgres back-end, but when I install it, the application still can’t find “postgres”.

Because the aforementioned article states that the pg extension is unstable, “postgres” seems to be what we should use. The article states that it is included in the ruby-pg package, but it doesn’t work when I install it, so I had to install “postgres”. I uninstalled ruby-pg, because it doesn’t seem necessary.

To continue, we once used a patched postgresql adapter, because we needed more accurate timestamps (the standard connection adapter rounded everything off to whole seconds), but if I recall correctly, this patch was only necessary on the connection adapter in Rails, not the back-end. We never commissioned the functionality that required this, so this existed only in the workdir of one of the devs.

As a final note; on our production server, we have a version of ruby-postgres installed in /usr/local. I can’t remember why…

Using wget to download all files on a page

Just a quick one-liner I used to download a bunch of MIDI files from an on-line listing of Chopin MIDIs:

$ wget http://www.piano-midi.de/chopin.htm -q -O - \
| grep 'href=".*\.mid"' \
| sed -e 's/^.*href="\(.*\)".*$/\1/' \
| xargs -i{} wget http://www.piano-midi.de/{}

Maybe not so useful to you, but it’s a good demonstration of applying the hacker’s mentality to one of those moments where, after clicking the fourth link or so, I find myself thinking: Wouldn’t spending a few moments on a one-liner be much more fun than clicking through and saving 44 more links?

Useful or not, I am now testing timidity’s piano sound with a nice rendition of Chopin in the background whereas, without this trick, I’d still be right-click-click-saving links instead of writing this post. It’s up to you to decide whether this is actually good or bad. ๐Ÿ˜›

VIM modelines for per-file configuration

The MediaWiki developers use tabs instead of spaces for indentation. This can be annoying for someone like me who has configured VIM to work with spaces by default—annoying because I don’t want to enter something like :set tabstop=4 noexpandtab shiftwidth=4 every time that I open a file. Adding different conditions for each project to my .vimrc is probably possible but not much fun.

The other minute, when I opened the sources of my Semantic Gallery extension for MediaWiki, I noticed that I had been mixing tabs and spaces again. So it was time to look up the VIM feature which allows you to put a configuration line in a comment at the bottom of a file. This quote is another perfect example of why it’s good practice to blog about such things. I remembered that the last time that I had wanted to do this, I could not find a useful search string at all and resorted to finding back an example in the code where I had first seen it and modifying that. Now, I thought I’d have to do the same, but from a quick googling I learned that I’m not the only one to use his blog as a memory extension. ๐Ÿ™‚

Good. Hopefully, from now on, I’ll remember that this configuration-thingy-at-the-bottom-of-a-file is called a modeline, so that I can just enter :help modeline in VIM the next time that I forget where the colons have to go.

An example for when I do forget:

# vim:set ts=4 sw=4 noexpandtab:

This reminds me of my many searches for Heredoc syntax when I didn’t know that they were called Heredocs.

Disabling SSH shell access for SVN users on a Linux/Unix system

A common problem is that Linux/Unix system administrators want to grant users access to SVN repositories, but prevent them from logging in on the shell. This can be accomplished quite easily.

First, disable the user’s account by running:

usermod --lock [user]

This way, only public key authentication is allowed. Then, when adding the user’s key to the ~/.ssh/authorized_keys file, prefix it with this:

command="/usr/local/bin/svnserve -t",no-port-forwarding,no-pty,no-agent-forwarding,no-X11-forwarding

I used our wrapper script in /usr/local/bin as the command, because it sets an umask of 002 before actually running svnserve. This is necessary when using svn+ssh access.

The source for this trick explains it in more detail.

Configuring a Debian satellite Exim server

A very common way to configure Exim on a Debian machine, is to make it a ‘satellite’; a server which uses another SMTP server for sending and does not do local delivery, the latter being the difference with a ‘smarthost’. It can be used by other computers in the network to send mail, but also by the machine itself, to send system notifications and such (one of my favorite apps, arpwatch, for example).

The following needs to be in /etc/update-exim4.conf:

dc_eximconfig_configtype='satellite'
dc_other_hostnames='[mailname]'
dc_local_interfaces=''
dc_readhost=''
dc_relay_domains='*'
dc_minimaldns='false'
dc_relay_nets=''
dc_smarthost='[your SMTP server]'
CFILEMODE='644'
dc_use_split_config='false'
dc_hide_mailname='false'
dc_mailname_in_oh='true'
dc_localdelivery='mail_spool'

The following needs to be in /etc/mailname:

[mailname]

[mailname] is the same in both locations, and is simply the FQDN (world wide, not just local, such as bla.net) which should appear after the @-sign. The reason that it must entered in both places, is because both have a different function. ‘etc/mailname’ Takes care of putting the specified domain after the @-sign if you mail to, for example, root. The ‘dc_other_hostnames’ is to let the server know that this is the machine that handles that domain. If you don’t specify the ‘dc_other_hostnames’, the server will just try to send it to the next relay. BTW, ‘dc_other_hostnames’ is colon (;) seperated.

Make sure the FQDN you use exists, otherwise a lot of mailservers refuse to accept it. What I don’t understand, though, is that in my experience, whatever you use as domain doesn’t have to exist as MX record, but just as an A record.

Also don’t forget to include an alias for root in /etc/aliases. I usually let all mail sent to root be sent to a local user, and alias that local user to an outside e-mail address.

Crane camera shots with just a tripod

When shooting footage with a motion camera, one of the most important things to achieve to avoid it looking like a home-barbecue video, is stable motion, normally achieved with a crane. A simple way to achieve this, is by retracting one leg of your tripod, and then tilt it forwards and backwards. This video gives a good demonstration. The difference between the tripod shots, and the hand-held shots (the shots made to demonstrate the technique) is astounding.


Video Cam Super Trick! – video powered by Metacafe

Remote pair programming with GNU Screen

I like pair programming. So much, in fact, that I want to do it even if I can’t look over the other person’s shoulder due to some geographical offset. Since I’m a real command-line freak, I can get what I want easily by using GNU Screen.

GNU Screen rehash

If you don’t know GNU screen yet and you ever find yourself using the command-line for an extended period of time, learn it. Now. I’ll name just a few advantages:

  1. You can manage multiple “windows” conveniently even if you don’t have a tabbed terminal emulator, or even when you’re not within a graphic environment such as X.
  2. You can “detach” and “reattach” your Screen sessions and continue exactly where you left. This is very useful if you do your work on a remote server, through SSH, for example. Never by stumped by instable connections again!
  3. But, the feature which is most useful for pair programming is the ability to attach to the same session from multiple terminals.

Starting GNU Screen is very easy. Just type screen at your shell prompt (or screen -S SESSION_NAME if you want your session to have an easy-to-remember name).

Press CTRL+A followed by d to detach. Exit your terminal. Start a new terminal, type screen -r and be amazed that you have your session back. screen -r can take as an argument the name or PID of the screen, which is useful if you have more than one screen running. To get a list of current screen sessions, type screen -ls.

Inviting your observer

The first thing you have to do is to add the following command to your .screenrc file:

multiuser on

If you don’t want to enable multiuser by default, you can also choose to type the command from within Screen each time that you need it. This is done by pressing Ctrl+A, followed by : and the command.

Myself, I prefer to have the command in my .screenrc. You need to admit users explicitly anyway. Admitting full access to a user is done by typing the :acladd USERNAME command (after pressing Ctrl+A). Then the given user can join this session by starting screen with screen -x SESSION_OWNER/ where SESSION_OWNER is the driver.

Get out of my driver’s seat! (Dealing with annoying observers)

The :acladd USERNAME command will give the observer full read-write access. Maybe, if you have to deal with an observer who insists on taking the driver seat, you want to limit his or her access to read-only. This can be done just as easily: press Ctrl+A; then type :aclchg USERNAME -w "#".

Make your terminals match

Using a shared screen, it can be kind of annoying if your terminal sizes don’t match. As an observer, I fix this by asking the driver to tell me the values of the $ROWS and $COLS environment variables. If then, for example $COLS=110 and $ROWS=40, I start my xterm with this in mind: xterm -geometry 110x40

Have fun with Screen!

I’ve only touched upon some of the things you can do with screen. The manual page contains much more information—perhaps a bit too much even. ๐Ÿ˜•

One of the things I also like to do with a shared screen session is remote system administration. If I want to perform delicate tasks as root, I find it kind of comforting if someone can stop me in time, before I do anything stupid. Besides, if you’re both root, you don’t even have to set permissions. ๐Ÿ™‚ So, it’s easy to.

« Older posts Newer posts »

© 2024 BigSmoke

Theme by Anders NorenUp ↑