How to install mongodb 1.8 on Ubuntu 10.04 Lucid LTS?

Here you have quick installation guide for mongodb on Ubuntu 10.04: Edit:

echo "deb dist 10gen" >> /etc/apt/sources.list
apt-get update
apt-get install mongodb-10gen

Remember that Debian-like systems and default package configuration aren't often security aware so you should edit mongodb config:

vim /etc/mongodb.conf

and add line:


This will disable default setting to run mongodb in trusted mode

How to check if processor is 32 bit or 64 bit?

You can check the long mode processor flag:

# grep lm /proc/cpuinfo
flags : fpu de tsc msr pae mce cx8 apic sep mtrr mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nonstop_tsc aperfmperf pni pclmulqdq est ssse3 cx16 sse4_1 sse4_2 popcnt aes hypervisor lahf_lm ida arat


If you have lm flag (like above) your CPU is at 100% 64 bit

How to list files in directory with Ruby

Often you need to get files listing from some directory in your administrative tasks/scripts. It's really simple to list directories within Ruby code. I prefer to use Dir class. You can use it as shown below:

 files = Dir.glob("*") 

Returns all files from the current directory as an Array. You can iterate over every element very easy and use it for custom action.

If you need to list only some type of files - you must change globbing option - for example to list all jpeg files:

If you need to list files from other directory you can put absolute or relative path into glob method, i.e.:

That's all for today. Thanks

Gentoo - install Ruby 1.9.2 - resolve problems with ruby_targets_ruby19

Gentoo - install Ruby 1.9.2 - resolve problems with ruby_targets_ruby19

Lastly I faced problems with installing Ruby 1.9 on Gentoo distros. First I unmasked Ruby 1.9.2 version. I use for that autounmask tool:

 # autounmask =/dev-lang/ruby-1.9.2

But after that I received error on rdoc installation:

 # emerge ruby emerge: there are no ebuilds to satisfy ">=dev-ruby/rdoc-2.5.11[ruby_targets_ruby19]". (dependency required by "dev-lang/ruby-1.9.2" [ebuild]) (dependency required by "ruby" [argument]) 

How to resolve that problem and install Ruby 1.9?

How to add swap space online - without repartitioning?

Instead of resizing swap partition you can create a swap file. Example:

(Create (almost) 1GB file filled with zeros)
# dd if=/dev/zero of=/tmp/swap_file bs=1000 count=1000000
("Format" file as swap)
# mkswap /tmp/swap_file
("Mount" it)
# swapon /tmp/swap_file

Now you can use free or top to verify that available swap space really increased. Of course the trick above works only until reboot - if you want it to persist, just add (on your Gentoo) server swapon /tmp/swap_file to /etc/conf.d/local.start.

Growing file

Starting named daemon in debug mode can cause problems with huge size of file. By default named save debug information to /var/named/ file. You can stop writing to it by disabling debug mode. Check that your named runs without debug option:

 ps ax|grep named named -d 3 -c /etc/named-master.conf 

If -d flag exists try to restart named without it and check again

 ps ax|grep named named -c /etc/named-master.conf 

And that's all. 

Related links:
Bind documentation


Due to data migration I'm adding  here Derek's comment:

A safer way to do this is the following:

1. delete (can be in /var/named, /var/cache/bind, etc, depending on the flavor of Linux).
2. "rndc notrace" to disable debug in bind
3. "rndc reload" to reopen file handles. 

If you're running bind in production, killing it is not usually an option.


How to check that variable is defined

There are minimu two ways. First - by using defined? method:

 if defined? my_var puts "exists" else puts "doesn't exist" end 

defined? method returns type of variable if variable exists and nil otherwise. Second way is by initializing variable which you want to check ...

It cost nothing - so that way it looks like that:
 my_var = nil if my_var.nil? #logic goes here else #otherwise end 

How to split archives (tar) into parts

There are many ways to create a tar archive that would allow to limit the file size and break up automatically into incremental archives. If you want to do it with tar you should follow this short instruction.

We will use two popular tools (split and tar). Here is example usage. Backup directory 2011_03_13 and split archive into 4GB chunks:
 tar -cvp '2011_03_13/' | split -d -b 4000m - archive.tar.bz2. 
Recreate archive from chunks:
 cat archive.tar.bz2.0* |tar -xpvf -

How to backup (tar) to remote machine

I've found two cases in which you need to do tar this way: - you don't have space on your machine - you don't trust the machine operator or you want to store backups on other machine What to do then?

The answer is simple - use tar over ssh session like below: tar with gzip compression
 tar zcvf - /my_data | ssh "cat > /backup/my_data.tar.gz" 
tar with bzip2 compression
 tar jcvf - /my_data | ssh "cat > /backup/my_data.tar.gz"