Archive for May 2010

 
 

OpenSuse 11.2 on Sony Vaio NS25G: Internal Microphone HOW-TO

On my fresh OpenSuse 11.2 setup, the VAIO inbuilt speakers worked well, but the internal mic did not seem to capture. KRecord and Skype did not pick the microphone inputs. Much tinkering and several days later…

My initial suspect of pulse-audio being broken was wrong. The following fix worked:

Dig into the Sound card hardware:

lspci | grep Audio
00:1b.0 Audio device: Intel Corporation 82801I (ICH9 Family) HD Audio Controller

This Intel-compatible audio controller would use the snd-hda-intel driver. Let’s find out:

yast_sound

From the Yast Control Center pick Hardware > Sound. In the screenshot below, the last line indicates the snd-hda-intel driver. Hit Edit and set the model option to toshiba-s06. Hit Next/Ok all the way thru.

YAST Sound Configuration

You can verify your settings out here:

sudo vi -R /etc/modprobe.d/50-sound.conf
options snd-hda-intel model=toshiba-s06

Use the alsamixer to make sure your speaker and capture volumes are cranked up.

alsamixer

alsa_mixer

The references below helped. The Ubuntu forums link below has references to other model names that might work for other laptop models.

[1] https://help.ubuntu.com/community/HdaIntelSoundHowto
[2] http://ubuntuforums.org/showthread.php?t=314383

Another Linux quickie – Determine your Linux distribution

I find myself staring at a remote shell, not knowing what Linux distribution the box is running. There does not seem to be any uname like universal command for this. Here are a few files to try:

OpenSuse:
cat /etc/SuSE-release
cat /etc/issue

Debian and it’s variants:
cat /etc/debian_version

RedHat:
cat/etc/redhat-release

Slackware:
cat /etc/slackware-version

And this one too:
dmesg | head -1

Penguin Notes: LCD Brightness, Firefox Annoyances

A few notes to self, trying to make my new OpenSuse desktop more hospitable.

Annoyance 1:
The laptop brightness controls did not adjust the brightness on KDE 4 running on OpenSuse 11.2. (They worked on Ubuntu Jaunty earlier). Neither could I find brightness sliders anywhere in KDE panels. This helped:

1
$ xbacklight -set 70

The value range is from 0 thru 100. Oddly, the laptop’s brightness shortcuts are BIOS controlled, so I wonder why they are dependent on the OS.

Annoyance 2:
A Ctrl+Bksp (Control + Backspace) on the Firefox address bar erased the entire address. I’m accustomed to using Ctrl + Bksp to erase segments of the URLs (“/” separated). The fix was in the Firefox “about:config”

  • Firefox Address bar: “about:config”
  • Filter by “layout”. Edit this item “layout.word_select.stop_at_punctuation”
  • Change that to a true

Referencing Spring Managed Beans from Non-Spring Java Code

I encountered the need to reference Spring managed beans from legacy Java code (i.e. Java code which is not managed by Spring).

An ideal approach is to avoid mixed-mode code and Spring’ify everything. But that’s not always an option in reality. Legacy projects could have a incremental migration to Spring.

Another option is to instantiate the bean object in your non-managed code. Since you would craft such an object by hand, you have to carefully ensure that all the object dependencies are satisfied. If you miss initializing some properties, you are likely to end up with NullPointerExceptions at runtime.

A preferred approach is to let Spring create and initialize the object for you and to get a handle to that object in your legacy code. We create a ApplicationContextAware bean as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
 
public class SpringApplicationContextAware implements ApplicationContextAware {
 
  private static ApplicationContext applicationContext;
 
  public void setApplicationContext(ApplicationContext context)
                                                        throws BeansException {
      applicationContext = context;
  }
 
  public static Object getBean(String beanName) {
      return applicationContext.getBean(beanName);
  }
 
}

We then declare a singleton instance of this bean using something like this in the Spring config:

1
2
<bean id="applicationContextAware" 
class="com.somedomain.somesubdomain.SpringApplicationContextAware"/>

At the time of Spring initialization, Spring will instantiate the bean defined above. And since the class implements the ApplicationContextAware interface, Spring will invoke the setApplicationContext() method on it.

We can then access any named Spring bean as follows:

1
MyBean bean = (MyBean) SpringApplicationContext.getBean("whackyBeanName");

If you prefer the new Annotation based configuration, then we can skip the declaration above and use something like this:

1
<context:component-scan base-package="com.somedomain.somesubdomain"/>

And use the @Component annotation on the bean as follows:

1
2
3
4
5
6
7
8
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
 
@Component
public class SpringApplicationContextAware implements ApplicationContextAware {
	...
}