A simple little script to echo stdin (or a file) to port 8080 on the host computer. Then simply browse to http://hostname:8080 and the contents will be there. Can be easier than trying to copy a lot of text in PuTTy. I saved it as to_nc.sh. Then you can do something like
cat filename | to_nc.sh
The script is really small, but does rely on netcat (nc) being installed.
if [[ "$1" != "" ]]
then
{ echo -ne "HTTP/1.0 200 OK\r\n\r\n"; cat $1; } | nc -l -p 8080
else
{ echo -ne "HTTP/1.0 200 OK\r\n\r\n";
cat -
} | nc -l -p 8080
fi;
I thought it would be a fun project to create a little Java program to make a nice wallpaper of the Astronomy Picture of the Day. You can get the executable JAR file here. It only works on Windows, and doesn’t need installing, just save the file and run it (assuming you have Java installed).
It’s not endorsed or affiliated with NASA in any way, it’s just for my own fun.
The default ImageIO save behaviour of images leaves something to be desired, so I put together a simple convenience method for saving them, based on the technique from Universal Web Services.
private void saveImageToJPGFile(Image img,
String fname) throws FileNotFoundException, IOException
{
BufferedImage bufImage =
new BufferedImage(img.getWidth(null), img.getHeight(null),BufferedImage.TYPE_INT_RGB);
Graphics2D bufImageGraphics = bufImage.createGraphics();
bufImageGraphics.drawImage(img, 0, 0, null);
Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
ImageWriter writer = (ImageWriter)iter.next();
// instantiate an ImageWriteParam object with default compression options
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(1); // an integer between 0 and 1
// 1 specifies minimum compression and maximum quality
File file = new File(fname);
FileImageOutputStream output = new FileImageOutputStream(file);
writer.setOutput(output);
IIOImage image = new IIOImage(bufImage, null, null);
writer.write(null, image, iwp);
writer.dispose();
output.close();
}
Via this post on lifehacker I found the brilliant memory aid Memoriser. It doesn’t come with any questions by default, so I made a list of capital cities in the correct format:
The data is originally from About.com
This is the obligatory “First Post”. I’m still finding my feet with WordPress, and I hope I will think of some interesting content…


