November 2, 2011

Making Gnus archive sent mail to an IMAP folder

Posted in Emacs, Linux, Gnus at 5:30 pm by theBlackDragon

Earlier searches lead me to believe that storing sent mail on an IMAP folder was not feasible with Gnus.

So I was pleasantly surprised that setting:

; Store sent mail in a server IMAP folder on a per year basis
(setq gnus-message-archive-group
      (format-time-string "nnimap+superbia:INBOX.Sent.%Y"))

just worked(tm)

Where “superbia” is the name of my IMAP server in my Gnus config.

Performance seems OK so far, so we’ll see how it turns out in the long run.

October 24, 2011

Making NetBeans 7.0 work with Subversion 1.7

Posted in Java, Netbeans, RCS, Subversion at 1:55 pm by theBlackDragon

As you might know the newly released Subversion 1.7 uses a different local repository format, no more do you need an .svn folder per directory in your project instead it uses one .svn folder in the root of your project.

The drawback is that new clients don’t support the old format and vice versa. Netbeans 7.0 still ships with an old built-in Subversion client so after upgrading TortoiseSVN and upgrading my repositories to the new format I could no longer use SVN functionality in Netbeans which was a bit annoying.

Theoretically the solution to this is simple: just tell NetBeans to use the TortoiseSVN provided svn binary (or the one that came with your distribution, if using GNU/Linux) in Tools -> Options -> Versioning -> Subversion -> Path to the SVN executable File.

Unfortunately that doesn’t seem to quite work, I’m assuming that due to a bug NetBeans is still trying to use the built in SVN client. The solution to this I found on the NetBeans forums (here) is that you need start NetBeans with the “-J-DsvnClientAdapterFactory=commandline” argument to force it to use the command line client instead of it’s built in one.

I hope this bug gets fixed in the upcoming 7.1 release, in the meantime this workaround seems to be working fine for me.

July 5, 2011

Move line to end of file and comment

Posted in Emacs, Java at 3:40 pm by theBlackDragon

I had to work on a bunch of translation Java property files in an ancient J2EE project that had old translations in between the new ones resulting in a hardly readable mess that confused the hell out of Netbeans’ property file editor plugin, so I decided to just move all those old lines to the bottom of the file and comment them out.
For this I quickly hacked up two elisp functions

(defun move-line-to-end-of-file ()
  "Move the current line to the end of the file."
  (interactive)
  (save-excursion
    (beginning-of-line)
    (kill-whole-line)
    (end-of-buffer)
    (yank-as-comment)))

(defun yank-as-comment ()
  "Yank the last killed selection as a comment, but leave text
  alone that is already a comment according to the current mode."
  (interactive)
  (save-excursion
    (yank)
    (if (not (comment-only-p (mark) (point)))
        (comment-region (mark) (point)))))

There probably is a much more idiomatic way to do this (which I’d love to hear about), but this seems to work just fine for my use. Note however that move-line-to-end-of-file will just append to the last line if the file doesn’t end with a newline (which isn’t an issue in my case).

June 7, 2011

ssmtp and aliasing the TO-address

Posted in Gentoo, Linux, Techie stuff at 9:40 pm by theBlackDragon

I ran into a rather annoying problem today, Gentoo had pulled in ssmtp and it had started to send out mails, but since root@localhost didn’t really go anywhere everything got sent to my host’s support address, which they weren’t very happy about (sorry).

My setup up to then had been using nailx (portage: mail-client/nail) as a mailx replacement since it supports sending mails straight to an SMTP server but since I already had ssmtp now (which I didn’t know about when I set this up) I figured I’d try setting that up correctly so I could finally be rid of the dead.letter files in my homedirectories. Setting up ssmtp to send mail to an smtp server proved fairly trivial, however aliasing “root” to something more useful proved a bit harder, or rather, the information on how excatly to go about it proved to be fairly hard to find at least if you don’t know what you’re looking for.

My first intuition was to use ssmtp’s revaliases, unfortunatley that doesn’t quite work as it aliases the from-address, not the to-address. A bit of Googling later I found out about /etc/mail/aliases but that file isn’t supported by ssmtp at all (although it oddly is present on my system).

In the end it turned out I needed to use mailx (portage: mail-client/mailx) instead of nailx to provide the mail program so I then could edit /etc/mail.rc like this:
alias root root<root@myremoteaddress.be>
This of course also works for accounts other than root and it seems to work just fine. I’m sure the nice folks at Benesol will be able to appreciate it.

March 18, 2011

Dynamic class loading in Java, using constructors

Posted in Java at 3:10 pm by theBlackDragon

This is a followup to my previous post on this subject. Recently I needed to load some modules (which all implement the “Plugin” interface in my example) in a project using constructor arguments, this is how to go about it. Most of the previous post stays valid, you still need a ClassLoader that “knows” the jars you want to load.

        URL[] jarFiles = findAllJars();
        if(jarFiles != null)
            classLoader = URLClassLoader.newInstance(jarFiles);

Then you need to load the Class (without instantiating it, of course) and create a Constructor object, then pass the appropriate arguments to the Constructor object and instantiate the class using this object and the actual arguments.

