Thursday, April 10, 2008

units

GNU Units

With this program you enter in the units that you have and the units that you want to convert to, and the program tells you what to multiply by or divide by to get there.

You have: furlongs per fortnight
You want: mph
* 0.00037202455
/ 2687.9946

You have: kilowatt hours
You want: calories
* 859845.23
/ 1.163e-06

Labels:

Wednesday, April 09, 2008

Gutsy and 100% CPU usage... udevd going nuts.

This article seems to have the fix:
Upgrade to Ubuntu Gutsy - emvs and udevd 100% cpu usage - aka udevd going nuts

One typo I noticed: He refers to /etc/init.d/udevd instead of /etc/init.d/udev.

The corrected steps:
# apt-get remove evms
# /etc/init.d/udev stop
# /etc/init.d/udev start

Full set of articles on evms

Labels: ,

Thursday, January 10, 2008

DidiWiki 0.5 source code

DidiWiki is a very simple wiki written in C. I've been able to compile it for Cygwin and under Ubuntu.

didiwiki-0.5.tar.gz

Labels: ,

Friday, February 09, 2007

Using Native Data Structures in JNI

Linking a static library to Java using JNI

Beginning JNI Linux tutorial for Netbeans

Once I had accomplished the above with complete success, I extended the experiment by linking my static library (.a) to the dynamic library, and calling the static library function from the dynamic library function.

My HelloWorldNative.h:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class helloworld_Main */

#ifndef _Included_helloworld_Main
#define _Included_helloworld_Main
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: helloworld_Main
* Method: nativePrint
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_helloworld_Main_nativePrint
(JNIEnv *, jobject);

/*
* Class: helloworld_Main
* Method: nativePrintNumber
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_helloworld_Main_nativePrintNumber
(JNIEnv *, jobject, jint);

#ifdef __cplusplus
}
#endif
#endif

My HelloWorldNative.c:
#include <jni.h>

#include <stdio.h>

#include "../HelloWorldNative.h"

void hello();
void hello_number(int i);

JNIEXPORT void JNICALL Java_helloworld_Main_nativePrint(JNIEnv *env, jobject obj)
{
hello();
}

JNIEXPORT void JNICALL Java_helloworld_Main_nativePrintNumber
(JNIEnv *env, jobject obj, jint ji)
{
hello_number(ji);
}

My Main.java:
/*
* Main.java
*
* Created on February 9, 2007, 3:48 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package helloworld;

/**
*
* @author thomas
*/
public class Main {

private native void nativePrint();
private native void nativePrintNumber(int i);
/** Creates a new instance of Main */
public Main() {
}

static {
System.load("/home/thomas/src/c/testlib/HelloWorldNative/dist/HelloWorldNative.so");
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Main me = new Main();
me.nativePrint();
me.nativePrintNumber(2);
me.nativePrintNumber(5);
// TODO code application logic here
}

}

Linking a static library to Java using JNI

Beginning JNI Linux tutorial for Netbeans

Once I had accomplished the above with complete success, I extended the experiment by linking my static library (.a) to the dynamic library, and calling the static library function from the dynamic library function.

My HelloWorldNative.h:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include
/* Header for class helloworld_Main */

#ifndef _Included_helloworld_Main
#define _Included_helloworld_Main
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: helloworld_Main
* Method: nativePrint
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_helloworld_Main_nativePrint
(JNIEnv *, jobject);

/*
* Class: helloworld_Main
* Method: nativePrintNumber
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_helloworld_Main_nativePrintNumber
(JNIEnv *, jobject, jint);

#ifdef __cplusplus
}
#endif
#endif

My HelloWorldNative.c:
#include

#include

#include "../HelloWorldNative.h"

void hello();
void hello_number(int i);

JNIEXPORT void JNICALL Java_helloworld_Main_nativePrint(JNIEnv *env, jobject obj)
{
hello();
}

JNIEXPORT void JNICALL Java_helloworld_Main_nativePrintNumber
(JNIEnv *env, jobject obj, jint ji)
{
hello_number(ji);
}

My Main.java:
/*
* Main.java
*
* Created on February 9, 2007, 3:48 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package helloworld;

/**
*
* @author thomas
*/
public class Main {

private native void nativePrint();
private native void nativePrintNumber(int i);
/** Creates a new instance of Main */
public Main() {
}

static {
System.load("/home/thomas/src/c/testlib/HelloWorldNative/dist/HelloWorldNative.so");
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Main me = new Main();
me.nativePrint();
me.nativePrintNumber(2);
me.nativePrintNumber(5);
// TODO code application logic here
}

}

