Tuesday, May 03, 2016

putty: Access Denied

IP/host name, username and password are correct but you get Access Denied when tyring to log in.
Try disabling this setting:

Putty has GSSAPI enabled by default.
Putty GSSAPI Configuration
Turn it off if you are not using Kerberos (and chances are, you are not in your environment).
Explanation:
I dealt with a few weeks back with when a new administrator could not login to any ssh host with putty - even the one that I know should be working for him. It seems that with GSSAPI Auth enabled, Putty will attempt to login with non-existent kerberos credentials, which resulted in an immediate Access Denied message.
[...]

Source: http://serverfault.com/questions/317781/putty-access-denied

Monday, February 15, 2016

Removing $Windows.~BT & $Windows.~WS Folders

$Windows.~BT & $Windows.~WS folders are created after an update to Windows 10 and are temporary directories taking a lot of space. They can safely be deleted.
  1. Run a DOS (cmd) console as administrator.
  2. Execute:
    1. takeown /F C:\$Windows.~BT\* /R /A
    2. icacls C:\$Windows.~BT\*.* /T /grant administrators:F 
    3. rmdir /S /Q C:\$Windows.~BT\
Remove anything left manually from the file explorer.
Thanks to TheWindowsClub.

Monday, November 23, 2015

Mercurial Tips

  1. Trashcan - [from the docs] The shelve tool is very conservative with your source and patch files. Before it modifies any file it makes a backup under .hg/Trashcan. This trashcan can be emptied by running the purge dialog from the Workbench Repository –> Purge menu option.

Monday, October 19, 2015

You don't currently have permission to access this folder

So you mount an external disk, try to go to the directory where you need to go and Windows tells you that you don't have the permission to do that.
I never understood the philosophy of Windows security, probably because I'm used to Linux. I don't want to understand it anyway unless it gets in my way.
What I tried successfully is:
  1. Open the folder's Properties.
  2. Go to Security and click Advanced.
  3. Change Owner: Enter the object name to select and do Check Names.
  4. Check Replace owner on subcontainer and objects.
  5. Ignore the Windows security warning.
  6. You're done!

Monday, October 05, 2015

Restoring Audio Service in Windows 10

Today I couldn't listen to anything or change the volume or do anything related to audio.
Someone suggested to:

> net stop audiosrv
> net stop AudioEndpointBuilder
> net start audiosrv
> net start AudioEndpointBuilder


After 5 minutes I'm still trying to see if the first command will ever end.


I'll never find out. I finally had to reboot. I tried the put-it-to-sleep solution but it went into eternal sleep.
That's always been Windows' solution: "reboot without  saving your changes"!

Tuesday, June 02, 2015

DokuWiki Hrun Alerts About Update even When Done

"Hotfix release available" alerts keep being displayed even after you do the update.
Apparently there is a bug.
In some places they explain you can manually remove the file: data/cache/messages.txt.
For me this doesn't work since the file is recreated right away.
What I did was to empty the file and leave it there and that worked.
... for a while. Now it's there again.

More info here if you want to try something.

Thursday, May 07, 2015

Take Ownership and Assign Permissions to Yourself on Windows

