Friday, 10 June 2011

Lost line breaks when copying from gedit to Evernote on Ubuntu - solution

I love Evernote. I work with Ubuntu so I have to use web based Evernote. The problem is that when I want to copy paste my txt files as notes in evernote I always lose the line breaks. I was very annoyed about that.

My solution is to use perl script fix-clipb.pl that works this way:
1. Select the text in gedit and copy it to your clipboard with ctrl+c
2. Run the script. You can create a launcher on your Gnome top panel.
3. Paste it in your Evernote note with ctrl+v.

How to configure it:
1. Install xclip first. Go to Ubuntu Software Centre and search for xclip, install it.
2. Create fix-clipb.pl file and save it somewhere:

#!/usr/bin/perl -w

@clipboardInput=`xclip -o -selection clipboard`;
$tmp_file = "/var/tmp/xclip.txt";

open OUT_FILE, ">$tmp_file"  or die("Error: cannot open file for write /var/tmp/xclip.txt\n");

foreach (@clipboardInput) {
    chomp;
    $_ =~ s/\t/    /g;
    print OUT_FILE "$_\n\r";
}
close (OUT_FILE);

system("xclip -selection clipboard -i $tmp_file");
system("rm $tmp_file");

3. Make the script runnable: chmod +x fix-clipb.pl
4. Add custom launcher to the script in your Gnome top panel.

Details what it does:
1. Gets your clipboard content with xclip.
2. Creates a temp file with line endings converted to Windows standard: \n\r (this is what Evernote treates as a line break). Additionally it replaces all tabs with 4 spaces as I noticed Evernote doesn't like tabs...
3. Exports temp file to your clipboard
4. Deletes the temp file.

Tuesday, 10 May 2011

Free online storage on Box.net - mounting to file system in Ubuntu

Box.net offers 5GB (25MB file size limit) of online storage for personal use. I came across it when I started to play with iThoughts - mind mapping application for iPhone.
I wanted to be able to edit my mind maps not only with iThoughts but from my computers at home and at work.
IThougths can integrate with Box.net. You can export your maps in FreeMind format. Box.net can be accessed remotely not only with their web base interface. You can install box.net iphone application to browse the content of your folders. Even more you can mount the your box.net account in your linux file system.
Your system must support WebDav file system. In order to do that go to your 'Synaptic Package Manager' in Ubuntu and install library: davfs2
Then Connect to Server with:

  • Service Type: WebDAV (HTTP) (if you have a business account with box.net you might have to select https)
  • server: www.box.net
  • folder: dav
  • user name and password for box.net
You can create a bookmark to easily access the box.net storage.