Thursday, February 08, 2007

Link java to a static library.

See last post, assume testlib has a void hello(void) function.

Step 1: Create a wrapper class.
public class TestLibWrapper {
public static native void hello();

static {
System.loadLibrary("testlib");
}
}

Step 2: Compile wrapper class.
javac TestLibWrapper.java

Step 3: Run javah to create C header and stub file.
javah TestLibWrapper

Step 4...

GNUmakefile for a basic library

GNUmakefile for a static library, testlib.a, including a single file, hello.c

OBJS = hello.o

CFILES := ${OBJS:.o=.c}
LDFLAGS =
ARFLAGS = rcv

all:: testlib.a

testlib.a: ${OBJS}
@$(AR) ${ARFLAGS} $@ $?

clean::
@$(RM) ${OBJS} testlib.a

Labels:

Sunday, February 04, 2007

More on update-alternatives

It appears that update-alternatives is a very handy facility in Debian derivatives for keeping track of the preferred application for specific tasks.

This seems to be a much SAFER than Windows way of handling things (i.e., let the application try to set itself as the default handler--a la IE vs. Firefox, whatever audio player you use, etc...).

This also seems to be much cleaner than what I've experienced in the past with Linux--maybe trying to override one browser with another, creating a random soft link, etc...

All such alternatives can be seen in the /etc/alternatives directory. On a Kubuntu 6.10 (Edgy Eft) box, one finds among the alternatives java, pager, x-terminal-emulator, x-window-manager, and x-www-browser. Some alternatives are used to point to specific versions of a program.

"update-alternatives --display " will display information about which alternative is selected.

"update-alternatives --list " will list alternatives.

"update-alternatives --config " allows the selection of a specific alternative.

The files which control the list of alternatives are in /var/lib/dpkg/alternatives.

Labels:

Tuesday, January 30, 2007

Selecting java alternatives

As root, run the following to see which alternatives are out there, and which one is selected as default:

update-alternatives --display java

As root, use the following to select default.

update-alternatives --config java

Monday, January 29, 2007

Research performed trying to get wireless card working on a laptop

"bcm4306 linux" search:
Dossy's Blog: Linksys WMP54GS with Broadcom chipset under Linux
How to Get One 802.11g Wireless Card to Work on Linux

"wmp54gs driver" search:
WinDrivers Computer Tech Support Forums - Linksys WMP54GS Wireless with Linux
HARDWARE wmp54gs - Gentoo Linux Wiki

"'no version of ndiswrapper found'"
Ndiswrapper Package Broken? [Archive] - Ubuntu Forums Conclusion: use 1.18 version of ndiswrapper in ubuntu.

"BCM43xx_IRQ_XMIT_ERROR" search
Problems with wlan bcm43xx - Ubuntu forums

Need to look into Linuxant:
Driverloader http://www.linuxant.com/driverloader/

1) Move wpa_supplicant binary to /usr/sbin/ and rename to "dldr_wpa_supplicant"
2) Move wpa_supplicant.conf to /etc/driverloader/ and rename to dldr_wpa_supplicant..conf, where interface is your interface name (mine was eth1)
3) Reboot

Tried adding pci=routeirq to boot parameters in /boot/grub/menu.lst

Monday, January 22, 2007

I never learned this in school.

Actually, I haven't had to format a Linux partition manually since (maybe) I experimented with Slackware in 1995. So, when I had a nice little 400 GB USB HD with three partitions (two NTFS, one Linux), I was somewhat at a loss as to how to proceed.

I found this handy guide to partitioning and formatting mkfs.ext3.

Ahhh... I have access now.

Labels:

Tuesday, January 16, 2007

Quick ascii table in hex.

The Linux Quick Hacks page inspired on this one:

perl -e 'foreach $x (32..126) { printf(":: %c %x ::", $x, $x) } print "\n"'