This is how the previous article’s example looks like when using arguments:

    public static void load(String p)
    throws ClassNotFoundException, InstantiationException,
    IllegalAccessException{
        Class cl = classLoader.loadClass(p);
        Constructor c = cl.getConstructor(String.class);
        Plugin plug = (Plugin) c.newInstance("myArgument");
    }

The argument p is the class to be loaded (for example be.lair.plugins.MyPlugin). The argument(s) to the getConstructor call are the types of parameters the constructor expects and the last line actually provide these arguments and instantiates the class.

On a related note, maybe I should look into unloading these classes after they have been loaded, if at all possible. I’ve never had a use case for trying to do this but it might be an interesting exercise.

November 29, 2010

Beyond Black Mesa trailer

Posted in Games, Life, the Universe and Everything at 12:24 am by theBlackDragon

Maybe I’ve been living under a rock, but I totally wasn’t aware of a short film being produced based on Half Life, titled “Beyond Black Mesa”. You can read the full thing here. Looks pretty good if you ask me.

Who said gamers were good for nothing?

September 15, 2010

Spring Framework missing in Netbeans 6.9

Posted in Java, Netbeans at 7:43 pm by theBlackDragon

Or is it?

When I tried to follow the Netbeans Spring tutorial I couldn’t for the life of me find the Spring framework where it was supposed to be, only Hibernate showed up.

Apparently you have to explicitly enable the Java Web and EE Plugin as described here. Finding this took me quite a while, I would honestly have expected this question to come up more often, especially from new Netbeans users or people that don’t usually use the Web technologies plugins (like me).

Clementine: Amarok 1.4 continued

Posted in Amarok, Clementine, Linux at 7:17 pm by theBlackDragon

So I stumbled over this post on the LinuxJournal website today about Clementine a project that is porting Amarok 1.4′s functionality to QT4. I’ve always loved Amarok 1.4′s user interface and now there is even a stable Windows version available, something Amarok 2 has unfortunately been sorely lacking thus far.

Even though Clementine is only at version 0.4, the most important functions are there already, the only things I really noticed that was missing were the playcount and last played fields in the playlist window and the ablity to display the track number in the library view.

March 11, 2008

Dynamic class loading in Java

Posted in Java at 12:03 pm by theBlackDragon

This is a repost of an older article I wrote back in 2006 (yes, I had to use the wayback machine to get it back ;) )

I was looking for a way to dynamically load plugins from (at development time) unknown jars the other day and after some searching (nowadays they call that Googling I guess?) I found the solution in Java’s ClassLoader class, in URLClassLoader to be precise. This task turned out to be amazingly simple.

I just defined an interface called Plugin that all the Plugins should implement so that I can cast whatever I get from the ClassLoader to this interface.

So without further ado, here’s the code (yes, only 6 lines of actual code):

        URL[] jarFiles = findAllJars();
        if(jarFiles != null)
            classLoader = URLClassLoader.newInstance(jarFiles);

This gets me a new ClassLoader with all the plugins in a given directory. findAllJars() is a oneliner grabbing all jars from my projects “plugin” directory using a FilenameFilter to filter the Jars from the cruft ;)

I can then load a plugin like this:

    public static void load(String p)
    throws ClassNotFoundException, InstantiationException,
    IllegalAccessException{
        Class c = classLoader.loadClass(p);
        Plugin plug = (Plugin) c.newInstance();
    }

This uses the ClassLoader to load an instance of the dot-notated classname I pass in (eg. be.lair.remes.plugin.ircplugin.IRCPlugin), I then use this Class to create an instance which I then cast to the correct type.

Notwithstanding the fact that I didn’t find a great deal of example of this on the net it was amazingly simple to get working. Makes me wonder why people always need to pick on Java.

June 3, 2007

GNU Emacs 22.1 released!

Posted in Emacs, Linux, Techie stuff at 11:26 am by theBlackDragon

This morning I check in on #fvwm and the first thing I notice is the following:

03/06|01:03:06 < Hun> theBlackDragon: aaaaaaaaaaah!
03/06|01:03:13 < Hun> e22 has been released!

So I run off to the Emacs homepage, but nothing to be found about a new release. Hmm.
So what can you do? Check usenet of course, and sure enough on gnu.emacs.devel (e-mail addresses removed for obvious reasons):

From: David Kastrup <*@*>
 Subject: Re: Cygwin binaries for Emacs-22.1 released!
 Newsgroups: gmane.emacs.devel
 To: Angelo Graziosi <*@*>
 Cc: emacs-devel@gnu.org
 Date: Sat, 02 Jun 2007 21:18:05 +0200
Angelo Graziosi <*@*> writes:
> Cygwin binaries for 22.1 release here:
 >
 >    http://www.webalice.it/angelo.graziosi/Emacs.html
I was going to mouth off about premature announcements and being
 careless about release numbers, but checking on the ftp server have
 found that the tarball for Emacs 22.1 has been uploaded.
Did I miss the announcement on this list?
--
 David Kastrup

And sure enough, there it was, on the GNU FTP server, all shiny and new: an Emacs 22.1 tarball, the changes from 21.x are a little bit too numerous to sum up here, I’d say just upgrade or read the ChangeLog.

Next page

Follow

Get every new post delivered to your Inbox.