Update:
user name : leave blank (It doesn't work if you enter it here)

Google Calendar Sync now supports Outlook 2010

If you want to sync your corporate calendar with google one install Google Calendar Sync


details here:
http://gmailblog.blogspot.com/2010/08/google-calendar-sync-now-supports.html

Syncing iphone with google calendar

The solution is based on: http://www.google.com/support/mobile/bin/answer.py?answer=151674

Basically you have to add calendar with 'Add CalDAV Account' option.
Server is google.co.uk, use your google username and password.


To choose what calendars will be synced go to:
https://www.google.co.uk/calendar/iphoneselect


Iphone 4.2 and Ubuntu 10.10


I have noticed a problem after updating the iPhone to the new 4.2.


The automount doesn't work. You'll receive an error like this:

Unable to mount iPhone_ org.freedesktop.DBus.Error.NoReply DBus error: MESSAGE DID NOT RECEIVE A REPLY (TIMEOUT MESSAGE BY BUS) 


This is how to fix it:
Go to Synaptick Package Manager and upgrade the library: libimobiledevice1

Wednesday, 23 March 2011

One keyboard and mouse on multiple computers across a network

In the office I have 2 computers. 1st is with Windows with 2 monitors. Second is with Ubuntu with it's separate monitor, keyboard and mouse. To free some space on the desk I got rid of the 2nd keyboard and mouse using a free tool called Synergy. You can use one terminal to control multiple machines and move to mouse cursor from one monitor to another.

As for now Windows version has got a nice gui. You just configure the monitors layout and start the server. Linux version has to be configured manually.
On linux all you need is to edit /etc/synergy.conf
and start the synergy client:
synergyc [SERVER HOST NAME]

You might have to update /etc/hosts file if you can't translate your server's host name.
More details about Ubuntu configuration: SynergyHowto for Ubuntu

I haven't tried QuickSynergy.

Customise the build using maven profiles and copy-resources plugin

Problem: Need to use different properties per environment.

CopyResourcesTest.java
package com.irenty;

import java.io.InputStream;
import java.util.Properties;

import org.junit.Test;

public class CopyResourcesTest {

    @Test
    public void testHelloWorld() throws Exception {
        InputStream propsStream = CopyResourcesTest.class.getResourceAsStream("/app.properties");
        Properties properties = new Properties();
        properties.load(propsStream);
        System.out.println("my.value=" + properties.getProperty("my.value"));
    }
}

Project structure:
copy-resources
¦   pom.xml
+---src
¦   +---main
¦   ¦   +---resources
¦   ¦       ¦   app.properties
¦   ¦       ¦
¦   ¦       +---configs
¦   ¦           +---custom
¦   ¦           ¦       app.properties
¦   ¦           ¦
¦   ¦           +---prod
¦   ¦                   app.properties
¦   +---test
¦       +---java
¦           +---com
¦               +---irenty
¦                       CopyResourcesTest.java

Program always reads properties from /app.properties that is in src/main/resources. The dafault content of that file is:
my.value=default

There are 2 other files in the resources folder: src/main/resources/custom/app.properties and src/main/resources/prod/app.properties containing:
my.value=custom
and
my.value=prod

Depending on the environment we want to build for different app.properties should be included in the package. To achieve that we will use maven profiles.

Here is the pom.xml for our project.

There are 2 profiles defined: prod and custom. Building with each of them will package the application with corresponding properties.

Here are the test results:
mvn clean install
...
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.irenty.CopyResourcesTest
my.value=default
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.015 sec
...
mvn clean install -Pcustom
...
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.irenty.CopyResourcesTest
my.value=custom
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec
...
mvn clean install -Pprod
...
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.irenty.CopyResourcesTest
my.value=prod
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec
...

Normally in the output package we only need 1 properties file. To do that we exclude the src/main/resources/configs from the resources, so the target folder looks like this:

└───target
    ├───classes
    │       app.properties
    │
    └───test-classes
        └───com
            └───irenty
                    CopyResourcesTest.class

Wednesday, 16 March 2011

How to post source code on blogspot

I found the 'how to' there:
http://vivianningyang.blogspot.com/2009/05/how-to-post-source-code-in-blogspotcom.html

I updated my blogspot's template to use the google code prettifier:
http://code.google.com/p/google-code-prettify/


HelloWorldTest.java
package com.irenty;
import org.junit.Test;
public class HelloWorldTest {
    @Test
    public void testHelloWorld() throws Exception  {
        System.out.println("Hello World!");
    }
}

Connecting from Ubuntu to Windows machine via Cisco Anyconnect SSL VPN

I tried to connect to my office's Windows workstation from my home Ubuntu. It's  Ubuntu 10.10 - the Maverick 64bit version. After installing the VPN client I couldn't connect.
An SSL VPN connection attempt produces the following error message:
"Connection attempt has failed due to server certificate problem."

In some cases, this error message is not totally accurate since the problem might be because the AnyConnect client fails to find or open some user-provided libraries it needs to manipulate certificates.
Install the missing libraries, or if the libraries are installed, create symbolic links that point to the location of the libraries in one of the places AnyConnects expects to find the them.

To troubleshoot this call:
strace /opt/cisco/vpn/bin/vpn connect url.com 2>/tmp/debug.txt
You will see errors like:

open("/usr/local/firefox/libnss3.so", O_RDONLY) = -1 ENOENT (No such file or directory)

The easiest solution is to use the libs included in the firefox package:

# Downloaded latest firefox from http://www.mozilla.com/en-US/firefox/
sudo tar -xvjf firefox-3.0.5.tar.bz2 -C /usr/local

The firefox folder will be created in /usr/local. Now link the expected files in /usr/local/firefox:
for lib in libnssutil3.so libplc4.so libplds4.so libnspr4.so libsqlite3.so libnssdbm3.so libfreebl3.so ; do sudo ln -s /usr/local/firefox/$lib /opt/cisco/vpn/lib/$lib ; done

This should solve the VPN connection issue.

Now just connect to your Windows machine with: tsclient
Make sure you use proper RDP version. In my case it was version 5.

Tuesday, 15 March 2011

Java application throws IOException: Too many open files - how to investigate issue in Linux

To investigate this kind of issues under Linux you can monitor the maximum number of open files / file descriptors (FD) for your application's process. It's not a solution to increase the limit of FDs in your system. You should eliminate the root cause of the problem in your application. Look for the unclosed files/connections. You might have missed something. In case of connections

Here are steps:
*** know your java process number
ps aux | grep java
1743
*** know the number of opened files by your process:
lsof -p 1743 | wc -l
975
*** know your file descriptor limit (soft and hard)
ulimit -Sn
ulimit -Hn
*** to display maximum number of open file descriptors:
cat /proc/sys/fs/file-max

***** System-wide File Descriptors (FD) Limits
*** increase the maximum number of open files by setting a new value in kernel variable /proc/sys/fs/file-max as follows (login as the root):
sysctl -w fs.file-max=100000
*** if the limit has to be set after reboot, append: fs.file-max = 100000 to:
vi /etc/sysctl.conf
*** log out and in or call:
# sysctl -p
*** verify:
sysctl fs.file-max
or
cat /proc/sys/fs/file-max

***** User Level FD Limits
*** set user level limits:
vi /etc/security/limits.conf
add:
httpd soft nofile 4096
httpd hard nofile 10240