log4j to console programatically

I thought I logged this, but when I searched I couldn’t find it. I guess I have lots more things I forget to log here. And it shows they’re useful, because I do come back here to search for it.

I often write small driver snippets to test my code in small units, and I need an easy way to configure logging so that I can see the output on my console without running to a file. And here’s the solution:


Logger root = Logger.getRootLogger();
root.addAppender(new ConsoleAppender(
    new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)));

Source: http://robertmaldon.blogspot.com/2007/09/programmatically-configuring-log4j-and.html

CruiseControl “Deployments by this build”

I was asked what I did to show the jar files listed in “Deployments by this build” in CC’s build report. I didn’t even publish any artifacts. A quick search shows that CC uses distributables.xsl to filter stuff from the ant log file.

Continuous integration is the next tool you ought to have after source control. It’s funny I had to learn them myself (no school I knew teaches it)…

Source: http://markmail.org/message/4qmotsivebcula4a

Personal Encryption

I finally took the time to search for some personal encryption while waiting for a long svn merge and commit. I wanted a small tool, preferably a single executable, works on multiple platforms, to encrypt files with keys. GPG initially felt a little too obscure to me, until I found this guide.

In short:

  • gpg --gen-key and answer the prompts to generate a key pair. Make sure your remember your passphrase.
  • gpg -k to list the keys.
  • gpg -r [keyname] -e [clearfile] to encrypt the file using the particular key. By default the output is the same clearfile name with .gpg extension. Use -o option to change it.
  • gpg -o [clearfile] -d [encryptedfile] to decrypt the file. -o option is needed here because this command outputs to console by default.
  • gpg -a -r [keyname] -o [keyfile] --export-secret-keys to export the secret key. I need the same key on another computer to decrypt the contents. The -a option is synonymous with –armor, which generates a text representation instead of binary.
  • gpg --import [keyfile] to import the key on to another computer.

A bonus feature was it actually compresses as it encrypts. I was thinking of manually scripting it to do so.

Security settings in cmd

Windows Explorer wasn’t responding well to a shared folder, so I was using cmd to quickly access what I wanted. Turns out I needed to change security settings on a folder to enable another domain user to access it. Then I realized I didn’t know how (in cmd). The network was local so I had no Internet access to help me.

Now that I have, I easily found the answer to be “cacls”. Looking at the syntax help I should be able to reproduce what I do with the GUI on the command line.

Section page orientation in OpenOffice Writer

Used to Microsoft Word’s style of creating a single document with different page orientations (portrait/landscape), I was having much trouble doing the same in OpenOffice Writer.

In Word, you could insert a new section, and go to Page Setup to switch the section page orientation to landscape.

In Writer, a section has a different meaning, although it could be used for columns as well.

To do the same in Writer, you have to:

  1. ‘Styles and Formatting’ box, click ‘Page Styles’.
  2. Right click on ‘Default’, select ‘New’.
  3. Name it ‘Default Landscape’.
  4. change the ‘Next Style’ to ‘Default Landscape’.
  5. Click on the ‘Page’ tab and set the orientation to Landscape.
  6. Click ‘OK’.
  7. Create another style called ‘Default Portrait’, this time setting the orientation to Portrait.

Now you can switch orientation by inserting a page break and selecting a different page style.

Reference: http://www.linuxforums.org/applications/word_to_writer.html

miobox

Had a first experience with a 2Wire mio box last Saturday, when I was helping my niece set up her broadband connection. The box is essentially an ADSL router-modem with VoIP features built in.

Similar to a typical ADSL setup, you hook up the power, microfilter, phone line and ethernet cable, and your PC should pick up a DHCP address. Launch the gateway IP into the browser and you’ll get into the setup screen. From there you can get to a familiar page with PPPoE configuration.

One good thing about its default setup is the wireless enabled by default, with WEP. The default WEP key is printed on the box itself.

OSGi

http://www.javaworld.com/javaworld/jw-03-2008/jw-03-osgi1.html

Wonderful tutorial about OSGi. Solves a few mysteries (to me) about Eclipse plug-ins.

In summary,

  • OSGi is a Java-based architecture for developing/deploying modular components. Such components should be able to be deployed without restarting the container.
  • These components are known as “bundles”.
  • Eclipse plug-ins are based on OSGi bundles, so every plug-in is a bundle. Eclipse uses Equinox, which is the reference implementation of the OSGi Service Platform version 4.
  • A bundle needs to have an “Activator”, which implements start/stop methods to handle the bundle life cycle. A bundle also needs to have a manifest, which describes the bundle and points to the Activator.
  • OSGi also helps to manage dependencies through package visibility. Bundles specify which packages to export, so implementation packages can be hidden from bundle clients.

Defraggler

From the same people who brought CCleaner, here’s Defraggler. I’ve not tried it personally yet, but I need to get it down here before I lose it again. (I often lose links, so its one of the purposes of this site.)

It’s free, compact, and it allows single file defrag. Sometimes its just that one big file that you load often, and you want it fast. So this is a program I’ve dreamed of.

ZSNES

Once again, Ubuntu amazed me with zsnes (Super Nintendo Emulator) in its package repository.

There was no sound initially, until I tried “zsnes -ad sdl“. Then I got sound. But terrible and crackling. Next I tried installing alsa-oss. Didn’t work, until I invoke it with “aoss zsnes”. Good sound! And it works subsequently from the “Start Menu”. Yey!

Now the problem is my gamepad is semi-working… It works fully in Windoze, but here it only recognizes the buttons but not the directional pad. Why? I followed some tips to install joystick and jscalibrator, but it didn’t work. Until I tried this site, to chmod 666 the device, and it worked! So now I’m not sure if its just the chmod, coz I uninstalled joystick and jscalibrator and it still works. (I did not uninstall the prerequisites of joystick and jscalibrator though). So if you have the same problem you may want to try the chmod first, to find out if joystick/jscalibrator was needed.

One more thing to note: Windoze stores game states in the same folder as the ROM, while in Ubuntu, the game states are in ~/.zsnes . Took me quite a while there.