Ubuntu and Compose Key on macbook
Ok, it seems there’s a bug in ubuntu 9.10 (and maybe earlier) with the apple macbook keyboard. The goal should be to map the right command (apple) key as ALT-GR.
A simple workaround is getting to System->Preferences->Keyboard. Select the Layout tab and layout options. Then select the key to choose 3rd level and enter on keypad. Now you can use the enter key (just beside the right apple key) as ALT-GR.
Install Ubuntu (9.10) via Floppy
Introduction
If you are in hurry you can skip this section. ![]()
I had an old laptop with no capabilities of booting via USB and with a broken cd-rom, but a working floppy. So the main goal was to boot the computer from a floppy then tell the computer to boot via the ubuntu live installed on an USB key.
What you need.
- A computer that can boot from cd and a USB port.
- A computer with a running floppy drive.
- An empty USB key (>=1Gb).
- An empty Floppy (1.44Mb).
Create the bootable USB
Boot the pc with the desktop live cd-rom. Plug-in the empty usb key and make it bootable. From Applications menu there’s a voice like create USB key. Otherwise you can have a look at the Installation from USB stick on ubuntu official site.
Create the bootable floppy
I’ve tried many way to have a bootable floppy, that can recognize the USB key for booting (dsl, sbm, …) but the only one that had worked was: plop bootmanager. As advised me on the TiLUG Mailing List (Italian).
Download the latest version of plop boot manager (at the time of writing: 5.0.5), expand the obtained zip wherever you like and write the image on the floppy: dd if=plpbt.img of=/dev/fd0.
Booting
Now insert floppy, plug the usb key into the computer with broken cd-rom and boot it via floppy. When asked, select USB from the menu and that’s all folks!
emacs strip blank lines
Here is a quick way to strip (remove) blank lines from a file with emacs.
- position on top of file: M-<
- Call a query-regex-replace: M-C-%
- input the regex ^ C-q C-j that stand for match all lines that consist in only a carriage return.
- RET-RET. The first one confirm the regex and the last one is for “replace with nothing”.
- When asked use ! to replace-all.
Summing all commands:
M-< C-M-% ^ C-q C-j RET RET !
here you are
SSL and Java (ciak 2)
Last time we spoke about accessing a site via HTTPS using the pure Sun way.
Today, we see the same problem, solved with the apache HttpClient libraries. This library require a keystore specified in the code. In order to generate a keystore, you will have to download a certification file as described in the previous post and then create a keystore using the keytool program. I don’t remember well how to create a new keystore with the required certificate via keytool (I did’t write it down), but reading the help of the program it should be something like:
keytool -importcert -alias <my_alias_certificate> -file <path_to_the_cer_file> -keystore myKeystore.ks
where myKeystore.ks is the name of the file containing the keystore. The pros of using this approach is that you can provide a .ks file among with the program, in a location desired and the program will use it, avoiding post-installation procedures to register the certificate on each jvm.
So, assuming to have our keystore into a sub-directory certs the code for using the site is in the pdf as usual.
rounding double in java
Rounding a double in java is very simple. If you have to round it to the nearest integer you could use the Math.round(double) method, but what about if you have to round it with a desired number of decimals?
Quite easy too. Using the BigDecimal.setScale(int,int) method you can choose how to round it. Following a quick example:
BigDecimal bd = new BigDecimal(123.45);
bd = bd.setScale(1,BigDecimal.ROUND_HALF_UP);
System.out.println(bd.doubleValue()); //should output 123.5
MySQL add 3 years to a date
It may happens if you are silly like me, that you just inserted a lot of records and then realized that you have inserted a mistaken date. In my case the date was a 3 years earlier than the required.
In order to fix it rapidly with mysql you can use the date_add function. Following a quick ad self explaining statement
update <table> set <field>=date_add(<field>,interval 3 year) where id>3289;
Debian, eclipse and exit code 127
Just after installing eclipse from lenny repository, it crashed me up with the error JVM terminated. Exit code=127. After a bit of searching and watching at what a console execution told me, I tried execute eclipse from command line with a simple java -jar /usr/lib/eclipse/startup.jar. Well, in this way it starts up successfully without any problem. Then I tried again a startup from gnome menu and everything worked fine.
Now there is still the failing about integrated browser and the fact that eclipse shipped with lenny is the very obsolete 3.2.
execute shell command via java
It happened to me that working via an extranet on a citrix environment in a WSAD workspace, that I needed to remove the attribute to at least 200 files in different directories.
Since do it one by one via WSAD is unthinkable, and I didn’t have time to going to the client, loggin into the net in order to have a shell and I dind’t have a shell by my hands, I did it via java.
The environment is Windows machine and here is the source
package tests.runners;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
public class ShellCommandRunner {
public static void main(String[] args) throws IOException{
OutputStream stdin = null;
BufferedReader br = null;
String line = null;
String command = null;
command = "cmd.exe /C attrib -r /S /D X:\\workspaces\\tuc-workspace\\*.*";
System.out.println(command);
Process p = Runtime.getRuntime().exec(command);
stdin = p.getOutputStream(); //use this to push commands
//processing stdout
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((line=br.readLine())!=null) System.out.println(line);
//processing stderr
br = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while((line=br.readLine())!=null) System.err.println(line);
System.out.println("done!");
}
}
Leave a Comment



