headermask image

header image

(Solved) Suspend/resume (to ram) on Ubuntu/Kubuntu Hardy Heron and T60 with ATI graphic card

Making my T60 suspend and resume with Hardy Heron was almost trivial :)

You just have to make a few changes to /etc/default/acpi-support

POST_VIDEO=false
RADEON_LIGHT=true
ENABLE_LAPTOP_MODE=true

And that’s all!

If you also fixed logout and reboot issue (look at my other recent post), then you have a fully working machine!

Lucky you!

(Solved) Blank screen on logout/reboot with Ubuntu/Kubuntu Hardy Heron (8.04) on T60 with ATI card

After waiting a couple of weeks to see if there were any big bugs and problems with the new Ubuntu/Kubuntu Hardy Heron, 8.04, related to IBM/Lenovo T60 and ATI graphic card, I finally decided to give it a shot. Recent ATI.amd.com drivers had a lot of problems on Ubuntu machines. I really don’t know why. I think they don’t even try to install their own drivers. Because if they did, they would easily see so, so obvious problems. It’s crazy if you ask me.

Anyway, to proceed… Kubuntu installation went nice and smooth. I don’t really have screenshots of the installation process, but you’ve probably installed it yourself if you got to this page with google search :).

After installing Kubuntu asked me a couple of very nice questions. Like… would you like to install MP3 support? :) Of course, the answer was yes and it got installed. Then there was a question about proprietary ATI drivers… also yes.

Then, since I have two monitors at work, I had to type in the console:

sudo aticonfig --dtop=horizontal

to get an extended desktop configuration (Xinerama).

And then started the problems. On logging out or rebooting of machine all I got was a black screen. That sucks. I though it’s gonna go away when I configure everything, but no. Couldn’t set it up.

Finally, after a lot of time searching on the Internet and reading numerous pages, I’ve found a solution to my problem at the following webpage: http://ati.cchtml.com/show_bug.cgi?id=992

The X server will often freeze when logging out/ending the session.
...
I've mentioned in a previous post that I've got problems with X freezing on
logout/restart.
...
etc...

And then, in Comment #26 From Patrick Chevalley:

Today I solve the problem for my Kubuntu 7.10 / Catalyst 8.3

This is just because /etc/ati/authatieventsd.sh do not search the xauthority
file at the right location. It look like the default for xorg 7 is
/var/run/xauth and this default is used by kdm.

In /etc/ati/authatieventsd.sh, at the function GetServerAuthFile() add :

# Check xorg 7
XDM_AUTH_MASK=/var/run/xauth/A$1*
XDM_AUTH_FILE=`ls -t $XDM_AUTH_MASK 2>/dev/null | head -n 1`   # Choose the newest file
if [ -n "$XDM_AUTH_FILE" ]; then
SERVER_AUTH_FILE=$XDM_AUTH_FILE
DISP_SEARCH_STRING="#ffff#"
return 0
fi

If this not work for you, search if your distrib do not override this value
with AuthDir= in kdmrc file (maybe in /etc/kde3/kdm/kdmrc)

And it worked!

The final contents of /etc/ati/authatieventsd.sh are:

#!/bin/sh

#
# Control script grant/revoke access to X for the ATI External Events Daemon
#
# Distro maintainers may modify this reference script as necessary to conform
# to their distribution policies.
#
# Copyright (c) 2006, ATI Technologies Inc. All rights reserved.
#

#
# Parameters:
# $1 is a keyword, either "grant" or "revoke"
# $2 is the display name
# $3 is the X authorization file to be authorized
#
# Returns:
# 0 if authorization was successfully granted/revoked
# nonzero on failure
#
# Note:
# The third parameter only makes sense if xauth is being used. If another
# mechanism such as xhost is being used it can be ignored. For setups that
# do not do any form of authentication(!) this script can be trimmed down
# to just "exit 0" and the daemon will assume that it is always authorized.
#

GetServerAuthFile()
{
# Determine where the authorization key may be hiding. The location will
# vary depending upon whether X was started via xdm/kdm, gdm or startx, so
# check each one in turn.

# Check xorg 7
XDM_AUTH_MASK=/var/run/xauth/A$1*
XDM_AUTH_FILE=`ls -t $XDM_AUTH_MASK 2>/dev/null | head -n 1` # Choose the newest file
if [ -n "$XDM_AUTH_FILE" ]; then
SERVER_AUTH_FILE=$XDM_AUTH_FILE
DISP_SEARCH_STRING="#ffff#"
return 0
fi

# Check xdm/kdm

XDM_AUTH_MASK=/var/lib/xdm/authdir/authfiles/A$1*
XDM_AUTH_FILE=`ls -t $XDM_AUTH_MASK 2>/dev/null | head -n 1` # Choose the newest file
if [ -n "$XDM_AUTH_FILE" ]; then
SERVER_AUTH_FILE=$XDM_AUTH_FILE
DISP_SEARCH_STRING="#ffff#"
return 0
fi

# Check gdm

GDM_AUTH_FILE=/var/lib/gdm/$1.Xauth
if [ -e $GDM_AUTH_FILE ]; then
SERVER_AUTH_FILE=$GDM_AUTH_FILE
DISP_SEARCH_STRING="$1"
return 0
fi

# Finally, check for startx

for XPID in `pidof X`; do
TRIAL_XAUTH_FILE=`tr '\0' '\n' < /proc/$XPID/environ | grep -e "^XAUTHORITY=" | cut -d= -f2`
TRIAL_XAUTH_KEY=`xauth -f $TRIAL_XAUTH_FILE list | grep "unix$1"`
if [ -n "$TRIAL_XAUTH_KEY" ]; then
SERVER_AUTH_FILE=$TRIAL_XAUTH_FILE
DISP_SEARCH_STRING="unix$1"
return 0
fi
done

# Couldn't find the key

return -1
}

