Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Linux Ask!

Jun 062013
 

Comment out multiple lines using vim

Answer:

When you want to comment out multiple lines in a configuration file or a program script, it is easy with the help of vim.

Steps:

1. Change to command mode
2. Enable visual block editing by pressing Ctrl + V
3. Select the line(s)
4. Press "I", enter the character you needed, e.g. "#"
5. Press "Esc", then "Enter"

May 152013
 

Generate random data in MongoDB

Answer:

You can use the following method to generate random string into a collection in MongoDB:

function randomString() { 
        var chars = 
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; 
        var randomstring = ''; 
        var string_length = 100;
        for (var i=0; i<string_length; i++) { 
                var rnum = Math.floor(Math.random() * chars.length); 
                randomstring += chars.substring(rnum,rnum+1); 
        } 
        return randomstring; 
} 

for(var i=0; i<2000000; i++){db.test.save({x:i, data:randomString()});}