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!

Aug 152010
 

Multi-line string in Ruby

Answer:

To declare a multi-line string in Ruby, it is as easy as the following.

sql = "
        SELECT *
            FROM `user` AS u
            JOIN `company` AS c
                ON u.cid = c.id
             WHERE u.id = 8
"

puts sql
Aug 142010
 

Enable gzip compression in Nginx

Answer:

Enabling gzip compression for text based output such as HTML can greatly improve the response of user.

If you are using nginx, it is easy by adding the following lines in your nginx.conf

gzip  on;
gzip_min_length  1000;
gzip_proxied     expired no-cache no-store private auth;
gzip_types text/plain text/html text/css application/json application/x-javascript text/javascript text/xml application/xml;
Aug 122010
 

Cross platform newline in PHP

Answer:

In PHP, if you want to print out a newline character, you can use the "\n" character

<?php

    echo "Hello World\n";

But the \n" character only work in Linux/UNIX, to make it work for both Windows, Mac and Linux/UNIX platforms, you can use a special constant PHP_EOL.

<?php

    echo "Hello World" . PHP_EOL;
Aug 112010
 

Upgrade Packages in Ubuntu

Answer:

From time to time, packages will release new version so your installed packages will also need to keep updated.

To upgrade your system, first update your package index by

# sudo apt-get update

Than upgrade the packages

# sudo apt-get upgrade