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);
}

}