Sunday, 7 February 2010

Small issue with Gitorious

I created a simple project to gitorious.org so that I can easily work on it from several locations. Of course I had issues, from one location I had problems getting through the firewall but I also had a minor issue from home.

Gitorious tells that I can clone the repository with
git clone http://git.gitorious.org/scheator/scheator.git


which worked but when I tried to push I got this error:

fatal: protocol error: expected sha/ref, got '
----------------------------------------------
The git:// protocol is read-only.

Please use the push url as listed on the repository page.
----------------------------------------------'


Reason is that the url for the repository is incorrect in .git/config. It looked like
url = git://gitorious.org/scheator/scheator.git


when in fact it should look like
url = git@gitorious.org:scheator/scheator.git


After I fixed that, it works. I can't figure out why this can't be correct in the first place without the need to fix it by hand.

Wednesday, 3 February 2010

NetBeans not finding the main class

Oh man, this was an annoying problem. I suddenly got the error "Main class not found" from NetBeans even though everything was ok (the class was there, so was main(), project properties were correct etc). After some digging I found the simplest of solutions:
touch the main class file, i.e. change the date so that NetBeans detects it has been changed and recompile.


Whew. I was getting worried there for a moment.

Wednesday, 20 January 2010

Things I should know

It's surprising how little math us programmers know, me included. You would think that working on something that is more or less completely based on mathematics (deep down, your computer is basically just adding, subtracting, comparing and moving numbers) people on the field would know it. Well, that's not true, and a lot of it has to do with the fact how it is handled in school and university. Steve Yegge has a great article about the whole issue. It's actually so great I got an urge to learn it myself! Well, I'll enroll to an algorithms course next Autumn in any case..

And sometimes you run into articles that make you say wow, because you thought you knew most of the stuff, at least in principle. This document by Brian Kernighan of C and Unix fame back from 1984 did that to me. Wow. Simply wow. What is intriguing is what this should mean for open source software. One of the big principles of OSS is that a lot of people can check it so the likelihood of it having Trojan horses is small. Is it, really?

Saturday, 9 January 2010

Checking ISBN with Java

I couldn't find any Java implementation to check both ISBN-10 and ISBN-13 so I wrote my own from scratch for a small assignment I had. The code can be downloaded here and anybody is welcome to use it as they please. It's a bit too long to copy to this blog directly, sorry. Using it should be easy enough.

Wednesday, 16 December 2009

TortoiseGit

I have been worrying about poor GUI support for Git because that is a major factor for many people not to use it. Especially true in companies where Git would cause some extra costs, at least initially.

Lo and behold, meet TortoiseGit.

Tuesday, 8 December 2009

Finding ALSA devices programmatically

Finding out the ALSA audio devices in a Linux box programmatically can be a bit tricky. I did it like this:

/**
* Reads audio devices from ALSA interface and returns count and array of
* strings containing the devices.
*
* @param[out] count Number of devices found.
* @param[out] Array of strings containing the device names.
*
*/
static void getALSADevices(int *count, char **devices)
{
void **hints;
const char *ifaces[] = {"card", "pcm", "rawmidi", "timer", "seq", "hwdep", 0};
int index = 0;
void **str;
char *name;
char *desc;
char *io;
char *name_tmp;
char *desc_tmp;
int devIdx = 0;
int len;

snd_config_update();

while (ifaces[index]) {

printf(" --- Trying interface %s ---\n", ifaces[index]);
if (snd_device_name_hint(-1, ifaces[index], &hints) < 0) {
printf("Querying devices failed for %s.\n", ifaces[index]);
index++;
continue;
}

str = hints;

while (*str) {
name = snd_device_name_get_hint(*str, "NAME");
desc = snd_device_name_get_hint(*str, "DESC");
io = snd_device_name_get_hint(*str, "IOID");

len = strlen(name)+1;
name_tmp = (char*)malloc(len);
devices[devIdx] = name_tmp;
strcpy(name_tmp, name);
devices[devIdx][len-1] = '\0';

printf("\n-- %s --\n", name);
printf("IO: %s\n", io);

desc_tmp = strtok(desc, "\n");

while (desc_tmp != NULL) {
printf("%s\n", desc_tmp);
desc_tmp = strtok(NULL, "\n");
}

free(name);
free(desc);
devIdx++;
str++;
}
index++;
snd_device_name_free_hint(hints);
}
*count = devIdx;
return;
}


Of course if you don't need to do it yourself, you can use the aplay command from the shell.

Monday, 7 December 2009

Debugging in Linux with advanced IDE's

This took me a while to figure out. I have been trying out several different IDE's for Linux C development (KDevelop, Code::Blocks, NetBeans) and I only managed to get debugging work like I wanted (e.g. code stepping, local variables etc) in Code::Blocks.

Finally I figured out why: I was compiling the code incorrectly. I thought I was doing it right, but I was actually only giving the -ggdb flag to the linker. Code::Blocks worked because it creates a new project for you and knows how to compile for a debug compilation.

KDevelop is just poor, it keeps crashing and the interface is rather unintuitive (how to use a Makefile and how to compile an application without a GUI?). Code::Blocks is nice, if ugly-looking but unfortunately it doesn't want to use the original Makefile. NetBeans is big and slow, but supports the Makefile directly. It's going to be a tough choice between Code::Blocks and NetBeans...

The only thing going for KDevelop is it has support for git, but then again, you can use it from the command line....

But how to do the Makefile correctly:

CC = gcc

CCFLAGS = -Wall -ggdb3

VPATH = /usr/include/

OBJS = file1.o file2.o file3.o

%.o: %.c
${CC} ${CCFLAGS} -c $< hwcheck: ${OBJS} ${CC} ${CCFLAGS} ${OBJS} -o myapp clean: rm -f myapp *.o
After that all the debugger options work inside the IDE.