I wanted to build incremental project builder in Eclipse today.
There is nothing on the top level of the "New Project" wizard to indicate how to build it. Quick search on the web didn't yield any usable result so, I guess posting a short post about it may be useful.
One builds incremental project builder by selecting "Plug-in development" and after 2-3 steps one is able to select among:
- Hello World
- Hello World Command
- Plug-in with a multi-page editor
- Plug-in with a popup menu
- Plug-in with a property page
- Plug-in with a view
- Plug-in with an editor
- Plug-in with an incremental project builder
- Plug-in with sample help content.
Selecting incremental project builder adds sample project builder, project nature, problem marker and popup menu action - so all the things I need.
Cool!
Wednesday, April 1, 2009
How to create incremental project builder in Eclipse?
Sunday, December 14, 2008
Toner refill kit recommended
My home laster printer (Samsung ML-1710) really needed a new toner. After a bit of comparison, I figured, I'll give a try to toner refill kits.
I got a Universal refill kit #6. It is a breeze to replace, but look at the instructions first. On Samsung's toner you need to drill the hole on the right, pour some toner in and put a cap on.
Happy printing.
Seagate date code
Last week my Seagate hard drive broke. It had weird date code on it. I figured that on the internet there has to be a place where someone posted how to decrypt this 5 digit number.
After a bit of search I have found PDF explaining it, but I noticed I could not find a on-line calculator. Given that calculation is not hard to do, but still not intuitive for human to calculate I wrote a little calc that solves that problem for myself and anyone who is wandering what the date is (this may be important to figure out if your drive is under warranty).
So, here is Seagate date code calculator.
Enjoy.
Friday, October 17, 2008
jflvlib-0.1 released
JFlvLib is a library that allows writing of Flash Videos (FLV format).
To use library user instantiates Capture instance using CaptureFactory class.
Capture c = CaptureFactory.getCapturer( os , new Dimension(xx , yy) ) ;
Capture interface provides 2 methods:
// generates new frame in compatible format for writing frame
BufferedImage newFrame();
// writes a frame to FLV stream
void writeFrame( BufferedImage image , int timestamp ) throws IOException;
At this stage library implements video only, SCREENVIDEO_CODEC and it generates only key frames. This is good for producting videos but they are larger than they need to be.
That's it.
TODO:
Optimize FLV creation writing not only keyframes but also interframes.
Implement other codecs (JPEG, H263, ...)
Add audio support
Example:
package edu.mit.star.flvexample;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import edu.mit.star.flv.Capture;
import edu.mit.star.flv.CaptureFactory;
public class Main
{
public static void main(String[] args)
{
try
{
OutputStream os = new java.io.FileOutputStream( "z:\\temp\\test.flv" );
int xx = 256 ;
int yy = 512 ;
Capture c = CaptureFactory.getCapturer( os , new Dimension(xx , yy) ) ;
int time = 0 ;
while( time < 5000 )
{
BufferedImage image = c.newFrame() ;
image.getGraphics().drawOval(0, 0, xx*time/5000, yy*time/5000);
image.flush();
c.writeFrame(image, time);
time += 250;
System.out.println( "Generating " + time + " ms frame.");
}
os.close();
}
catch( IOException ex )
{
ex.printStackTrace();
}
}
}
Thursday, March 20, 2008
Getting UNIX process ID in Java
We encountered a need to kill process spawned by Runtime.getRuntime().exec() in java in a bit friendlier way than Process.destroy() provides for. To do this, easiest way is to execute "kill -number PID".
Process ID is not available as part of the interface, and below is outlined hack to get that information:
public class test
{
public static void main( String[] str )
{
try
{
Runtime r = Runtime.getRuntime() ;
Process p = r.exec( "sleep 200" ) ;
java.lang.reflect.Method m = p.getClass().getDeclaredMethod( "ac cess$100" , new Class[] { p.getClass() } ) ;
m.setAccessible(true);
Object ret = m.invoke( p , new Object[] { p } ) ;
System.out.println( "process ID " + ret ) ;
System.out.println( "Press Ctrl-Z and ps to confirm" ) ;
Thread.sleep( 100000 ) ;
}
catch( Exception e )
{
e.printStackTrace() ;
}
System.exit(1);
}
}
Thursday, December 6, 2007
Java, HashSet, Equals and hashCode
Today, I was working on the code that attempts to add 2D points to java.util.HashSet and test if HashSet contains them.
Point implemented equals method correctly, and accoding to java.util.Set documentation contains should: "Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that (o==null ? e==null : o.equals(e))."
Well, documentation is wrong - and for a good reason - to implement specification as documented one would need to iterate all objects (in the set) for check for equality. What java.util.Set does is to use hashCode() value to index objects and compare them.
Therefore, if your class does not implement hashCode correctly, following test will fail:
ArrayList
points.add( new IntPoint2D( 2, 2 ) ) ;
assertTrue(points.contains(new IntPoint2D(2,2)));
A dilemma is what to return as hashCode? I opted, knowing that my data will be local to implement hashCode as:
public int hashCode()
{
return (x & 0xffff) | ((y & 0xffff)<<16) ;
}
That will be good enough solution for the problem I'm facing.
There is corollary of this implementation:
1. if one assumes that hashCode() is natively implemented to return a pointer to underlying objects, and one tests for identity of the objects contained in the set (often the case) than Set works great.
2. if one needs to overload hashCode() and stuff more complex object in it, it needs to be aware of remote or not-so-remote chance that hashCode will return same value for two different objects, thereby yielding incorrect code.
Tuesday, August 7, 2007
Man isn't this useless, but cute...
Browsing for fast USB drives I found a useless feed. And this useless gadget is kind'a fun - check YouTube video.
Link: http://www.getusb.info/category/usb-novelty-gadget/