|
Sunday, November 29. 2009
I needed to plot data from a program in real-time for a demo, that is, as the program generates the data, I wanted it to show in some nice diagram.
A friend pointed me to Visualize real-time data streams with Gnuplot by Thanassis Tsiodras, which is very nice: you specify the number of streams to plot and where to plot them, and feed it with lines like '0:1.23', '1:2.3', etc. defining the data points for the individual streams (here: first point on stream 0 is 1.23, first point on stream 1 is 2.3, etc.).
However, I needed to plot several streams in a single window, which that version lacked. So I extended that program with the ability to plot several streams into a single window (download).
For this, you specify both the number of streams you want to plot and the number of windows you want to show. Furthermore, you specify in which window each stream is plotted. I kept as much as possible of the original command line interface to ease the transition to this new version. The result looks like this:
Continue reading "Plotting data with gnuplot in real-time"
Friday, January 30. 2009
Who's designing the error messages of g++? Anyways, here is a translation:
error: request for member ‘foo’ in ‘((Test*)this)->Test::_bar’,
which is of non-class type ‘C_bar*’
means: in class Test, you've written _bar.foo, but _bar is a pointer; you need to write _bar->foo, that is, change the dot to an arrow.
Happy C++ coding!
Tuesday, January 27. 2009
I just stumbled over my python code, similar to the following one, which raises an UnboundLocalError in the first line of push:
def func_stack1():
stack = []
def push(num):
print "stack before: ", stack
stack = stack + [num]
print "stack after: ", stack
return push
push = func_stack1()
push(1)
Continue reading "Global and local variables in python"
Thursday, November 6. 2008
I wanted to 'upgrade' my python from 2.5 to 2.6 on Ubuntu. Unfortunately, I could not find .deb packages for Ubuntu. Fortunately, the Python 2.6 sources (sig) are available, so I can compile it from source. Here's what I had to do to get it running. (Short version: apt-get build-dep python2.5 and apply this patch to disable unavailable and outdated modules.)
Continue reading "Installing Python 2.6 on Ubuntu 8.04"
Saturday, May 17. 2008
I gvim, if you set
:setlocal spell spelllang=en_us
gvim will spell-check your file and underline wrongly spelled words with a red line much like you know it from OpenOffice. If you
:set mousemodel=popup
you can even right click on any misspelled word to get a list of suggested corrections.
However, this sometimes did not work for me. I could not figure out a reason, until I read the help docs again, which clearly say:
Note for GTK: don't release the right mouse button until the menu appears,
otherwise it won't work.
They actually mean what they say: if I release the right mouse button too fast, the menu appears, but it does not replace the misspelled word with the corrected word. Only if keep the right mouse pressed until the menu appears, it works, for whatever reason. RTFM!
Tuesday, May 6. 2008
If you link a static library to your executable, the GNU linker ld (as many others) only adds those symbols that ld thinks are actually used in your executable (that's a feature). Unfortunately, ld can only check if the symbol is in use, but not if the side effects of the symbol's initialization is used. Thus, your program will fail if it depends on the initialization of an unused static object.
In my case, I have a factory (class module::factory<T> : public factory_plant {...} factory;) at which classes can register themselves with a name (module::factory<Group> f("Group")). If I call the factory with a name (factory.create("Group")), the factory returns a pointer to a newly created class associated with that name. The class registers itself via a static object (here: f) whose initialization code does the actual registration.
The problem arises if the class is not used directly and the linker throws the static object away. The registration does not happen and thus I can't use the factory to create an object of the class. There are several possibilities to work around this feature:
Use --whole-archive to tell the linker to include all symbols, no matter what (with gcc use -Wl,--whole-archive -lmylib -Wl,--no-whole-archive). The drawback is that symbols that I neither use nor care about are also included, resulting in increased code size.
Use -u<symbol> to tell the linker to treat <symbol> as if undefined and thus include it in the executable, even it is not used. The drawback here is to know what <symbol> looks like. Easy for C files, difficult (and not portable) for C++ files (see Name mangling in Wikipedia).
Use static initializers (thanks to Alex for this). This is my preferred method. I use a throw-away class, which I add to the header file:
static struct Init {
Init() {
static module::factory<Group> init("Group");
}
} init;
Friday, December 14. 2007
I've just found a nice, small C compiler: tinycc. The compiler includes the actual compiler and the linker, so you don't need other external tools. The executable is only 122KB in size on my system (Fedora Core 6). I like tcc because it allows you to create C-scripts.
Continue reading "TinyCC -- a fast C compiler"
Thursday, December 13. 2007
I always have to look it up how to restrict access to some files or directories on my web server, so I write it down here. Two steps:
- You need a password file
- You must specify the restrictions
Continue reading "Restricting access to directories and files in Apache's httpd"
Wednesday, December 12. 2007
That's really cool: Johnny Lee uses the Wii remote to create a low-cost multi-touch screen, either on a whiteboard or your laptop or any other surface you like. You can even download his software at his homepage. That's great, check it out!
Sunday, November 25. 2007
When you connect to a host that you have not connected to before via ssh, ssh prints a message like
lava:~$ ssh lava
The authenticity of host 'lava (134.2.14.48)' can't be established.
RSA key fingerprint is 9e:1a:5e:27:16:4d:2a:13:90:2c:64:41:bd:25:fd:35.
Are you sure you want to continue connecting (yes/no)?
Usually, you say yes and enter your password. With this, you accept the encryption key the server sent you as the actual encryption key of the server (as opposed to an encryption key some eavesdropper might have sent you who sits between you and the server you connect to). You are supposed to accept the encryption key only if you compared the received encryption key with the actual encryption key of the server by comparing their fingerprints. However, how do you get the fingerprint of the actual encryption key?
Continue reading "How to get ssh server fingerprint information"
Tuesday, August 14. 2007
I found the Howto on the gcc inline
assembler
difficult to understand, so I wrote up the major parts here and
created some kind of summary.
Continue reading "Gcc inline assembler howto summary"
Friday, June 29. 2007
On my machine running Fedora 7, I saw message like
/etc/selinux/targeted/contexts/files/file_contexts:
Multiple same specifications for /usr/local/lost\+found/.*.
for some files or directories, especially when doing an yum update or running rpm. I checked the file_contexts file, but I could not find any duplicates.
The solutions was some stale file_contexts.pre file in the same directory, which was a copy of file_contexts with some modifications. After deleting the file_contexts.pre file, the messages disappeared.
I'm still wondering, where this file_contexts.pre file came from, as it did not belong to any package.
Monday, June 18. 2007
Writing meaningful error message is sometimes hard. Even harder is understanding error message of someone else's program. Today I was buffeled with an error message from cfengine:
cfengine:lava: image exists but destination type
is silly (file/dir/link doesn't match)
cfengine:lava: source=/afs/wsi/wsi/environment/fedora/6/cfengine/
config/ti-background.png,dest=/usr/share/pixmaps
How can a destination type be silly? And what file/dir/link does not match?
Looking into the sources (see second match) revealed that the destination type refers to the type of dest, that is /usr/share/pixmaps, which is a directory. This type does not match the type of the source /afs/wsi/.../ti-background.png, which is a regular file.
So the solution to the problem is explicitly naming the target file in the cfengine configuration files:
dest=/usr/share/pixmaps/ti-background.png
I wish the error message from cfengine would be a bit more verbose on this. But now I know what the error message means, and so do you.
Friday, June 8. 2007
Today a small hint that can save you a lot of debugging time when writing shell scripts. If you start your (bash) shell script with
set -u -e
unset parameters won't expand to nothing (-u) and the script ends immediately when one command fails (-e) unless it is part of a test (if, while, ||, etc., see bash(1)).
If you want to debug your shell script, you either insert echo commands throught your script, or you can just insert
set -v -x
at the top. This will turn on verbose mode (-v) in which bash will print the input lines as they are read. The execution trace (-x) mode will print the commands after expansion but before execution, so you can check if the command is invoked the way you intended.
I thought about posting similar hints for tcsh, but who is shell scripting in tcsh anyways?
Thursday, May 17. 2007
Yesterday, Dario Lesca asked for a recursive ldd on the fedora mailing list. I see two possibilities:
- Extend the ldd script to accept an '-r' option and search for dynamic libraries recursively.
- Write a script that reads in the output from ldd and recalls ldd to resolve the dependencies.
I opted for the second approach (ever tried to shell script platform-independently?). You can find the resulting ldd-rec.pl script here.
|