Get latest bleeding edge gfx drivers in Ubuntu

June 18th, 2010

Want the latest of the latest updated bleeding edge graphic drivers in Ubuntu?

Open /etc/apt/sources.list:

sudo gedit /etc/apt/sources.list

Add these lines at the bottom:

deb http://ppa.launchpad.net/xorg-edgers/ubuntu lucid main
deb-src http://ppa.launchpad.net/xorg-edgers/ubuntu lucid main

Update and upgrade:

sudo apt-get update
sudo apt-get upgrade

If you don’t use Lucid (Ubuntu 10.04) just change “lucid” to what ever you use, for example ‘karmic’.

Enjoy :)

Generate random string in PHP

June 18th, 2010

Here’s a function to create a random string with the chars ‘a’ to ‘z’, ‘A’ to ‘Z’ and 0 to 9 in PHP.
I have seen many people asking for this, so here it is:

<?php

function randStr($length, $str='') {
	$array = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9));
    for($i = 0; $i < $length; $i++) {
        $str .= $array[rand(0, (count($array) - 1))];
    }
    return $str;
}

?>

Add Tweet with C++/Qt4

May 25th, 2010

Qt logoThis is a code from my Twitter client for how to send a Http request from C++/Qt4 to add your status message…

It used the QNetworkAccessManager class instead of the deprecated QHttp.

#include <QtCore>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>

void main(int argc, char ** argv)
{
    QString unescaped = "<My status update!>";
    QString data = "status=" + QUrl::toPercentEncoding(unescaped.toLatin1());
    QString auth = "<Username>" + ":" + "<Password>";
    QString encryptedAuth = auth.toAscii().toBase64();
    QNetworkAccessManager* manager = new QNetworkAccessManager(this);
    QNetworkRequest request;
    QNetworkReply *reply;
    request.setUrl(QUrl("http://twitter.com/statuses/update.xml"));
    request.setRawHeader(QByteArray("Host"), "twitter.com");
    request.setRawHeader(QByteArray("Content-Type"), "application/x-www-form-urlencoded");
    request.setRawHeader(QByteArray("User-Agent"), "Mozilla");
    request.setRawHeader(QByteArray("Authorization"), "Basic " + encryptedAuth.toAscii());
    QByteArray postData(data.toLatin1(), data.length());
    reply = manager->post(request, postData);
}

Google Showing off HTML5

May 21st, 2010

Today I opened my favorite web browser Chrome and then suddently I heard the Pac-man theme melody and there it was, a pac-man game as the Google logo written in HTML5 to celebrate Pacman’s 30th birthday. I also noticed a nice virtuel keypad as shown in the screenshot down the page, but only in the Norwegian google site (google.no).

I guess this is to show the world the power of HTML5 and that the developement are highly in progress :)

googlepacman

Hit insert coin, and you will get Ms. Pac-man which you control with the asdf buttons :)

Free Up Some Ubuntu Space!

May 19th, 2010

cleaning up ubuntuHaving trouble cleaning up space for your Ubuntu installation?
I only have a 4GB SSD drive on my Lenovo S10e netbook, so I have the problem myself. Here are some handy tips for you!

Remove files not needed

sudo apt-get autoremove

Remove all stored archives in the cache

Basically it clears up the ‘/var/cache/apt/archives/’ and ‘/var/cache/apt/archives/partial’ folders

sudo apt-get clean

Remove package files that can no longer be downloaded

sudo apt-get autoclean

Remove locale data

This will remove unneeded locale files and localized man pages.

sudo apt-get install localepurge

Run it:

localepurge

A window will pop up. There choose your language. I use English, therefor I chose “en”.
Ignore the capitalized ones.

Remove orphaned packages

It shows you which packages that have no other packages depending on them.

sudo apt-get install deborphan

Run it:

sudo deborphan | xargs sudo apt-get -y remove --purge

Cleaning up log files

sudo find /var/log -type f -exec rm {} \;

Cleaning up doc files (use only when desperate use of space)

sudo rm -rf /usr/share/doc/*

Remove Linux kernels not in use

Check what kernel you are using:

uname -r

Goto System->Administration->Synaptic Package Manager

Search for “Linux” and mark all Linux header/kernel files which you are not currently using for complete removal. Then hit ‘apply’.