Archive Page 2



Self executing jar files

I personally always felt bad about the fact that we have to provide a shell script which runs the executable jar file. It would be nice if we could provide a self contained executable in a single file, right?

I just discovered a trick which works on unix, but it can possibly be adapted on Windows.

Ingredients:
- a jar
- a bash script

Let’s start with the jar. Create an HelloWorld.java file:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

I like to indicate the Main Class in the manifest, so we create a MANIFEST.MF:

$ echo Main-Class: HelloWorld > MANIFEST.MF

now, let’s put the jar together:

$ javac HelloWorld.java
$ jar -cvmf MANIFEST.MF hello.jar HelloWorld.class 

You can try it:

$ java -jar hello.jar 

It should print “Hello World!”. No surprise.

Now, let’s create, once and for all, the bash script “stub.sh”

#!/bin/sh
java -jar $0 $*
exit

Now let’s put together our self-executable java program:

$ cat stub.sh hello.jar > hello.sh
$ chmod +x hello.sh

And now we can run it!

$ ./hello.sh 
Hello World!

Cool uh?

I think, you can create a stub.bat on Windows; possibly you should just replace the first line with “@echo off” and the “$0 $*” with “%0 %1 %2 %3 %4 %5…”. It should work. Don’t ask me to test the Windows version. I’m allergic.

Update:
A shorter version of the stub script:

#!/usr/bin/java -jar

For windows, this should translate to stub.bat:

@java -jar %0 %1 %2 %3 %4 %5
exit

For windows, depending on what you use to concatenate files (copy /b should work) make sure there is a newline between the end of the stub.bat and the beginning of the jar file. I didn’t test on Windows, but I’m pretty sure it will work. Let me know, if otherwise.

Yesterday I noticed that when I close the lid of my MacBook Pro the light in front of the case was not indicating that the computer was going to sleep normally. Still the fans were running and when I opened the lid, I saw that it was not resuming from sleep properly, presenting a strange behavior: it asks for a password for a second or so, then the screen goes black again, and I need to turn it on manually pressing the light buttons (fn+F1/F2) then the screen appears again.

I debugged the problem and I discovered the cause.

The cause is that I enabled “Internet Sharing” from the “Sharing” item in the “System Preferences”. Basically I am sharing the WIFI internet to set of devices connected to the Ethernet.
If the WIFI is enabled (and connected) and the Internet Sharing is enabled, my MacBook hangs while doing the sleep process.

After resetting the SMC and trying several times to close all possible apps which may interfere, I finally found that the Internet Sharing is affecting this behavior.
Another workaround I found is to disable the WIFI. In this way the “Internet Sharing” is also disabled and the problem doesn’t happen anymore.

I reported the bug to Apple, and I hope they will have a look and try to solve it. To me, it is obviously a BUG in the Internet Sharing feature, which by the way it’s superb.

New year, new life. Got my camera bag stolen with all the gears in my hometown Turin. Yesterday I was looking back to the old pictures, and I found some good ones made with a 10 year old super compact camera, Pentax Optio S. I found this one and I like it. Unfortunately I lost also this camera too, during the misadventure in Turin.

Another funny video I found around.


I/O Exception handling

I very much prefer this approach:

OutputStream out = new MyOutputStream(...); //may throw IOException
try {
    //use the stream
} finally {
    out.close();
}

than this:

OutputStream out = null;
try {
    out = new MyOutputStream(...); //may throw IOException
    //use the stream
} finally {
    if (out != null) {
        out.close();
    }
}

I just find the first example correct and the second incorrect. I see the second ‘pattern’ everywhere.

Opinions?

Sunset on Salzburg by Luigi R. Viggiano
Sunset on Salzburg, a photo by Luigi R. Viggiano on Flickr.

I got very positive comments about this picture I made yesterday evening in Salzburg. My only picture in flickr explore was another sunset I shot in Dusseldorf, and this one is getting good attention today, so I hope it will be my second flickr explore pic.
Some work colleagues suggested a bit of fill light at the base. I actually used some vignette effect to focus the viewer attention on the center; if the composition was a little bit better I could have cropped the base area a little bit more still keeping the sun and the mountains in the right position.
Still, it looks like everybody likes this shot. So here I share it also on my blog.

Venetian Mask

Venetian Mask by Luigi R. Viggiano
Venetian Mask, a photo by Luigi R. Viggiano on Flickr.

I made many pictures of those masks in Roman shops. In some shops I saw same sign saying "no picture please". Eventually the idea to shot those colorful masks is not too original, and the shop owners get tired of people coming in just for pictures. BTW those masks are for sure the most colorful subjects I found so far. And here’s another one.
The price for the most funny sign in a souvenir shop goes to the one with "for the sake of our health we don’t provide touristic informations!", wow :-)
In my ‘venetian masks’ set, this one above is definitely my favorite.

After installing OS X Lion I tried to burn a DVD in my macbook, and it turns out that this is what I get using Disk Utility:

I tried several DVDs (DVD+R, DVD-R, different brands, and tried to burn at different speed), with no luck. Also it refuses to read movie DVDs. But it can read the Snow Leopard DVD, so I hope that at least it can read common data DVDs.

I tried to reset the SMC and PRAM/NVRAM, no luck again.

Still remains to try some other burning software.

Reading support forums and searching on google has been a waste of time so far.
I don’t know if this is a side effect of Lion installation, or it is just a coincidence, but since now Apple didn’t ship any update. Only I find it quite suspicious that if you just search for “Lion superdrive” you find many people having problems with those two.

I used my DVD very few times, if it is an hardware problem it means that the claimed superior hardware quality of Apple is just another myth.

Big disappointment by Apple, either if it is a software or hardware problem. Super…drive.

Landscape Silhouette

This picture has been shot from the Rhein promenade in Düsseldorf. I remember I was having a bad day at home, so I went out for a photo walk, which extended to be till late evening. I come back with a lot of good shots. The sun was red and visible by bare eyes, and the buildings were completely black, projecting only their own shadow. At the time I didn’t know that this was a perfect subject for a ‘Silhouette‘ photography. I’m still a photo beginner.
This is my first picture on Flickr Explore. I increased the red a little bit, but this picture is almost a “straight out of the camera” one.


Looks like with the plugins I installed recently on my blog, the spam is completely gone away.

I didn’t want to install captcha, since they are quite annoying. But it looks like they are effective against spam. I found “Conditional CAPTCHA” which works in the correct way: the user insert the comment, if the bayesian filter identify the comment as spam, then a very simple captcha is displayed, so the user can prove that is a human being or a spam bot. If the captcha test fails, the comment is deleted definitively.
Additionally I am using “Bad Behavior” which checks the ip address against an online black list, and prevents suspicious ones to even connect to your site.

So, this is my list of WordPress plugins that have proven to be effective against spam:

  1. Akismet
  2. Bad Behavior
  3. Conditional Captcha

So far, so good.

I still moderate comments manually, approving/trashing them one by one, since I don’t receive many comments, it is feasible. But if this plugin team works so well, I might stop moderating the comments and let it run completely automatic.




About

You are currently browsing the NewInstance weblog archives.

Calendar

August 2014
M T W T F S S
« Dec    
 123
45678910
11121314151617
18192021222324
25262728293031

Follow me

twitter flickr LinkedIn feed

Subscribe by email

Enter your email address:

Archives


Categories

Tag Cloud


Listening