# Main part of script

#
# Since the daemon is usually started during init time before X comes up,
# $PATH may not yet contain the paths to the X binaries, particularly xauth.
# Add the usual location for where xauth may live and fail out if we still
# can't find it.
#

PATH=$PATH:/usr/bin:/usr/X11R6/bin
which xauth > /dev/null || exit -1

case "$1" in
grant)
GetServerAuthFile $2 || exit -1
DISP_AUTH_KEY=`xauth -f $SERVER_AUTH_FILE list | grep $DISP_SEARCH_STRING | awk '{ print $3 }'`
if [ -n "$DISP_AUTH_KEY" ]; then
xauth -f $3 add $2 . $DISP_AUTH_KEY || exit -1
else
exit -1
fi
;;

revoke)
xauth -f $3 remove $2 || exit -1
;;

*)
exit -1
;;
esac
exit 0

If you want you can overwrite the original contents of this file with the one pasted here. Or you can copy them from the pastebin if you have problems getting them from here: http://pastebin.com/f6e6ae392

I would really like if ATI/amd maintainers did their job and fixed the scripts at least for the mainstream distributions. It’s not like Ubuntu is not used by anyone…

I don’t really get it…

Anyway, “it works for me”, now :)

How to install Flash player in Mozilla Prism, in Ubuntu Gutsy (Linux)

I recently found out about Mozilla Prism (previously known as WebRunner).
This very nifty application allows you to run any ordinary web page as a desktop application! It adds a shortcut to the start menu and/or desktop, and on a click it opens a window, or an application, with just that web page inside.
No problems with slow browser (Firefox) starting - as this starts and runs very very fast. No problems with slowing down the rest of the browser because your Gmail is having problems - e.g. waiting for some Ajax request to complete.
All in all, really, really nice experience. Here’s a screenshot of the Prism in action:

Screenshot of Prism in action

Now, the first problem I faced was installing Adobe Flash player in all Prism applications. And here’s a solution for Linux ((K)Ubuntu Gutsy 7.10):

1. download flash plugin from http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash

2. unpack it, to get libflashplayer.so
you can use Ark for this, or

tar xzf install_flash_player_9_linux.tar.gz

1. by default Prism is installed to /opt/prism, so you should copy as root (superuser) libflashplayer.so to /opt/prism/xulrunner/plugins:

sudo cp libflashplayer.so /opt/prism/xulrunner/plugins

Close all open Prism applications and start again. And there you have it… Flash is running!

And a screenshot as a proof:

Prism running YouTube

Hehe… that’s it… enjoy!

Function for counting number of bits set to one, in a 32-bit word (in C)

I’ve found a great way to (efficiently) count number for bits set to one, in a 32-bit word.

So, here’s a function:

uint32_t count_nonzero_bits(uint32_t n)
{
  uint32_t masks[] = { 0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF };
  for(size_t i=0; i < 5; i++)
  {
    n = (n & masks[i]) + ((n >> (1 << i)) & masks[i]);
  }
  return n;
}

It could be easily extended to 64 bits or more, just by adding one (or more) masks.

And here’s a link to the original article: http://11011110.livejournal.com/38861.html

test for function for counting number of non-zero bits in a 32-bit word

Here’s a test for the previous function:


#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>

uint32_t count_nonzero_bits(uint32_t n)
{
  uint32_t masks[] = { 0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF };
  size_t i;
  for(i=0; i < 5; i++)
  {
    n = (n & masks[i]) + ((n >> (1 << i)) & masks[i]);
  }
  return n;
}
uint32_t count_nonzero_bits_slow(uint32_t n)
{
  uint32_t cnt=0;
  uint8_t tmp=0;
  while(n>0) {
    tmp = n&1;
    cnt += tmp;
    n >>= 1;
  }
  return cnt;
}

int main() {
  srand(time(0));
  uint32_t iter, X;
  for (iter=0; iter<1000; iter++) {
    X=rand();
    if (count_nonzero_bits(X)!=count_nonzero_bits_slow(X))
      printf("test failed (number=%u)\n", X);
  }
  printf("tests finished\n");
  return 0;
}

enjoy!

Hamachi on Kubuntu Linux doesn’t login… (Logging failed)

