Digital Stronghold - Software Engineering, Musicality and Facts of Life…



October 29, 2009

Locking a file in Java

Locking a file in Java is platform dependent. Write once run anywhere? Thumbs down. Some platforms will not allow a file access without a lock while others will.

This is very useful especially when writing your own database (I know some people will argue but this is still happening in corporations handling very sensitive data). It starts with a simple file access.

try {
    final File file = new File("Tables.dat");
    final FileChannel fileChannel = new RandomAccessFile(file, "rw").getChannel();
	
    // this method will block until a lock is acquired
    final FileLock lock =fileChannel.lock();
	
    // this method will not block, it will return null or throw an exception
    lock = fileChannel.tryLock();
	
    // TODO: do something with the file
	
    // release the lock
    lock.release();
	
    // cleanup / close file
    fileChannel.close();
} catch (Exception e) {
    // TODO: handle exception
}

Caution: You really need to verify how the target platform handles files. This will not apply on a distributed database as well as networked file systems, if that’s the case you need to write at least a protocol for handling concurrency.

October 20, 2009

Earth planner - Architect Felino Palafox Jr. (Manila Bulletin)

Earth planner
Architect Felino Palafox, Jr.
October 17, 2009, 8:49am

THE MMetroplan is to Felino Palafox Jr. as the ark is to Noah.

Through the plan and the ark, respectively, both forewarned their people of destruction to come their way if they didn’t mend their ways.

Unfortunately, both were not heeded - and we all know what happened thereafter.

“It was not an act of God. The devastation caused by Typhoon Ondoy could have been averted if humans only listened,’’ firmly believes world-renowned Filipino architect Palafox.

Palafox, of course, completely knows what he was talking about. More than 30 years ago, in 1977, he came out with the Metro Manila Transport, Land Use and Development Planning project, a World Bank-funded report that aimed to protect Metro Manila from further flooding. In this report, recommendations were made for transportation, land use, zoning, and flood control, particularly in the eastern part of the metropolis, specifically in – you guessed it – Marikina, Cainta and Pasig.

The proposal, Palafox says, was to build developments in the city in the south, or northeast direction rather than west or eastward reclamations.

But instead of adopting the plan, the government at that time copied the wrong models, i.e. Los Angeles which was not even designed for pedestrians but for automobiles. On top of that, there were poor garbage disposal, and deforestation caused by illegal and legal logging to give way to the rise of subdivisions in all the wrong places.

Palafox says he came out not to fix the blame – and no, he is not running for any elective position.

“This crisis is an opportunity to learn lessons or unlearn the mistakes of the past and maybe revive those good proposals and bring them to the 21st century,” stresses Palafox who shared the same report with 32 other countries. Ironically, while most of these countries adopted the plan, the Philippines did not.

(more…)

October 18, 2009

vrms - Virtual Richard M. Stallman

Though I am aware that there are non-free packages lurking in my box, I want to be precise, thanks to Virtual Richard M. Stallman.

          Non-free packages installed on linux-conqueror
	
fglrx-modaliases          Identifiers supported by the ATI graphics driver
linux-generic             Complete Generic Linux kernel
linux-restricted-modules- Non-free Linux 2.6.28 modules helper script
linux-restricted-modules- Restricted Linux modules for generic kernels
nvidia-173-kernel-source  NVIDIA binary kernel module source
nvidia-173-modaliases     Modaliases for the NVIDIA binary X.Org driver
nvidia-180-modaliases     Modaliases for the NVIDIA binary X.Org driver
nvidia-71-modaliases      Modaliases for the NVIDIA binary X.Org driver
nvidia-96-modaliases      Modaliases for the NVIDIA binary X.Org driver
nvidia-glx-173            NVIDIA binary Xorg driver
skype                     Skype - Take a deep breath
tangerine-icon-theme      Tangerine Icon theme
virtualbox-3.0            Sun VirtualBox
	
           Contrib packages installed on linux-conqueror
	
nvidia-common             Find obsolete NVIDIA drivers
nvidia-settings           Tool of configuring the NVIDIA graphics driver
	
  13 non-free packages, 0.9% of 1505 installed packages.
  2 contrib packages, 0.1% of 1505 installed packages.

Well, I need these.
- NVIDIA - Who wants to use the generic vesa driver (+ mesa) for playing games?
- Skype - I have relatives to keep in touch with.
- Virtual Box - I use Windows 7 to run web applications classified as For Microsoft Internet Explorer Only.

October 7, 2009

Linus’ discussion about goto statements

As discussed by Linus Torvalds 6 years ago,

From: Linus Torvalds
Subject: Re: any chance of 2.6.0-test*?
Date: Sun, 12 Jan 2003 12:22:26 -0800 (PST)

On Sun, 12 Jan 2003, Rob Wilkens wrote:
>
> However, I have always been taught, and have always believed that
> “goto”s are inherently evil. They are the creators of spaghetti code

No, you’ve been brainwashed by CS people who thought that Niklaus Wirth
actually knew what he was talking about. He didn’t. He doesn’t have a
frigging clue.

> (you start reading through the code to understand it (months or years
> after its written), and suddenly you jump to somewhere totally
> unrelated, and then jump somewhere else backwards, and it all gets ugly
> quickly). This makes later debugging of code total hell.

Any if-statement is a goto. As are all structured loops.

And sometimes structure is good. When it’s good, you should use it.

And sometimes structure is _bad_, and gets into the way, and using a
“goto” is just much clearer.

(more…)

October 3, 2009

Cypress Semiconductor USB2.0 Storage Device

I’m just happy to have this device plugged in my PC.

UUID:               32efe183-7da8-4aea-8750-299d6584cc4a
VendorId:           0x04b4 (04B4)
ProductId:          0x6830 (6830)
Revision:           0.1 (0001)
Manufacturer:       Cypress Semiconductor
Product:            USB2.0 Storage Device
SerialNumber:       ############
Address:            sysfs:/sys/devices/pci0000:00/0000:00:02.2/usb1/1-8//device:/dev/bus/usb/001/004

Theme designed by Joset Anthony Zamora


Digital Stronghold

↑ Get Headline Animator