Sound makes crakling static noises.

June 18th, 2009

The sound in my ubuntu 9.04 stopped working correctly, and instead of playing a song, all I heard was static.

I tried a number of different things such as restarting pulseaudio and reloading the kernel modules. But the problem was that the PCM mixer’s volume was muted, and a way to change it is with alsamixer.

 alsamixer -Dhw

admin GNU/Linux, Ubuntu, troubleshoothing

keys stop working when using VMWare under Ubuntu

May 7th, 2009

Sometimes the keyboard stops working properly when I run windows inside a VMWare virtual machine. The key bindings gets all screwed up and the the cap locks, shift, and ctrl keys stop working.

As a workaround you can just execute setxkbmap in to remap the the keyboard.

https://bugs.launchpad.net/ubuntu/+source/linux/+bug/195982

admin GNU/Linux, Ubuntu

VIm commands for Programmers

March 10th, 2009

These are the VIm commands I found most useful for coding.

Find And Replace

:%s/old/new/g Replace all occurences of “old” by “new” in file
:%s/old/new/gw Replace all occurences with confirmation
:2,35s/old/new/g Replace all occurences between lines 2 and 35
:5,$s/old/new/g Replace all occurences from line 5 to EOF
:%s/^/hello/g Replace the begining of each line by “hello”
:%s/$/Harry/g Replace the end of each line by “Harry”
:%s/onward/forward/gi Replace “onward” by “forward” , case unsensitive
:%s/ *$//g Delete all white spaces
:g/string/d Delete all lines containing “string”
:v/string/d Delete all lines containing which didn’t contain “string”
:s/Bill/Steve/ Replace the first occurence of “Bill” by “Steve” in current line
:s/Bill/Steve/g Replace “Bill” by “Steve” in current line
:%s/Bill/Steve/g Replace “Bill” by “Steve” in all the file
:%s/\r//g Delete DOS carriage returns (^M)
:%s/\r/\r/g Transform DOS carriage returns in returns
:%s#<[^>]\+>##g Delete HTML tags but keeps text
:%s/^\(.*\)\n\1$/\1/ Delete lines which appears twice
Ctrl+a Increment number under the cursor
Ctrl+x Decrement number under cursor
ggVGg? Change text to Rot13

Indentation

:set autoindent Turn on auto-indent
:set smartindent Turn on intelligent auto-indent
:set shiftwidth=4 Defines 4 spaces as indent size
ctrl-t, ctrl-d Indent/un-indent in insert mode
>> Indent
<< Un-indent

Syntax highlighting

:syntax on Turn on syntax highlighting
:set syntax=java Force syntax highlighting (try java, perl, python, etc)

admin GNU/Linux, Programming, Tools , , ,

Retrieving Query String Parameters from a JSF Managed bean

February 24th, 2009

Here is a way of retrieving the a query string parameter from a URL. (e.g. http://localhost/app/details.faces?userId=1)


HttpServletRequest request = (HttpServletRequest) FacesContext.
                                        getCurrentInstance().
                                        getExternalContext().
                                        getRequest();
String ID = request.getParameter("userId");

admin JSF, Java, Programming

libnotify

February 21st, 2009

libnotify allows a program send a notification to your desktop through notification-daemon.

To be able to use it in your code you’ll need the appropriate header files and shared library to link against which can be found in the libnotify-dev package.

Here is a sample program taken from the libnotify package source.

#include <libnotify/notify.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char * argv[] )
{
    NotifyNotification *n;  

    notify_init("Basics");

    n = notify_notification_new ("Foo",
                                 "Bar",
                                  NULL, NULL);
    notify_notification_set_timeout (n, 5000); // 5 seconds

    if (!notify_notification_show (n, NULL))
    {
	fprintf(stderr, "failed to send notificationn");
	return 1;
    }

    g_object_unref(G_OBJECT(n));

    return 0;
}

libnotify-run

Alternatively, here is the same program in python.

import pynotify
pynotify.init(’foo’);
pynotify.Notification(’foo’, ‘bar’).show()

admin C/C++, GNU/Linux, Programming, Python , , ,

Hello world!

February 21st, 2009

w00t! First post.

admin Uncategorized