I’m a proud user of Hamachi. It’s a cross-platform VPN solution:
Hamachi is a zero-config VPN client for Windows and Linux (currently Beta for Mac). It allows you to, very easily, create a virtual private network that can be logged into and accessed for all over the net. It does this by creating IP tunnels to each VPN client, making them directly accessible to all the other clients on the VPN. Hamachi also encrypts the connections it creates to allow for secure access.”
Today, after a long time, I had a problem with it. It couln’t login to the Hamachi network. On Linux. On Windows it works fine after few retries (30s or so of retrying…). Therefore, the same mechanism can be used on Linux: retry until success :)

On my Kubuntu Gutsy 7.10, as well as on OpenSuse 10.1, I get the following message:
stomic@dell02:~> hamachi login
Logging in ….>.. failed
stomic@dell02:~> hamachi login
Logging in ….>.. failed
stomic@dell02:~> hamachi login
Logging in ….>.. failed
stomic@dell02:~> hamachi login
Logging in ….>.. failed

But this is boring…
So, I’ve wrote a one-liner that retries for 100 times, or until a login is successful:
CNT=1; echo -n “Logging in… ” ; while [ `hamachi login | grep -c failed` -eq 1 -a $CNT -lt 100 ]; do echo -n “$CNT “; let CNT=$CNT+1; sleep 2; done; echo

You should use this command instead of a simple “hamachi login”.
The output is now:

Logging in… 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

You can also make an alias for this command with the bash command:
alias “command”=”whatever”

Strategy DP

this design pattern should: “Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

Consider using it when (one of the following):

  • You have a volatile code that you can separate out of your application for easy maintenance
  • You want to avoid muddling how you handle a task by having to split implementation code over several inherited classes
  • You want to change the algorithm you use for a task at runtime


Decorator DP

This DP allows new/additional behaviour to be added to an existing method of an object dynamically.
The formal definition: “Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

The decorator pattern works by wrapping the new “decorator” object around the original object, which is typically achieved by passing the original object as a parameter to the constructor of the decorator, with the decorator implementing the new functionality. The interface of the original object needs to be maintained by the decorator.

Decorators are alternatives to subclassing. Subclassing adds behaviour at compile time whereas decorators provide a new behaviour at runtime.

This difference becomes most important when there are several independent ways of extending functionality. In some object-oriented programming languages, classes cannot be created at runtime, and it is typically not possible to predict what combinations of extensions will be needed at design time. This would mean that a new class would have to be made for every possible combination. By contrast, decorators are objects, created at runtime, and can be combined on a per-use basis. An example of the decorator pattern is the Java I/O Streams implementation.


Factory DP

This DP applies very valuable practice: “Separate the parts of your code that will change the most, from the rest of your applications. And always try to reuse those parts as much as possible“.
Abstract Factory Pattern provides a way to encapsulate a group of individual factories that have a common theme.
In normal usage, the client software would create a concrete implementation of the abstract factory and then use the generic interfaces to create the concrete objects that are part of the theme.
The client does not know (nor care) about which concrete objects it gets from each of these internal factories since it uses only the generic interfaces of their products.
This pattern separates the details of implementation of a set of objects from its general usage.

Mediator DP

Let’s say you have a four-page web site that lets users browse a store and make purchases. The user should be able to move from randomly from page to page.
Instead of modifying the code in each page to know when and how to jump to every new page and how to activate it, create a mediator class to encapsulate all the navigation code out of the separate pages and place it into a mediator object instead.
From then on, each page just has to report any change of state to the mediator, and the mediator knows what page to send the user to.

Adapter DP

(also called wrapper pattern, or simply wrapper)
You have an upgrade in the system, and the code now needs a new interface. But you already have the code that works with old-type objects.
Now, you create a adapter class that exposes the new interface and calls the already existing methods.
The adapter pattern is useful in situations where an already existing class provides some or all of the services you need but does not use the interface you need.

Proxy DP

Say that you’ve got some local code that’s used to dealing with a local object (only). But, if you want to deal with some remote object, somewhere else in the world.
You create a proxy, a stand-in for another object that makes the local code think it’s dealing with a local object. Behind the scenes, the proxy connects to the remote object, all the while making the local code believe it’s working with a local object.

Free Web Hosting - Page 1

Free Web Hosting - Page 1

very nice list of free web servers

search search - grep and less frontend

search
grep and less frontend

This script is used as a frontend to grep & less. Usually, grepping the source code tree for some string doesn’t yield a useful output. And it isn’t scrollable. So, I’ve written a simple frontend.

Put it somewhere in your path, and after that you can invoke it in the following way (for example):

The example shown above is for case-insensitive search (-i) in all subdirectories (by default) for a term ‘transactCPU’

As a result we get:


Not exactly point-and-click, but much better than original output.

You need to have installed grep and less.

I’m using Kubuntu 6.10 and VIM 7.0

Download here

Good luck!

programmer_hierarchy.png (PNG Image, 449×649 pixels)


programmer_hierarchy.png (PNG Image, 449×649 pixels)

haha :)
excellent :)