Output:
:: 20 :::: ! 21 :::: " 22 :::: # 23 :::: $ 24 :::: % 25 :::: & 26 :::: ' 27 ::
:: ( 28 :::: ) 29 :::: * 2a :::: + 2b :::: , 2c :::: - 2d :::: . 2e :::: / 2f ::
:: 0 30 :::: 1 31 :::: 2 32 :::: 3 33 :::: 4 34 :::: 5 35 :::: 6 36 :::: 7 37 ::
:: 8 38 :::: 9 39 :::: : 3a :::: ; 3b :::: < 3c :::: = 3d :::: > 3e :::: ? 3f ::
:: @ 40 :::: A 41 :::: B 42 :::: C 43 :::: D 44 :::: E 45 :::: F 46 :::: G 47 ::
:: H 48 :::: I 49 :::: J 4a :::: K 4b :::: L 4c :::: M 4d :::: N 4e :::: O 4f ::
:: P 50 :::: Q 51 :::: R 52 :::: S 53 :::: T 54 :::: U 55 :::: V 56 :::: W 57 ::
:: X 58 :::: Y 59 :::: Z 5a :::: [ 5b :::: \ 5c :::: ] 5d :::: ^ 5e :::: _ 5f ::
:: ` 60 :::: a 61 :::: b 62 :::: c 63 :::: d 64 :::: e 65 :::: f 66 :::: g 67 ::
:: h 68 :::: i 69 :::: j 6a :::: k 6b :::: l 6c :::: m 6d :::: n 6e :::: o 6f ::
:: p 70 :::: q 71 :::: r 72 :::: s 73 :::: t 74 :::: u 75 :::: v 76 :::: w 77 ::
:: x 78 :::: y 79 :::: z 7a :::: { 7b :::: | 7c :::: } 7d :::: ~ 7e ::

Saturday, January 13, 2007

sed guides.

I'm using sed (along with awk and shell scripts) to extract data from my website files.

Frequently Asked Questions about sed, the stream editor

sed one-liners

Colorized list_urls.sed

Wednesday, January 10, 2007

sed/sh/awk removing a section in multiple files

All of my scripts are in ~/bin, I'm replacing a marked section with my google adsense code, contained in a separate file.

remove_topstart.sh:
#!/bin/sh
find . -name '*.html' | while read x
do
   cat $x | awk -f ~/bin/remove_topstart.awk >> $x.$$
   cp $x.$ $x
   rm $x.$
done


remove_topstart.awk:
BEGIN { outsideTop = 1 }
/<!--TOPSTART-->/ { outsideTop = 0 }
/<!--TOPEND-->/ { outsideTop = 1 }
outsideTop {
   if( $0 !~ "<!--TOPEND-->" )
   {
      print $0
   }
}

insert_adsense.sh:
#!/bin/sh
#my.adsense.txt contains as its first line and as
#its last line.


#insert after tag, regardless of case.
#change index.html in current directory
cat index.html | sed '/<[Bb][Oo][Dd][Yy]>/r /home/thomas/my.adsense.txt' > index.html.$$
cp index.html.$ index.html
rm index.html.$

#change all *.html files in selected subdirectories
find . -name '*.html' | egrep "SubDir1|SubDir2|SubDir3|SubDir4|SubDir5" | while read x
do
   cat $x | sed '/<[Bb][Oo][Dd][Yy]>/r /home/thomas/my.adsense.txt' > $x.$$
   cp $x.$$ $x
   rm $x.$$
done

Labels:

Tuesday, January 09, 2007

IE 4 Linux

Internet Explorer on Linux
http://webexpose.org/2007/01/07/internet-explorer-7-on-linux/

http://www.tatanka.com.br/ies4linux/page/Installation
IEs 4 Linux needs two packages: cabextract and Wine. You can install them using your Linux package manager (synaptic, apt-get, yum, emerge etc) or go to their sites.
wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-latest.tar.gz
tar zxvf ies4linux-latest.tar.gz
cd ies4linux-*
./ies4linux

Monday, January 08, 2007

Research on adding a wireless card using WPA in Ubuntu

I've just begun to research WPA + PCI wireless card in Ubuntu.

Follow installation instructions for ndiswrapper:
http://ndiswrapper.sourceforge.net/mediawiki/index.php/Installation

Using a ZyXEL card:
http://ndiswrapper.sourceforge.net/mediawiki/index.php/List#Z

Tools to use:
  • iwconfig - to configure wireless network interface.
  • iwlist wlan0 scan - scan for access points using wlan0 interface
WPA with ndiswrapper:
http://ndiswrapper.sourceforge.net/mediawiki/index.php/WPA

Friday, December 29, 2006

Log of setting up a "test" virtual server on apache2 under Linux.

Equipment HP Pavilion 6745C/700 MHz Celeron/256MB ram. I'm using gvim as an editor.

Step 1, Add host to /etc/hosts:

sudo gvim /etc/hosts
Before the IPv6 section (if you have one), add:
127.0.0.1 latte
In this case "latte" is my virtual hostname.

Step 2, Add a new configuration file for the virtual host:
cd /etc/apache2/sites-available
cp default latte.conf
The naming of the configuration file is somewhat arbitrary, but I used {hostname description}.conf.

Step 3, Edit the configuration file:
sudo gvim latte.conf

Change the following lines and save your configuration file:
NameVirtualHost *

DocumentRoot /var/www

to the following:
NameVirtualHost latte

DocumentRoot /var/www/latte

Your original "DocumentRoot" may be different, but the new value should be the root directory for website files.

Step 4, Link to the configuration file in the "sites-enabled" directory:
cd /etc/apache2/sites-enabled/
sudo ln -s /etc/apache2/sites-available/latte.conf latte.conf

or in Debian (and by derivation, Ubuntu):
a2ensite latte.conf

Step 5, Reload the apache configuration file:
sudo /etc/init.d/apache2 reload

Step 6, Browse to your virtual server to check your work:
firefox http://latte

Wednesday, December 27, 2006

Manually adding a PCI display card.

Equipment/Software:

  • HP Pavilion 6745C

  • 256 MB ram

  • Kubuntu 6.10 (Edgy Eft)

  • eVGA (nVidia) GeForce4 MX 4000 PCI



I've had persistent problems with the i810 on-board vga with virtually every install of Linux that I've tried with this PC (with the exception of damnsmalllinux). Between that and its poor performance, I added a MX 4000 to this PC. However, recent distributions have failed to even properly recognize the card at install/configuration time, so I had to take some indirect steps to add the device.

Step 1:
Install Kubuntu using i810. This required setting bios to use the "AGP" video card (in this case AGP=onboard video). I had the MX 4000 PCI card installed for this as well, but not hooked to a monitor.

Step 2:
Run "lspci" at a shell prompt. At the end of my listing was:
01:0d.0 VGA compatible controller: nVidia Corporation NV18 [GeForce4 MX 4000 AGP 8x] (rev c1)


Step 3:
At a shell prompt, run "sudo vim /etc/X11/xorg.conf" (substitute your favorite editor for vim). I copied and pasted the following section:

Section "Device"
Identifier "Intel Corporation 82810 ..."
Driver "i810"
BusID "PCI:0:1:0"
EndSection

I modified my new section to read:

Section "Device"
Identifier "NVidia"
Driver "nv"
BusID "PCI:1:13:0"
EndSection

The "Identifier" value must be copied in a later section, so the value doesn't matter as much as the consistency of that value. The 1:13:0 is from the lspci output (01:0d.0, where 0d in hex = 13 in decimal). "nv" is the free nVidia compatible driver. I may later apply the proper nVidia driver (instructions in a previous post).

Step 4:
Still in xorg.conf, I modified the "Screen" section (Section "Screen") by replacing "Intel Corporation 82810..." with "NVidia" on the Device line.

Section "Screen"
Identifier "Default Screen"
Device "Nvidia"


Step 5:
Save xorg.conf and restart X (Ctrl-Alt-Bksp on an X screen). X will now start on the nVidia card.

Step 6:
Reboot, switch bios to use "PCI" as the primary display. Save BIOS.

Step 7:
Plug monitor into nVidia card, and boot with new BIOS settings.

TODO:
- Get both devices working on this PC as two separate displays.
- Install "proper" nVidia drivers.

Tuesday, December 26, 2006

Discovered bluetooth keyboard and mouse was not working.

More fallout from upgrading to Edgy Eft, my bluetooth keyboard and mouse no longer worked. This post on ubuntu forums was the best consolidated set of instructions on how to configure bluetooth (which worked without configuration before upgrade, by the way).

I ended using "/etc/init.d/bluetooth restart" instead of "/etc/init.d/bluez-utils restart". However, I've only been able to restore the connection to my mouse, not my keyboard.

HOWTO: Bluetooth Keyboard and Mouse