Sometimes on mounted external drives, you are not the owner (don't ask me why, I'll never understand what's the reasoning behind Windows in general) and cannot change/view files.
Try this:

# Recursively take ownership of directory:
> takeown /f "c:\path"

# Reset permissions recursively
> icacls "c:\path" /reset /T

Monday, March 30, 2015

Dell Laptop: Plugged In, Not Charging

I recently noticed this unwanted message on my Dell Latitude E6540 with Windows 7.
Don't know exactly what prompted it but the battery would not charge above 64%, no matter how I changed the settings of the power saving mode.
Here's how I solved it:
  1. Power off
  2. Remove the battery
  3. Restart Windows
  4. Go to Control Panel -> Hardware and Sound -> Device Manager
  5. Under Batteries, remove all Microsoft AC Adapter and Microsoft ACPI-Compliant Control Method Battery
  6. Power off
  7. Put the battery back in place
  8. Restart Windows
Then magically the battery restarted charging and didn't stop until it reached 100%.
Thanks to nickscomputerfix!

On the contrary, a good reason not to keep it charged at 100%:

The third tip relates to when and by how much batteries should be charged. One of the more widely known aspects about battery life is the “memory effect”.
In older rechargeable battery chemistries, such as nickel cadmium, partial charging and discharging significantly decreases the energy capacity.
What is less known is that the memory effect in lithium-ion batteries, if it exists, tends to be very small. Instead, they have quite nuanced characteristics. When not in use, batteries degrade most when fully charged. So if left for several days or weeks without use, they should ideally be kept at a relatively low charging state, e.g around 20% charged.
Conversely, when being charged and discharged a lot, it is best to keep the batteries as close to the 50% mark as possible. So if you are only charging and discharging batteries a bit at a time, it is much better to do this between 45-55% than between 90-100%.

Full article.

Thursday, February 05, 2015

Windows Taskbar Does Not Hide

Sometimes even if you configured the taskbar to hide itself, it won't and you tried everything you know.
Welcome to the Windows way of doing things!
There is probably a notification from some process, which you cannot easily spot.
The quick way to solve this: kill and restart the file explorer.

Go to the Task Manager --> Processes, and kill explorer.exe.
Then File --> New Task (Run) and type explorer.exe.
Done!

Monday, January 12, 2015

iReport 5.6.0 Failing Silently

Versions up to 5.6.0 (currently the last one) do not run with JDK 1.8. They will silently fail, at least on Windows 7.
If you want to keep JAVA_HOME set to a JDK 1.8 installation, you can run it launching a batch file with something like this inside:

@echo off
set JAVA_HOME=C:\opt\java\jre1.7.0_71
"C:\Program Files (x86)\Jaspersoft\iReport-5.6.0\bin\ireport.exe"

Customize as needed.

Friday, December 12, 2014

Removing commons-logging Dependency from Spring with Ivy

Let's say you want Spring to use SLF4J instead of commons-logging.

First you need to remove the dependency from spring-core:

[TODO]

In the unlikely event you are already not loading transitive dependencies:

<dependency org="org.springframework" name="spring-core" rev="3.2.8.RELEASE" transitive="false"/>

you need to to nothing.

Then add the following dependencies to specify the framework you want to use:

<dependency org="org.slf4j" name="jcl-over-slf4j" rev="1.7.7" transitive="false"/>
<dependency org="org.slf4j" name="slf4j-api" rev="1.7.7" transitive="false"/>
<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.7.7" transitive="false"/>

Ant: Class not found: javac1.8

This error is known to happen with Apache Ant versions less than 1.9.0, which aren't compatible with Java 8.
Upgrade!
Worked for me.

Thanks to Kristian.

Wednesday, December 10, 2014

Find out which applications are using port x on Windows

Find out which applications are using port x on Windows:
> netstat -aon | findstr 0.0:8080

Tuesday, August 19, 2014

Google Drive: Failed to Schedule 1 File for Upload

If your Google drive application for an Android mobile device gives you this message and you have the Developer Options enabled, try to uncheck Do not keep activities before trying anything else.

Thanks to bbell67.

Friday, June 27, 2014

Wireshark: The NPF driver isn't running

The NPF driver isn't running. You may have trouble capturing or listing interfaces.

You run Wireshark occasionally and don't want to start the NPF driver automatically at start up.

Open a command shell with administrator rights and type:

> sc start npf

You can [stop] the service in the same way.

Run a Command as Administrator on Windows

I didn't know this but since I'm a Linux guy, I'm not ashamed.
On windows, if you log in as a user with administrator privileges but want to run a command shell with administrator's rights, you still need to run it in a special way:
  1. Go to the start bar search box
  2. Type cmd
  3. Right-click on cmd.exe and choose "Run as administrator"
Thanks to Olav.

Tuesday, June 10, 2014

Building with Ant from Eclipse: "Specified VM install not found"

After an update of the JDK and successive removal of the old version, when I tried to build with Ant from Eclipse I got:

Specified VM install not found: type Standard VM, name jdk1.7.0_55

Yeah, right, OK, but where do I update the JDK that's used by Ant??
Here:
Run -> External Tools -> External Tools Configurations -> JRE

Thanks to Michael Borgwardt

Monday, June 09, 2014

Windows Keeps Forgetting the Wi-Fi Connection Password

One possible cause of the problem is that the Intel PROSet/Wireless WiFi Connection Utility is somehow conflicting with the OS.
Try to disable it and go back to Windows  managing the connections.

Once you're opened the Intel WiFi connection utility, choose: Advanced, then something like Let Windows Manage the WiFi Connections.

You're done.

Windows: Choose What is Started at Startup

Run:
> msconfig

then switch to the Startup tab.

Wednesday, May 07, 2014

Windows 7 Taskbar Icons Not Displaying Properly After Repair

If some of your icons display like empty boxes after a repair to the system because of some reset, then follow these instructions. They worked for me.
  1. Open the task manager in the processes tab.
  2. Kill explorer.exe.
  3. From the File menu in the task manager, choose New task (run...)
  4. Execute the following:  
    1. cmd /c del %userprofile%\AppData\Local\IconCache.db /a
  5. And restart explorer running: 
    1. explorer.exe
Everything should be fine now!
Tested on Windows 7

Thanks to bhadri.

Sunday, April 27, 2014

Add a Program to the Send To Menu

If you need to use Windows and would like to add some more user-friendliness to the super user-friendly MS GUI, like, adding some other program to the Send To menu, here it is what you need to do:
  1. Open Windows explorer and type: shell:sendto in the text field.
  2. Create a link, ehm shortcut for the program you plan to add in some place (directory, desktop).
  3. Cut and paste it into the Windows explorer directory.
  4. You're done! 
Updated for Windows 10 in May 2016.

Thursday, April 24, 2014

Specified VM install not found: type Standard VM ...

Specified VM install not found: type Standard VM, name jdk1.7.0_45

You installed a new JDK, configured Eclipse to recognize it but the old one still pops up when you compile or do something else.
Try removing the following file: \.metadata\.plugins\org.eclipse.debug.core\.launches\projectname build.xml.launch

Thanks to Mujahed

Monday, March 17, 2014

Mercurial: abort: uncommitted local changes

If you're using TortoiseHg Workbench: go to Repository --> Terminal.
Otherwise simply open a console and cd to the root directory of your repository.
Type: 
 
> hg update --clean -r tip

That should solve the problem.
Thanks to Mike here.

Friday, February 21, 2014

Annoying Eclipse Validation Errors

Sometimes you run into these Unknown validation errors in Eclipse which you seem not to be able to get rid of.
The Maven build is running fine even from within Eclipse but the messages won't go away even if you:
  • Right-click on the project --> Validate
  • Project --> Clean
  • Close and re-open it
What worked for me is: select them all, right-click and delete them.
If there was no real reason for them to show up because in the meantime you had removed the reason for them to exist, then they'll not be generated again.

Thanks to pelotom!

Friday, November 08, 2013

Nexus 7 Not Showing Up on Windows 7 After Upgrade to Android 4.3

First generation Nexus 7 with Android 4.3

It was working before the last firmware upgrade.
After the upgrade the device simply doesn't show up in the file explorer.
If you go to the list of devices, it's there.
If you remove the driver, Windows will simply reinstall it automatically.
If you choose "Upgrade driver" Windows will tell you you have the most recent version.

What worked is:
  1. Go to Settings --> Storage
  2. Open the menu on the top left corner and select USB computer connection
  3. Choose Media device
It will immediately appear :-)
It should...

Thursday, October 24, 2013

Forgot to Change Mercurial's Commit Comment?

If you're using TortoiseHg (my version is 2.9.2) and it's the last thing you did (the commit), then you can simply go to Repository --> Rollback/Undo. What you need is the Undo and to preserve the changed files in the workspace. Follow the instructions then and you're set!

Monday, October 21, 2013

WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.

I got this while running an Eclipse Configuration (Run Configurations) on a GWT project on Windows. If Eclipse cannot do it, you can do it manually...
  • Start regedit 
  • Navigate to the following path
    • HKEY_LOCAL_MACHINE\Software\JavaSoft
  • Right click on the JavaSoft folder and click on New -> Key
  • Name the new Key Prefs
Link to the original post.

Friday, June 07, 2013

Reduce a Video Size with ffmpeg

Basic command to reduce a video for upload to YouTube:

> ffmpeg -i input_video.mp4 -ab 56k -ar 22050 -b 300k -r 15 -s 640x360 output_video.flv

If the original size was greater and you have the time to keep it bigger, YouTube suggests a size of 1280x720 for better reproduction.

More info to come... in the meantime:
Read the man page for more information.

FFmpeg documentation.

Saturday, May 25, 2013

Configure Sun's Java Plugin for Firefox

  1. Install the JRE or JDK as RPM or in your favorite location;
  2. Open a shell and go to: ~/.mozilla
  3. 64-bit platform: create the link: ln -s /opt/java/jdk1.7/jre/lib/amd64/libnpjp2.so . (the dot stands for the current directory)
  4. 32-bit platform: search for the directory: i386.

Reference:
http://www.java.com/en/download/help/index_installing.xml

Monday, April 22, 2013

Set Sun's JDK as Default on Fedora 18

If you installed Sun's JDK (yes, I still call it Sun's!) from the binary package (versus the RPM) and need to use it as the default implementation, you can manually alter the PATH and JAVA_HOME but the easy way is to, at first let Fedora know about it:

# java
> alternatives --install /usr/bin/java java /opt/java/jdk1.7.0_21/jre/bin/java 20000

# javaws
> alternatives --install /usr/bin/javaws javaws /opt/java/jdk1.7.0_21/jre/bin/javaws 20000

# Java Browser (Mozilla) Plugin 64-bit
> alternatives --install /usr/lib64/mozilla/plugins/libjavaplugin.so libjavaplugin.so.x86_64 /opt/java/jdk1.7.0_21/jre/lib/amd64/libnpjp2.so 20000

# Install javac only if you installed JDK (Java Development Kit) package
> alternatives --install /usr/bin/javac javac /opt/java/jdk1.7.0_21/bin/javac 20000
> alternatives --install /usr/bin/jar jar /opt/java/jdk1.7.0_21/bin/jar 20000


and then set it as the default:

> alternatives --config java
> alternatives --config javac

Source.

Monday, April 15, 2013

Add Installed JDK to Eclipse

