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.

Oct 032010
 

How to install Easy Install for Python in Ubuntu

Answer:

EasyInstall is a package manager for the Python programming language that provides a standard format for distributing Python programs and libraries (based on the Python Eggs wrapper).

To install the EasyInstall under Ubuntu, type:

# sudo apt-get install python-setuptools python-dev build-essential

Sep 302010
 

Use of ASP like tags in PHP

Answer:

In PHP, you can use ASP-like <% %> tags in addition to the usual <?php ?> tags. But you need to enable it before use.

You need to editing the php.ini

vi /etc/php.ini

And set

asp_tags = 1

Restart your web server if needed.

Sep 262010
 

Connect MySQL server using C

Answer:

Below show a code sample for how to connect to MySQL server using C programming language.

#include <stdio.h>
#include <stdlib.h>
#include "mysql.h"

MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;

void exiterr(int exitcode)
{
	fprintf( stderr, "%s\n", mysql_error(&mysql) );
	exit( exitcode );
}

int main()
{
	uint i = 0;

	if (!(mysql_connect(&mysql,"host","username","password"))) 
		exiterr(1);

	if (mysql_select_db(&mysql,"payroll"))
		exiterr(2);

	if (mysql_query(&mysql,"SELECT name,rate FROM emp_master"))
		exiterr(3);

	if (!(res = mysql_store_result(&mysql)))
		exiterr(4);

	while((row = mysql_fetch_row(res))) {
		for (i=0 ; i < mysql_num_fields(res); i++) 
			printf("%s\n",row[i]);
	}

	mysql_free_result(res);
	mysql_close(&mysql);
}
Sep 192010
 

Code formatting and indentation in VIM

Answer:

Vim support code formatting and auto indentation - if you tell Vim to know the filetype (either by file extension, or by setting the filetype)

e.g. A simple C program (test.c)


#include 

main()
{
for(int i=0;i<10;i++)
{ 
printf ("Hello World!\n");
}
}

Then type following in Vim command mode (by pressing Esc):

gg=G

Now the code will be formatted to:

#include 

main()
{
    for(int i=0;i<10;i++)
    {
        printf ("Hello World!\n");
    }
}