Posted by: rydow | October 26, 2007

C Code to redirect stdout

This link http://www.cs.purdue.edu/homes/cs354/LectureNotes/Spring2002/week6-3 gives a good understanding on what happens in the below code:

static int pipePair[2];
static int oldstdout;

static int redirectStdOut(void)
{
  oldstdout = dup(STDOUT_FILENO);

  if ( pipe(pipePair) != 0){
    return -1;
  }

  dup2(pipePair[1], STDOUT_FILENO);
  close (pipePair[1]);
  return pipePair[0];
}
static void restoreStdOut(void)
{
  dup2(oldstdout, STDOUT_FILENO);

  close(pipePair[0]);
  pipePair[0] = -1;
}

The above is by no means meant to be complete, but gives an implementation to start from when testing code that uses e.g. printf. Reading the pipePair[0] gives what printf etc. would have written to stdout. We have essentially made ourselves a printf stub.

Posted by: rydow | September 18, 2007

Sony ericsson as a bluetooth remote.

Under ubuntu do the following:

Edit /etc/blutooth/hcid.conf sectionHCI devices class 0x100100

Edit /etc/default/bluetooth (bluez-utils on older versions) HIDD_ENABLED=1

Run sudo /etc/init.d/bluetooth restart (bluez-utils on older versions)

Pair the phone and the box from the phone (search and add bt devices)

Run hcitool scan to see the address of your phone and use that address to do

sudo hidd –connect 00:11:22:33:44:55

Before doing that I got error messages of the type:
"hidd[11565]: Rejected connection from unknown device 00:11:22:33:44:55"on ubuntu 7.04 and
"hidd[5087]: HID create error 84 (Invalid or incomplete multibyte or wide character)" on ubuntu 6.06

Now it should be possible to connect from phone to box (amusements, remote). The steps have been tested to work on K750i, W810i and K810i

The above is condensed from these pages, first second

Note that much things from the second link does not apply on modern ubuntus.

Posted by: rydow | September 17, 2007

Selective undo in emacs

Sometimes it is handy to to be able to undo in just a specific region. You have done a lot of editing and the code broke in a specific function which of course used to work…

The trick is to do C-<space> in the beginning of the function and moving down to the end of the function and pressing C-u C-_ to undo changes only in the region you have marked.

Posted by: rydow | September 7, 2007

Jumping to errors in emacs

When compiling (M-x compile) or searching (M-x grep-find) you get a list in another window. To jump to the first hit in the list do C-x ` (backtick). Repeat to jump to the next entry.

Posted by: rydow | August 24, 2007

Backup home with rsync

I have usb disk on which I make backups. It is formatted ext2 so that permission stuff works.

I use rsync on all of home like this:
sudo rsync -a -u –progress /home /media/SEA_DISC

Posted by: rydow | August 24, 2007

Awk reminder.

Since I don’t us awk very regularly nowadays I thought it would be nice to have the basic use case somwhere. So here are some examples:

  • Get the process id of syslogd, and yes i know that it could be done simpler with the right ps switches, but the point is demonstrate awk right!
    ps -e | grep -v awk | awk 'BEGIN{FS=" "}/syslogd/{printf $1"\n"}'
    The BEGIN{…} clause may be skipped in this case since whitespace is default field separator. The stuff inbetween the slashes is a regexp and the grep -v is to not get the awk process itself in the answer.
  • awk 'BEGIN {FS = "-"; max = 0;}{if ($2 > max) max = $2;} END {print $1 "-" max}'
    This one uses calculations on a list loocking like this:
    image1-800
    image1-1024
    image1-1280

That’s all for now, have a nice weekend!

Posted by: rydow | August 13, 2007

Modify cvs message

Back from a six weeks holiday and totally dizzy, I am supposed to work 8 hours a day again from now on. What a chock!

If a version is already committed in cvs it is possible to change the log entry by using:

cvs admin -m rev:msg file

Posted by: rydow | August 6, 2007

Getting Ubuntu 7.04 to run on a Dell d830

Last week of this years summer vacation I decided to make my new Dell d830 usable by installing ubuntu 7.04 to dual boot with XP.

First I installed ubuntu with the alternate cd, the normal one failed miserably. I basically followed these threads: this and this

  • xserver:
    After basic installation the x server did not work so I updated a bit with:
    sudo apt-get update
    sudo apt-get dist-upgrade
    sudo apt-get install xserver-xorg-video-intel
    sudo dpkg-reconfigure xserver-xorg
    and skipped auto detect monitor and running screen at1280x800@60 Hz. Since the screen was not showing colours correctly I installed this
  • Wireless: taken from here
    sudo gedit /etc/network/interfaces
    Comment out everything other than “lo” entries in that file and save the file
    Create a file called /etc/default/wpasupplicant, add entry ENABLED=0 and save the file
    Reboot your system or use the following command
    sudo /etc/init.d/dbus restart
  • cd:
    sudo modprobe ata_piix
    sudo modprobe ata_generic
    sudo gedit /etc/modules
    and add the line piix (not ata_piix)

Update: Decided to try out changing the touchpad behaviour with the instructions found here. I also relalized that some of the above links do not work if one is not logged in into the ubuntuforums. Another remaining issue is that the pointing pin a la IBM thinkpads does not work for clicking, it does however work to move the pointer.

2007-09-18 Update:

I have now tried bluetooth which essentially work out of the box with obex (file transfer here and there). It is also possible to get a Sony ericsson phone work as a remote control saving you the trouble of leaving the bed after watching Life of Brian to turn off the computer, really cool! Take a look here.

Posted by: rydow | June 25, 2007

Emacs search completion.

When searching with emacs it is possible to complete the search with the word you are standing on like this:

C-sC-w also try C-sM-p which moves backwards in the search ring.

Posted by: rydow | June 23, 2007

Some emacs commands work in bash.

If you use bash and know your emacs commands you might have discovered that some of them work in bash. The ones I find most useful are:

  • C-k kill line
  • C-y yank killed line
  • C-a move cursor to beginning of line
  • C-e move cursor to end of line
  • M-d kill to end of word

« Newer Posts - Older Posts »

Categories