If you install a JDK yourself (from a BIN, ZIP or other archive) you can easily add it from Window --> Preferences --> Java --> Installed JREs, choosing Add --> Standard VM and specifying the root directory of the newly unpacked installation.
If the JDK is already installed with the Linux standard directory structure, you should instead specify one of the directories you can find in /lib/jvm.

Create an Eclipse Git Maven Java Project

You need to create a new Eclipse (Juno) Java project from a remote Git repository (like GitHub) managed by Maven (i.e. you already have a pom.xml for your project.)
  1. Make sure you installed a Git plugin like EGit.
  2. Click on File --> Import --> Git --> Projects from Git
  3. Then follow the instructions...
  4. Specify a URI for the repository source. This will end with a file.git.
  5. Select a branch.
  6. Local destination (<Git's_local_repository>/<project_name>)
  7. Select Import existing project.
  8. Select create Java project.
  9. Select Use custom location. This should be the local Git repository location.
  10. Mavenize it: right-click on the project's name --> Configure --> Convert to Maven project.

Friday, April 12, 2013

Export Java Syntax Coloring Preferences from Eclipse Juno

I just found out that trying to export just the Java syntax coloring preferences from Eclipse Juno doesn't work.
These are the color preferences you set from Window --> Preferences --> Java --> Editor --> Syntax Coloring.

Theoretically you should do a File --> Export --> General --> Preferences, select Java Code Style Preferences (I don't have a Syntax coloring item) and get them in your favorite file.epf
They should be included in those.

It doesn't work. But you can get them if you select export all.
I don't know if this is a bug or not...

Thursday, February 21, 2013

rpm Features

Show  contents of non-installed package:
> rpm -q -filesbypkg -p package_name.rpm

Extract RPM package files to current directory:
> rpm2cpio package_name.rpm | cpio -idmv

Sunday, February 10, 2013

Create Maven Project in Eclipse from Existing pom.xml

If you want to create an Eclipse project from an existing pom.xml file, you cannot do it from the usual New --> Project ...

For some reason you need to import it:
File --> Import --> Maven --> Existing Maven projects

Maybe I'm wrong but with Ant you could create a new Ant project from an existing build.xml...

Thursday, January 17, 2013

Open a File in a Google Chrome Tab

There is no menu item to do that but...

Linux
Just type file:/// in the address bar.
The last / is the root directory of the filesystem.

In Windows: file://c:

Thursday, January 10, 2013

Performance Degradation of Gnome 3

If I leave my Fedora 17 desktop (4Gb of RAM) running for half a day or more, the responsiveness drops as the load climbs.
At the end it's a total stall with memory usage skyrocketing to 99% and the system blocked.
I thought it was Firefox, then Gnome then I noticed the gnome-shell process was at the top of the resource-consuming processes.
A simple restart of Gnome (Alt-F-r) fixed the problem for good.
I'll check how often I need to do this.

It could be something connected with this particular release of Fedora or a general one with this Gnome (3.4.x).

Update! Another source of load is Chrome. Try to restart it to see if you gain some memory space.

Friday, December 21, 2012

Gnome 3 Extension: System Monitor

I was missing a system monitor icon from the previous release of Gnome and finally had the time to look for a replacement in Gnome 3.
Go to the extension page with your favorite browser.
Install and enable the extension turning the button in the top left corner on.
Don't forget to configure the icon position clicking on the configure button or you'll find the calendar icon squeezed on the right and unreadable.

Tuesday, December 04, 2012

Fedora 17 Microphone not Working

If you can't use your headphones microphone on your newly installed Fedora 17 device, you first need to:
  1. Open your sound settings and check the proper  device is enabled.
  2. If yes, run alsamixer, select the sound card and make sure that the internal microphone and capture are enabled and that both Mic Boost and Capture have high volumes.
  3. Run arecord -D "hw:1,0,0" -f cd -d 4 test-mic.wav. The wav file created should have sound in it.
More details on this thread.

Thursday, November 29, 2012

gnome-tweak-tool to change Gnome 3 Settings

[Updated 2013-06-20]

You can modify the gnome settings using gnome-tweak-tool

E.g. The clock/date settings
If you want to show the date in the clock on the top bar:
  1. Launch the gnome-tweak-tool
  2. Go to the "Shell" menu
  3. Enable "Show date in clock"

Wednesday, November 28, 2012

Fedora 17: em1 Instead of eth0?

Network Interface Controllers (NIC) that are embedded on the motherboard are identified by udev as em1, em2, etc. This is part of an attempt to make interface naming more predictable and meaningful.
That's what you will find instead of eth0, eth1, etc.

To get back the old name go to: /etc/default/.
There you'll find the configuration file for the default Fedora boot loader, GRUB: grub

Add the following command (bold) to the line with the key GRUB_CMDLINE_LINUX:

GRUB_CMDLINE_LINUX="rd.md=0 rd.lvm=0 rd.dm=0 SYSFONT=True  KEYTABLE=us rd.luks=0 LANG=en_US.UTF-8 biosdevname=0 rhgb quiet"

Go to /boot/grub2, make a backup copy of grub.cfg and regenerate the GRUB configuration file:

> grub2-mkconfig -o grub.cfg

Reboot and eth0 will be back!

Hints here and there.

Saturday, October 27, 2012

Get Delete Command in Nautilus File Manager Menu

Hitting delete on a Nautilus file won't work like it used to in the past for "security" reasons.
If you want to, at least, have the delete context menu (right click) item to be able to bypass the send-to-trash behavior in the Nautilus file manager, you need to:
  1. Go to Edit --> Preferences
  2. Behavior Tab
  3. Check the Include a delete command that bypasses trash
That's it!

Friday, October 19, 2012

Upgrading BIOS on an Asus Motherboard

I was trying to upgrade the BIOS on a Asus P8H61-M PRO motherboard on a floppy-less PC.
Luckily this motherboard supports upgrading from the BIOS itself.
The problem was I got this error once the image was selected on a disk partition (strangely enough the BIOS saw only one of the two disks):
Selected file is not an EFI BIOS

It turned out the file should reside on a FAT32 partition while the one it was on was NTFS.
I put the new BIOS on a pen drive and the BIOS saw it, finally ending the story.
Side note: the error message was pretty useless, once again.

Thursday, July 19, 2012

Order of Annotated Controllers When Matching @RenderMapping and @ActionMapping

ConfigurationJDK 7, Spring 3.1.1.RELEASE and Hibernate 4.1.3.Final. Multiple annotated controllers.

When you invoke a Render or Action mapping, it might happen the default mapping is picked up instead of the correct one.
This happens when the controller with the default mapping is first in the list.

DEBUG [http-8080-1] (AbstractMapBasedHandlerMapping.java:74) - Key [view] -> handler [{org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping$RenderMappingPredicate@2e19e=my.package.controller.DefaultController@12a8bad, ...

It's probably a bug or I don't understand the purpose yet.
This can be fixed by forcing Spring to put the controller with the default mapping last. First you scan all others and separately the default one:

    <context:component-scan base-package="it.italiangrid.liferay.doclibadmin.controller" use-default-filters="true">
        <context:exclude-filter type="regex" expression="EmiDocumentController"/>
    </context:component-scan>
    
    <context:component-scan base-package="it.italiangrid.liferay.doclibadmin.controller" use-default-filters="true">
        <context:include-filter type="regex" expression="EmiDocumentController"/>
    </context:component-scan>

Update I found out that if you use @RequestMapping instead of @RenderMapping and @ActionMapping in all methods of the controller with the default action, the problem seems to disappear.
You can use render and action mapping annotations in all other controllers.

References

Thursday, July 12, 2012

Gnome 3: Add a Custom Item to Favorites

Install and run alacarte. This tool allows you to manage the applications you see in the window Activities --> Applications. Those shown there are a subset of the ones available.

  1. Create a new one in Alacarte with New Item in an existing or new menu.
  2. Check the Show checkbox.
  3. Go to Activities --> Applications and right click on the icon to add to the Favorites side bar.

Tuesday, July 10, 2012

Fedora 17: Disable Jetty

From this Fedora 17 announcement:


If you have updated from Fedora 16 and you had jetty installed, it was 
automatically enabled to start on reboot. If you are are not using jetty for 
serving web content, but it was installed as a dependency, please run the 
following command as root user:

# systemctl disable jetty.service

This will stop jetty from running automatically on system reboot. If you also 
want to stop the currently running jetty you can run following:

# systemctl stop jetty.service

Friday, June 29, 2012

BASH's Ctrl-r

Used to search a command in the history.
Usage: type the command and start entering what you're looking for. Once found you can...

Ctrl-r + ENTER = Execute.
Ctrl-r + left/right arrow = put it on the command line to edit.
Ctrl-r + Ctrl-r = Get an older command starting with the same characters typed.

Wednesday, June 13, 2012

Weird Things With Spring, Eclipse and Tomcat?

Everything was working and now an action seemingly still properly configured from a controller is simply ignored?
It's not Spring's or Eclipse's or your sister's fault.
Check you inadvertently didn't start another instance of Tomcat.
That's what happened to me! And I don't have sisters to blame!

Thursday, June 07, 2012

hibernate3:hbm2ddl - Could not determine type for: java.util.List

Trying to generate DB tables from Java classes, I got this error for this one-to-many mapping:

    @ElementCollection(targetClass = DocArea.class)
    @CollectionTable(name = "area_doc",
        joinColumns = @JoinColumn(name = "id_doc"))
    @Column(name = "id_area")
    public List getAreas() {
        return areas;
    }

where Area is an enumeration.
It was a version incompatibility between the hibernate3 plugin and Hibernate itself. I found out you can override a plugin's dependencies in the configuration of the plugin itself thanks to Ivar's post.

Thursday, May 17, 2012

Firefox 12 Way Too Slow on Fedora 16

I found these useful tips on how to customize Firefox and get it faster.
Now, when I have time I need to test if they're working because in the meantime I switched to Chrome despite my lifelong appreciation for the Fox. This is to tell you how unusable it has become.

Monday, May 14, 2012

No Cascade Delete on a Collection Relationship

I had the following relationship in a UserAnswer, the answer(s) a user can give to a question in a survey:

     public SortedSet getSelectedAnswers()

I wanted to propagate all persistence operations to the collection except DELETE. I didn't want an Answer to be deleted when all UserAnswers were removed.
This is how it worked for me: 

    @ManyToMany(targetEntity=Answer.class, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
    @Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
    @JoinTable(name="userAnswer_answers",
            joinColumns=@JoinColumn(name="userAnswer_fk"),
            inverseJoinColumns=@JoinColumn(name="answer_fk"))
    @Sort(type = SortType.COMPARATOR, comparator = AnswerPositionComparator.class)
    public SortedSet getSelectedAnswers() {
       
        return selectedAnswers;
    }


If you don't use CascadeType.ALL, Hibernate doesn't cascade the save of an entity's Collection properties when using the PERSIST annotation. You have to explicitly use the org.hibernate.annotations.CascadeType.SAVE_UPDATE annotation.

Source here.

Friday, May 11, 2012

Eclipse Code Templates

If you'd like to have your own text additions to a new file upon its creation, you can customize the way it is created with code templates.
Go to Window --> Properties --> Java --> Code Styles --> Code Templates.

You can customize comments and code components in this way at Eclipse level or project level.

Monday, January 30, 2012

hbm2ddl SchemaExport: You have an error in your SQL syntax near type=InnoDB

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=InnoDB'

I used to create my MySQL DBs with ant and everything was working. Now, moving to maven and hbm2ddl I get this error.
After some searching it comes out that it's a problem of incompatibility between the MySQL Java connector (5.1) and the MySQL version (5.5) where type InnoDB was dropped and replaced with engine.

The solution is to change the MySQL dialect from org.hibernate.dialect.MySQLInnoDBDialect to org.hibernate.dialect.MySQL5InnoDBDialect.

Places where this generally occurs are hibernate.cfg.xml and hibernate.properties.

Tested on MySQL 5.5.22

Wednesday, November 09, 2011

Maven + Subversion Enabled Eclipse Java Project

Updated - Apr 2013
What I want for my Eclipse projects is to be Java projects, allow content revisions with Subversion and be managed by Maven.

This is what I need to do.

Eclipse version: Eclipse Juno
Subversion plugin: Subversive
Maven plugin: m2eclipse (m2e)

Support for Subversion and Maven is now integrated into Eclipse.
  1. Choose Help --> Install new software --> Work with: Juno - http://download.eclipse.org/releases/juno.
  2. Expand collaboration and check the m2eclipse and Subversive packages. Install all required components.
  3.  Add the Polarion update site: http://community.polarion.com/projects/subversive/download/eclipse/2.0/juno-site/ (see step 1 for details) and install the Subversive SVN Connectors and a connector of your choice (I use SVNKit 1.7.4)
  1. Create a new project (Checkout Maven projects from SCM). Choose svn as SCM URL and type the URL. If svn does not appear in the list, check the global configuration under Window --> Preferences --> Team --> SVN --> SVN Connector. The connector you just installed must appear on that list.
  2. Once the project has been created, you might have a Java-Maven project only. If that's the case, to connect it to the SVN repository, right click on the project's name, choose Team --> Share --> SVN and follow the instructions to conncet your project to the SVN source.
Now you have a Java project checked out from a Subversion repository which uses a Maven repository to manage its library dependencies.
You can further configure Maven under Window --> Preferences --> Maven. In particular you can add an external Maven installation and change the location of the repository which defaults to the user's personal repository and not the global one.

Monday, October 24, 2011

Liferay: Error Registering Portlets

I got a problem when trying to undeploy a portlet on Liferay the standard way: removing the unzipped WAR in Tomcat's webapps/ dir and the cached information.

08:48:56,725 ERROR [HotDeployUtil:112] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering portlets for MyPortlet

It seemd like the portlet was somehow still in the page for Liferay and the message saying the portlet needed to be removed from the page did not show any buttons to do that. After a while I didn't have the message anymore but only an error page.

Some googling brought me on a page in the Liferay forum where they suggested to remove the portlet-api-2.0.jar from the lib/ directory of the WAR and redeploy it:

> zip -d MyPortlet.war /WEB-INF/lib/portlet-api-2.0.jar

It actually worked. Don't ask me why.

Monday, August 08, 2011

Batch Resize on Linux

Install imagemagick.
Now you can use mogrify.
Example: to resize to half the original size all the JPGs in a directory (keeping the aspect ratio of course):

> mogrify -resize 50% *.jpg

More here.

Eclipse Startup - Crash on Fedora 15

For some obscure reason, the Fedora 15-packaged Eclipse doesn't include JSP syntax highlighting and I could find no easy way to add it (conflicting dependencies prevent that). So I resorted to the original TAR-GZ distribution. The problem there is with the OpenJDK. My Eclipse simply crashes on startup.
What you need to do is tell Eclipse to use Sun's JDK.
Open the eclipse.ini and add the path to the Java executable:

-vm
/opt/java/jdk1.6.0/bin/java

right before the -vmargs option.
More here.

[UPDATE] - Oh, the reason for the crash is not openJDK. It's a bug in Fedora. To circumvent it do the following:
  1. In Gnome3 the webkit library name changed to libwebkitgtk so you need to create one missing symbolic link: ln -s /usr/lib/libwebkitgtk-1.0.so.0 /usr/lib/libwebkit-1.0.so.2
  2. Add -Dorg.eclipse.swt.browser.UseWebKitGTK=true to the -vmargs options in eclipse.ini
More here.

Friday, July 01, 2011

Extracting Audio from Video or Stream

From AVI or other video formats:
> ffmpeg -i file_name.avi -ab 128 -ar 44100 file_name.mp3

From an online stream:
> ffmpeg -i URL_address -ab 128 -ar 44100 file_name.mp3

> man ffmpeg

Wednesday, June 15, 2011

Fedora 15: Old and New Alt-Tab Behavior

As of Fedora 14 (Gnome 2.32) the behavior of Alt-Tab was to cycle through all the windows of all the open applications in a virtual workspace.
Gnome 3 shipping with Fedora 15 behaves differently and probably more efficiently (time will tell.)

Alt-Tab now cycles through all open applications in all virtual workspaces. All the windows of an application are shown when that application is the selected one. You can move the mouse over one window and select it but you can't just use the keyboard to do that.

If you want to cycle through all the windows of the active (selected) application you need to use Alt-~ (or the button above Tab.)

Fedora 15: Add Back Shutdown Option

Gnome 3 by default won't show the shutdown button. To see it click on your name on the top bar and press Alt. The Suspend option will turn into Power off.
If you don't want to perform this extra step (updated after kind comment):
  1. Install: yum install gnome-shell-extensions-alternative-status-menu.
  2. Type Alt-F2 then gnome-tweak-tool
  3. Go to Shell Extensions --> Alternative Status Menu Extension and switch it to on
  4. Type Alt-F2 then r and enter (reloads the Gnome shell.)
  5. You're set! You have gained the Hibernate and Power off options now.

Fedora 15: Add Back Window Buttons


UPDATED on May 9, 2020

Gnome 3 default behavior suppresses all window buttons but the Close. If you want them back:

> gsettings set org.gnome.desktop.wm.preferences button-layout ":minimize,maximize,close"

or use: gnome-tweak-tool.

References:
  1. https://askubuntu.com/questions/651347/how-to-bring-back-minimize-and-maximize-buttons-in-gnome-3

Wednesday, December 22, 2010

Eclipse Error: "Import Cannot Be Resolved"

The imported class is there but Eclipse won't see it.
Try: Project --> Clean

Thursday, November 25, 2010

Creating a SVN Repository

Create the repository

> svnadmin create svnrepo

> gedit svnrepo/conf/svnserve.conf

Enable the following lines:

anon-access = none
auth-access = write
password-db = passwd

> gedit svnrepo/conf/passwd

Edit/add user

Create project directory:

> svn -m "Your comment" mkdir file:///data/svnrepo/sample-project
> svn -m "Your comment" mkdir file:///data/svnrepo/sample-project/trunk
> svn -m "Your comment" mkdir file:///data/svnrepo/sample-project/branches
> svn -m "Your comment" mkdir file:///data/svnrepo/sample-project/tags

Import the project:

> svn -m "Your comment" import /path-to-source/sample-project file:///path-to-svnrepo/svnrepo/sample-project/trunk

Prepare work location:

> mkdir sampleProject
> cd sampleProject

Local check out trunk of project (without the folder itself):

> svn co file:///data/svnrepo/sample-project/trunk/ .

Remote check out (using SVN + SSH protocols):

> svn co svn+ssh://user@host/path-to-svnrepo/svnrepo/sample-project/trunk/ .

Create user and group svn:

> useradd svn

Add group svn to your groups.

Change ownership of all files in svnrepo/db to svn:

> chown -r svn:svn *

Add write permissions to all files in svnrepo/db.

Monday, November 22, 2010

Microphone Not Working in Fedora 14

If your microphone is not working on your new installation, just try this. It worked for me:
  1. Go to System --> Preferences --> Sound
  2. Select the input tab
  3. Switch from the existing configured microphone (probably microphone 1) to another one (microphone 2)
  4. Close the application and everything should work ;-)
It looks like this issue has been going on and off since Fedora 10...

Friday, November 19, 2010

Spring Property Editor for an Enumeration with Localized Names

Problem statement:
  • You use a property editor when you bind a nested Enumeration field of a form backing object.
  • You have localized names for the values.
When you write your PropertyEditor you should remember that the getAsText() method needs to take care of the translation:

@Override
public String getAsText() {

if(getValue() == null) {
return null;
}

SurveyStatus status = (SurveyStatus)getValue();
return status.getTranslatedName();
}

while the setAsText() method does not:

@Override
public void setAsText(String surveyStatusStr) {

if (logger.isDebugEnabled()) {
logger.debug("Read string [" + surveyStatusStr + "] for the survey status field");
}

SurveyStatus status = null;

if (surveyStatusStr.compareTo(SurveyStatus.ACTIVE.toString()) == 0) {
status = SurveyStatus.ACTIVE;
}
else if (surveyStatusStr.compareTo(SurveyStatus.INACTIVE.toString()) == 0) {
status = SurveyStatus.INACTIVE;
}

setValue(status);
}

This is because Spring implicitly uses the enumeration name for the value of your tag, not the translated name.
E.g. If you have a select tag, this is what Spring does for you:

<option value="ACTIVE" ... >

It makes sense, of course...

Wednesday, September 15, 2010

Grep Selected Files

You can use find and grep to search for a particular string (string_pattern) in a selection of files:

> find <dir> -name "<file_find_pattern>" -exec grep -H -n '<string_pattern>' {} \;

Thursday, September 09, 2010

Spring Open View In Session Pattern For Portlets

I needed to implement the Open Session In View pattern for a portlet using Spring (3 with annotations) and Hibernate.
This pattern allows lazily loaded objects to have access to the Hibernate Session for the entire processing of the render request despite the original transaction (associated to the portlet request) already being completed.
I.e. If you have One To Many associations, this allows you to load the Many side of the association in the same thread of the request where you loaded the One side.

What I needed to do is:
Add a WebRequestHandlerInterceptorAdapter interceptor wrapping the stantard OpenSessionInViewInterceptor to applicationContext.xml:

<bean name="openSessionInViewInterceptor"
class="org.springframework.web.portlet.handler.WebRequestHandlerInterceptorAdapter">
<constructor-arg>
<bean class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</constructor-arg>
</bean>

then add it to the DefaultAnnotationHandlerMapping in yourPortlet-portlet.xml:

<bean id="annotationMapper"
class="org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="10" />
<property name="interceptors">
<list>
<ref bean="openSessionInViewInterceptor"/>
</list>
</property>
</bean>

Wednesday, May 12, 2010

Fedora: Receiving Files Over a Bluetooth Connection

This post refers to receiving files from a phone to a computer over a Bluetooth connection.
Please refer to the official Fedora documentation for installation and initial configuration:
Then you have to enable the bluetooth file sharing service.
If you can't find the link to the application in Applications --> System Tools, then create the link yourself or launch the following command manually:
> gnome-file-share-properties&

Enable Receive Files over Bluetooth.
Go to your phone and send the file to your computer.

Friday, April 16, 2010

Hibernate ManyToOne Association With Annotations

It took me a while to get rid of a:
ERROR org.hibernate.util.JDBCExceptionReporter -
Unknown column 'applicatio0_.domain_domainID' in 'field list'

on a simple many-to-one association.
I had an Application object with a Domain field where many Applications could have the same Domain (standard many-to-one association).
The annotations on the field were:

@ManyToOne(cascade = CascadeType.ALL)
public Domain getDomain() {
return domain;
}

Class Domain started with:

@Entity
@Table(name="domain")
public class Domain implements Serializable {
// DB name: domainID
private Long id;
private String name;

Hibernate couldn't correctly map the domain ID until I added the JoinColumn annotation:

@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name="domainID")
public Domain getDomain() {
return domain;
}

which in my opinion could be inferred from class Domain:

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "domainID", unique = true,
updatable = false, nullable = false)
public Long getId() {
return this.id;
}

but it wasn't.
Always use JoinColumn.

Thursday, March 11, 2010

Creating a Movie from Images (Linux)

The short story at this time. These instructions refer to the creation of MPEG4 video from JPGs images on Linux.
You need mencoder, part of the mplayer software.

Type:

> mencoder mf://<PATH>/*.jpg -mf w=320:h=240:fps=12:type=jpg
-ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell
-oac copy -o output.avi

Where you should customize at least:
  • <PATH>/*.jpg is the path to the directory where your JPGs are.
  • w=320:h=240 is the image size.
  • output.avi is the resulting file name

Monday, March 08, 2010

Eclipse: Copying Preferences To a New Workspace

When I create a new workspace in Eclipse what I want every time is to have all my preferences from the other workspaces, first of all the color preferences. There is no apparent option in Eclipse to do that. File --> Import --> Preferences won't do that. Maybe it's hidden somewhere else.
I found an easy way to do that: simply copy the settings directory to the new workspace.
Preferences are stored in each workspace in:
/.metadata/.plugins/org.eclipse.core.runtime/.settings

Shut down Eclipse.
Copy part or the entire contents of that directory to the corresponding directory of the new workspace (after you've created it, of course).
Restart and you're done!

Monday, March 01, 2010

Turning a SVN Project into a SVN/Java Project

This will be needed for a Java project created with the type "from SVN source". It will not have a Java nature by default.

Add a Java nature to the project in .project:

<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>

Create the file .classpath with the JDK/JRE libraries (and optionally the default output directory):

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Then you might want to add to the classpath the libraries which could not be detected at creation time.

This method is alternative to the one detailed here.

Eclipse: Hiding Internal JARs

If you need to hide all the internal libraries your project is using, you can do so from the Package Explorer:
  1. Choose the view menu
  2. Check Show referenced libraries node
You can't do that from the Project Explorer (formerly Resource Navigator) since that is a view not reserved to Java projects.

Tuesday, July 28, 2009

Eclipse Losing Reference to JARs

I have this weird problem that every once in a while (especially upon checking in files to SVN/CVS but not limited to that situation) Eclipse will lose reference to class path JARs and start signalling errors everywhere in the code.
What I temporarily did to fix this was to remove a library directory from the [Project] Properties --> Java Build Path --> Source list of a project, save the properties, open them again and add it back in. Problem gone... for a while.

Now I'm trying something I read somewhere: start Eclipse with the -clean command line parameter.

I'll keep you posted...

Feb 2010 Update: with the current version of Eclipse I'm using (Eclipse Java EE IDE for Web Developers, Build id: 20100218-1602) this issue seems to be vanished.

Wednesday, July 15, 2009

Booting Debian in Text Mode

# disabling login GUI (if not gdm replace with yours)
> update-rc.d -f gdm remove

# re-enabling
> update-rc.d -f gdm defaults

Friday, July 03, 2009

No Javadoc When Hovering Cursor Over Text in Eclipse

I had this weird problem that no javadoc preview showed up when hovering the cursor over java code in Eclipse.

Eclipse version: eclipse-java-ganymede-SR2-linux-gtk
OS: Linux (Fedora 11)

I didn't find out why it didn't work but I found out that it was specific to the version of Eclipse I was using.
When I upgraded to Eclipse Galileo (eclipse-java-galileo-linux-gtk), with exactly the same configuration files and preferences, it worked straight away.

I guess it was a bug of the Ganymede SR2 then...

Friday, June 12, 2009

Unable to Start Eclipse On An Empty Workspace

OS: Fedora 11
Eclipse Version: 3.4.2, Build id: M20090211-1700

If I try to initialize a new workspace (empty but with an existing directory), Eclipse will open as an empty non-killable window.

I was able to have a "dirty" initialization copying the .metadata directory of another workspace I had previously and mysteriously created to the new workspace.

I need to experiment a bit more to see if it's possible to, for example, just create the .metadata directory...

Thursday, June 11, 2009

rpmdb: PANIC: fatal region error detected

I had the following error when trying any yum operation on Fedora 11:

> yum update
Loaded plugins: refresh-packagekit
rpmdb: PANIC: fatal region error detected; run recovery
error: db4 error(-30974) from dbenv->open: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db3 - (-30974)
error: cannot open Packages database in /var/lib/rpm
Traceback (most recent call last):
File "/usr/bin/yum", line 29, in
yummain.user_main(sys.argv[1:], exit_code=True)
[...]

The googled ;-) solution that worked for me was:

> cd /var/lib/rpm
> rm -f __db.00*
> db_verify Packages
> rpm --rebuilddb

Thursday, May 28, 2009

Eclipse: Could not launch the product...

Eclipse crashed or in my case took too long to open a file and I had to shut it down in a not clean state (really surprised it didn't crash during my attempt AND I didn't have to kill it! Great job people@eclipse!).
Next thing that happens when I try to re-launch it using the same workspace is an error message:

Could not launch the product because the associated workspace is currently in use by another Eclipse application

You need to:
  1. go to the workspace home directory
  2. enter the .metadata directory
  3. remove file .lock
and you can happily restart from where you left your job.

Thursday, May 14, 2009

JUnit, log4j And Eclipse

If you want Eclipse to pick up your log4j configuration file when you run JUnit tests from within Eclipse you can:
  1. Right-click on a test class.
  2. Select Run as --> Run configurations...
  3. Select the Classpath tab
  4. Select the home directory of you project and Advanced
  5. Then Add folder and add the folder with the configuration file and you're done.
This will configure the test file's JUnit run options.

If you want to configure all test classes with the same optoins... uhmm... stay tuned. I'll be back.

Wednesday, March 25, 2009

Fedora 10: Firefox Starts up in Offline Mode

The problem: upon strting Firefox it goes in offline mode even if the network is enabled and working. It's really unconvenient to un-check Work offline from the File menu every time especially if you start up many windows and tabs.
The quick solution is to stop and disable the Network manager application from the System --> Administration --> Services window.
Unless you need it... in that case I can't help you right now...

Friday, March 06, 2009

gedit Color Schemes

If you upgrade to Fedora 10 right now, the new version of gedit doesn't explicitly allow you to set up a custom color scheme. They say in the future there will be an editor for that.
In the meantime what you can do is:
  1. > cd /usr/share/gtksourceview-2.0/styles/
  2. Copy one of the available schemes to a new one and edit that file to suit your needs.
  3. Once you restart gedit, the new color scheme will be available under Edit -> Preferences -> Font & Colors

Thursday, January 29, 2009

Adding a Script to The Gimp (Linux/UNIX)

  1. Create an *.scm file with the script. To create a script you can follow this tutorial.
  2. It's recommended to keep them (scripts) in your personal settings. Enter your own gimp directory: ~/.gimp-2.6 or similar, the scripts sub-directory and copy the file there.
  3. The place in the menus it will be placed is set in the following command (usually a the end of the script): (script-fu-menu-register "script-fu-photo-scriptName" "/Script-Fu/Photo/"). This will place the script in the Script-Fu --> Photo menu.
  4. Then you need to run Filters --> Script-Fu --> Refresh Scripts command.

Thursday, December 04, 2008

To-Haves When Using Eclipse (Java development)

  • CloudGarden Jigloo: SWT/Swing GUI builder
  • Tigris Subversion: SVN repositories management (Subclipse is one client for Eclipse)

Tuesday, December 02, 2008

Converting MPEG-4 to MP3

Instructions for Fedora Linux.
Install lame:
> yum install lame

Install FAAD.
You need to compile it. Instructions are in the README.linux file in the source package.

Then you can use this command:
> faad -o - "file.m4a" | lame - "file.mp3"

References
  1. Lame, http://lame.sourceforge.net/
  2. FAAD, http://sourceforge.net/projects/faac/

Monday, September 22, 2008

Ant unable to locate javadoc.exe

The situation: you're launching an Ant build file from within Eclipse on Windoz and the file has a Javadoc task. But Eclipse can't find the executable.

What you need to do is add the JDK bin directory to the PATH environment variable.
There is nothing to configure in Eclipse.

Tuesday, September 09, 2008

Configuring the Class Path When Testing in Eclipse

If you're testing from within Eclipse and are using Apache Commons Logging + log4j and you get the message:
log4j:WARN No appenders could be found for logger

you can let log4j know about the location of the log4j configuration file adding the directory where that file can be found this way:

Right click on the test class and choose Properties --> Run/Debug Settings
Select the file.
Click on Edit and select the Classpath tab.
Select the first item in User Entries, then Advanced, then Add Folders and you're done.

Monday, August 25, 2008

Merging PDFs on Windows

First you need Ghostscript.
Then, you can just issue the command:
> gswin32 -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=merged_file.pdf -dBATCH file_1.pdf file_2.pdf file_3.pdf

What I noticed is that the text in the merged file is a little bigger than the original one at the same magnification although nothing is missing.
Maybe you/we need to tweak a bit with the parameters...

Sunday, August 24, 2008

Dual-boot With Grub After Installing Windows XP on a Linux Machine

Your situation: Windoz will boot but Linux is now invisible.
What you want is to have Grub installed on the Master Boot Record (MBR) of the first disk to pilot the boot sequence.
You need a Linux distribution CD/DVD with the rescue mode as an option. Any distribution is fine even if different from the one you have installed.
  1. Boot in rescue mode
  2. Once you have a shell type:
  3. > fdisk -l
  4. > grub
  5. grub> root (hd0, n)
  6. grub> setup (hd0)
  7. grub> quit
Notes
3. With fdisk -l you can check which partition holds the linux root partition (in case you forgot).
5. If your partition is, for example, /dev/sda2, then your value for n is 1 (Grub starts from 0)

Now you can exit the rescue shell and reboot. If you had a Grub configuration file configured to boot Linux and Windoz, you are done. You will be in the same exact position as before Winsoz zeroed Grub on the MBR.

If you didn't have Windoz before, you need to add to the Grub configuration file the Windoz entry:

title Windoz
root (hd0,m)
makeactive
chainloader +1

where m is the Windoz partition (Grub's way of course, see note above).

Sunday, July 27, 2008

Screen Capture With Mac Keyboard and Windows Desktop

The problem starts on the Mac keyboard: you don't have the prnscr key! But still what you have is a Windoz machine. What is working for me (there are external applications but I couldn't find a good free one) is to open the on-screen keyboard under Programs --> Accessories --> Accessibility. There you have it!
If you have the always-on-top option enabled, you loose control of the physical keyboard and sometimes I had to kill the virtual thing anyway to get back the other one. But I can live with that.

Thursday, July 17, 2008

gpk-application Not Working

I recently had this problem with the gpk-application on a Fedora 9. This Gnome application allows you to check what you have installed and install/remove packages.
The thing was I could not see the groups of packages and update the list from a remote machine. It happened I found out the cache was corrupted and this command:

> yum makecache

restored it to its full functionality.
Almost. I still cannot remotely refresh the list (which I could on the local display) but I think this is another story... permissions maybe.

Tuesday, July 15, 2008

Linux Graphical FTP Client

I recently switched to gFTP, the FTP client from Gnome, after I apparently encountered problems connecting to a couple sites with Kasablanca (from KDE). One was that the client could not display the content of a remote directory no matter what I did.
I must say that gFTP is more solid and it did not have those glitches. I personally recommend it at this time.

Wednesday, May 28, 2008

Linux Toolbox: pdftk

(from the man page) If PDF is electronic paper, then pdftk is an electronic staple-remover, hole-punch, binder, secret-decoder-ring, and X-Ray-glasses. Pdftk is a simple tool for doing everyday things with PDF documents. Use it to:
  • Merge PDF Documents
  • Split PDF Pages into a New Document
  • Rotate PDF Documents or Pages
  • Decrypt Input as Necessary (Password Required)
  • Encrypt Output as Desired
  • Fill PDF Forms with X/FDF Data and/or Flatten Forms
  • Generate FDF Data Stencil from PDF Forms
  • Apply a Background Watermark or a Foreground Stamp
  • Report PDF Metrics such as Metadata and Bookmarks
  • Update PDF Metadata
  • Attach Files to PDF Pages or the PDF Document
  • Unpack PDF Attachments
  • Burst a PDF Document into Single Pages
  • Uncompress and Re-Compress Page Streams
  • Repair Corrupted PDF (Where Possible)
Get it on Fedora:
> yum install pdftk

Note Unfortunately pdftk was removed from the Fedora repository due to a license issue that prevented it from being used in nuclear facilities. Yeah, right. Okay. Whatever!
You have to recompile it from the sources or... grab the final product from someone who already did it: Professor Kriehn's Fedora Repository!

Tuesday, May 27, 2008

Exporting the Graphical Display

If you need to open a graphical application on a Linux box A and see it on another one B (i.e. exporting the DISPLAY) there is one easy way if you log in from B to A with SSH:

> ssh -X -Y user@host.domain

Then you can start a graphical application on A from the remote session on B and see the output on B.

Monday, May 12, 2008

Installing Linux on the Sony Vaio PCG FX-220

I bought this notebook in August 2001. I will never buy a Sony again despite the pros for the following reasons:
  • Bad user support. If you have a problem, you have to pay to be able to speak with a Sony representative.
  • A memory slot had a problem which prevented it to be used. This is a common issue ([1]) with this series and Sony did nothing to fix that.
  • The CD/DVD reader broke in 2007 (I have a Fujitsu notebook from 1996 which is still perfectly working).
Anyways, for the last reason and the fact that I needed to reinstall from scratch recently, I needed to go with boot diskettes and a network installation. Debian 4.0 was the easiest choice from a first overview (I had already installed Debian a few years ago on this notebook).

Installation
  1. You need the boot, root and network-drivers-1 diskettes.
  2. Start at the boot with: expert hw-detect/start_pcmcia=false
  3. After that, installation starts. It might hang (it did with me) but it's a network timeout problem. Retry with a different mirror.
  4. At the end of the installation, LILO and Grub won't install. Skip that step.
  5. To reboot, use the boot diskette with the following parameters: rescue root=/dev/hda1 (replace with your settings). Load the drivers, networks-drivers-1 and 2 diskettes this time (might not be necessary but it might save your time).
  6. Log in as root. Install Grub: apt-get install grub.
  7. Configure Grub automatically creating its configuration file.
  8. Reboot.
  9. Start in single user mode because the default X.org configuration file won't work.
  10. Edit the X.org configuration file manually removing all references to screen resolutions above 1024x768 and above 16bpp (TODO to be verified, 24bpp might work)
  11. Reboot.
  12. Check that the network parameters are correctly set.
Components

USB: working out of the box.

Useful Links

Tuesday, May 06, 2008

Logitech Quickcam Pro 4000 on Linux

This post is about using a Logitech Quickcam Pro 4000 on Linux (Fedora 8) to store snapshots and producing a movie.

# Install xawtv (xawtv-3.95-7.fc8)
> yum install xawtv

# Install mencoder (mencoder-1.0-0.90.rc2.lvn8 from the livna repository)
> yum install mencoder

The xawtv package contains tools which allow you to connect to the webcam, grab pictures and videos on the fly and also produce movies from the snaps.

# Check that the webcam is recognized and broadcasting:
> xawtv -c /dev/video0 &

/dev/video0 : the device (use xawtv -hwscan to see which one it is for you)

# You can grab pictures in two ways with xawtv: using webcam or using streamer.

# grab snapshots using streamer
> streamer -c /dev/video0 -j 85 -t 1200 -r 0.03 -o office-0000.jpeg

/dev/video0 : the device
85 : JPEG quality
1200 : number of snapshots to grab
0.03 : frames per second (here it's about 1 snap every 30 seconds)
office-0000.jpeg : output file with counter to accomodate 4 digits here

# grap snapshots using webcam
> webcam webcam.conf

All configuration is read from file. My webcam.conf is:

[grab]
device = /dev/video0
text = Atlanta GA - %Y-%m-%d %H:%M:%S
#infofile = infofile.txt
fg_red = 255
fg_green = 255
fg_blue = 255
width = 320
height = 240
delay = 30
wait = 0
#input = camera
brightness = 100
#norm = pal
rotate = 0
top = 0
left = 5
bottom = -1
right = -1
quality = 85
trigger = 0
once = 0
archive = office-%Y%m%d-%H%M%S.jpg

TODO Explanation to follow...

# make movie using mencoder (you can also use streamer but I didn't try it yet)
> mencoder "mf://${CURR_DATE}/*.jpg" -msglevel all=-1 -mf fps=12:type=jpg -ovc lavc -lavcopts vcodec=mpeg4:trell:mbd=2:dc=10 -oac copy -o "movie_${CURR_DATE}.avi"

... to be continued

Wednesday, April 30, 2008

Fedora Extras @ livna

rpm.livna.org provides many useful packages that can not be distributed in Fedora (previously known as Fedora Core and Extras) for one reason or another, including multimedia applications.

rpm.livna.org is not a standalone repository, but an extension of Fedora, Fedora Core and Extras repositories.

To add livna Fedora 8 packages to your list of repositories:
> rpm -ihv http://rpm.livna.org/livna-release-8.rpm

Tuesday, April 29, 2008

Installing Xine on Fedora 8

This procedure details the installation using the available prepackaged RPMs. The trick is that they're not all in the same place!

Install the main xine libraries (available from the main Fedora repositories):
> yum install xine-lib

Grab the main package and dependencies from RPM Find [1] and RPM pbone.net [2]:
  1. xine (xine-0.99.5-1.fc7.i386.rpm) [1]
  2. xine-lib-moles (xine-lib-moles-1.1.11.1-1.fc8.i386.rpm) [1]
  3. vcdimager (vcdimager-0.7.23-7.fc8.i386.rpm [2]
  4. libdvdcss (libdvdcss-1.2.9-2.fc7.i386.rpm) [1]
  5. libfame (libfame-0.9.1-12.fc7.i386.rpm) [1]
  6. libmad (libmad-0.15.1b-4.fc7.i386.rpm) [1]
Note that on Fedora 8 you need the above version of xine-lib-moles for compatibility with xine-lib.

Install them directly with rpm to avoid the need of disabling yum's signature check:

> rpm -ihv libdvdcss-1.2.9-2.fc7.i386.rpm libfame-0.9.1-12.fc7.i386.rpm libmad-0.15.1b-4.fc7.i386.rpm vcdimager-0.7.23-7.fc8.i386.rpm xine-0.99.5-1.fc7.i386.rpm xine-lib-moles-1.1.11.1-1.fc8.i386.rpm

Another way is to add livna to your list of repositories and do a:
> yum install xine

Didn't try this though...

Thursday, April 17, 2008

Java and Firefox 3 Beta 5 on Linux

This post is about configuring Java with Firefox 3 beta 5 on Linux i386. It might work for similar versions of Java and Firefox though.
The JRE coming with JSE v1.6.0_03 is currently not working. BUT the one coming with JSE v1.5.0_08 does work!
You just need to follow the usual instructions (which can be found here) and create a symbolic link the the Java plugin library:

> cd ${FIREFOX_HOME}/plugins
> ln -s ${JAVA_HOME}jre/plugin/i386/ns7/libjavaplugin_oji.so libjavaplugin_oji.so

Restart Firefox and check at this URL: about:plugins if it's loaded and here if it works.

Note: Actually "works" is perhaps a little bit of an overstatement. I found out an applet which is supposed to update itself with streaming data and is not doing it. So maybe it's a matter of waiting on Firefox's final version...
On the other side Firefox 3 is much much faster and less memory consuming than Firefox 2.

Tuesday, March 18, 2008

Verifying Which Ports Are Listening

The most reliable way is to use a port scanner like nmap.
You can install nmap in a blink of an eye on a Red Hat system (Fedora included) with yum install nmap or rpm -ihv if you have the package or in many other ways lasting a little bit longer than the blink of an eye.

Then issue:

> nmap -sT -O localhost

Reference: Red Hat Linux Manual v9