Friday, June 22, 2012

eclipse seizure - 1

In some cases when you are trying to install a  eclipse plugin through their update manager, and you are on Linux, you may get something like:


Cannot complete the install because one or more required items could not be found. Software currently installed: Shared profile ....... etc.

It happened to me many times. What do to ?

Login as root, and install the updates you need. Big chance it may work. You may try to change the permissions for the base eclipse installation, but I didn't try this yet.


Monday, June 11, 2012

Mounting database as a file

Postgresql offers the ability to query external data. In some scenarios this can be really useful. This called SQL/MED ("SQL Management of External Data").

One of those cool scenarios is when you need to query a file inside code as if it was a database table. To do so you need to have at least postgresql-9.1.

We will use the simplest file format to demonstrate the idea.

Create a CVS file:

Year,Make,Model,Length
1997,Ford,E350,2.34
2000,Mercury,Cougar,2.38
 
 
Create a postgresql server:
 
CREATE SERVER file_server FOREIGN DATA WRAPPER "file_fdw" ;




Now it's the time to create the table:


CREATE FOREIGN TABLE test (
year int,
make text,
model text,
length float
) SERVER file_server
OPTIONS (format 'csv', filename '/tmp/test.txt', header 'true', delimiter ',', null '');
 
CREATE FOREIGN TABLE

Let's try a select:

testdb=# SELECT * from test ;                                                      
 year |  make   | model  | length 
------+---------+--------+--------
 1997 | Ford    | E350   |   2.34
 2000 | Mercury | Cougar |   2.38
(2 rows)
 



Change a value in the file, and re-run the select. You should see the changes reflected in query results.

Additional Forgein Data Wrapper exists and they are cool. Using them, you can query 'twitter', MySql tables,
LDAP servers.
 
Additional documentation:
Foreign data wrappers


 
For those who likes this idea but don't use postgresql, here's a perl utility that may help:
DBIx::FileSystem

Related documents:
http://archive09.linux.com/feature/127055 
https://github.com/bianster/mysqlfs
http://www.nongnu.org/libsqlfs/
http://www.perlmonks.org/?node_id=397814




Sunday, April 29, 2012

JSTL, jsp-api with IVY

Many Application servers include jstl.jar in their classpath. However tomcat doesn't.
When you include it in your dependency manager, it pulls jsp-api.jar which conflicts with the one
shipped with tomcat. Therefore you need to exclude jsp-api.jar. For ivy users,


<dependency org="javax.servlet" name="jstl" rev="1.2" conf="compile->*" >
            <exclude module="jsp-api" />
</dependency>

<dependency org="javax.servlet" name="javax.servlet-api" rev="3.0.1" conf="provided->*" />






Tuesday, January 24, 2012

Back to Ant

Now with apache ivy, there's no need for maven, and I can easily rewrite Ant targets in xml without diving into extending maven. However, I still miss maven's "Convention over Configuration", and I hate reconfiguring every single war file, when using ANT+IVY combo. Gradle looked promising, but hey, when will I stop learning new build systems ? How many build system available and all of them address one single problem. If ant+ivy can do it, then they are good enough for me.

Plus, I was hit with gradle limitation, the third day I started using it and tried to extend it.

runnig task programmatically

To me, nothing is more transparent than ant and easier to customize, except those repetitive configurations.

May be it's the time for a simple antlib that saves me for writing those configuration again and again.

Saturday, June 18, 2011

Connecting to samba share from windows guest on KVM

  1. Install samba server. I will not explain this here as it depends on your linux distribution.
  2. Configure it: cat /etc/samba/smb.conf
    [WorkShare]
    comment = Host Share
    path = /home/mansour/work/
    valid users = mansour
    public = yes
    writable = yes
    printable = no
  3. Now we need add "mansour" to samba users. If you don't this, you wont be able to login to the share!
    smbpasswd -a mansour
  4. start your KVM :
    kvm -m 2G -vga std -smp 2 -net nic,vlan=1 -net user,vlan=1 my-window-xp-pro.im
  5. From window Start --> Run : \\10.0.2.2\WorkShare
    enter the username and password, and you should be able to view the files in your share.

For reference: Use Windows XP on Gentoo Linux with KVM

Sunday, June 12, 2011

Installing Perl Modules with CPAN

I was trying to install the latest version of XSH2. Really a very neat utility, and a must for each XML programmer. The previous revision had a bug, and I didn't know that I can install the latest from CPAN, just like I install any other software with emerge, yum, RPM, or ruby gem. Ok, so here's the steps:
  1. Login as root.
  2. Initialize the CPAN configuration. This is easily done with:
    perl -MCPAN -we 'shell'
    Accepting all the defaults is ok.
  3. Now run
    install XML::XSH2
    And you are good to go.
I didn't know it's that easy to install perl modules !

Tuesday, April 5, 2011

Copy the selected text in visual mode to search

I many cases I like to search for other occurrence of some text in a file, under vim. Here's are the steps:
  1. Yank with y
  2. Start the search with the forward slash "/"
  3. CTRL-r then type "
And you should see the text in the search area.