Friday, February 8, 2008

Linux Tip 4

This is a simple bash script that will shut down your computer.All you have to do is to open a text editor( such as gedit,vi,emacs or whatever your favorite is) write the code than save it as "theName.sh". Inside the file write "init 0" (for shutdown) or "init 6" (for reboot).Then place this in the /usr/bin/ directory. Now you can open a console window and call the "theName"(watch out for case) script.

Tuesday, January 15, 2008

Java screenshot

This is a simple class that takes a screenshot and saves the image as a jpeg file.


screenshot.java :

import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class screenshot {
int k;
public screenshot(){
k=0;
}
public void takeScreenShot() {

try {

Robot robot = new Robot();
BufferedImage bi=robot.createScreenCapture(new Rectangle(1024,768));
ImageIO.write(bi, "jpg", new File("E:\\PROJECTS\\Java Stuff\\My new Projects\\film\\imageTest"+k+".jpg"));
k++;
} catch (AWTException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

In the other class you first create an instance of the screenshot class like this :
screenshot x=new screenshot();

Then we call the function:
x.takeScreenshot();

and a picture is saved into the folder defined earlier.



This is the code of the recording.java class.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class recording implements Runnable {
screenshot x=new screenshot();
Thread th;
public static void main(String args[])
{
new recording();
}
public recording()
{
th=null;
start();
}

public void start()
{
if (th==null)
{
th=new Thread(this);
th.start();
}
}

public void run()
{
while(th!=null)
{
x.takeScreenShot();
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
System.out.println(e);
}
}
}

public void stop()
{
}
}

This small java application takes a screenshot every second and saves it in your computer.If you want to capture all the action that takes place on your screen you can lower the 1000 miliseconds timeout.That will generate lots of images though :D
You can use this trick in many ways.You can spy on someone that chats on your pc ;), you can take screenshots of you playing some game and I will just let you think about others ... Hope you will find this useful !

Tuesday, January 8, 2008

Linux Tip 3

The find command is very useful in a unix environment when one needs to find a certain category of files.For example if you have to find all the files and folders that match a pattern you can use it like that :
find /ThePathToTheSearchedDirectory -name 'picture*'
This way you can find all the files that start with 'picture'. You can find files like
picture01.png , picture02.png, picture03.png ... and you can take further actions on them.
The find command is far more complex than that.In order to learn more about a command use the man command :
Examples:

man find
man grep

etc.

Java 4K Programming Contest

First of all : Happy new year !
Java4k is a very funny contest . The best part is that you don't have to write 3 months to create a decent entry. You could create a nice game (that has to be under 4 kilobytes in size !!!) in a single night .All you have to do is to respect the rules and create a fun game.Even if you won't write a game you can just look at the other games an have tons of fun playing those small unique games.
Here is the announcement :
The Java 4K Programming Contest is the ultimate byte-squeezing Java challenge! Using only 4096 bytes, competitors use every trick up their sleeve to create an entire game.

Submit your games here before March 1st, 2007!

Contest Prizes
* 6 months free playtime of Wurm Online, courtesy of Mojang Specifications!
* Top 5 entries score a free copy of Tribal Trouble, courtesy of Oddlabs!

Basic rules are as follows:
* The final game package (byte code + resources) must be below or equal to 4096 bytes

* Must be a playable game (cannot be a pointless animation)

* Must be pure Java (no JNI)

* Must be self-contained- no external resources (e.g. loading an image from a website)

* No Pack200

* No external libraries may be used - you must use the libraries that come with the “public” version of the JRE

* No soundbanks may be used because they are not a default part of the “public” JRE. You will have to create your sounds at runtime rather than use MIDIs.

* The presentation (jar, class, or other) does not matter, as long as the code can be executed without a command line

* The target JRE is 1.5 (Java 5) or lower

Specific questions and comments can be made at the official Java 4K forum.

Official website

Good luck ;) !

Monday, December 24, 2007

Merry Christmas !


Code-on-Blog wishes you a very merry Christmas !

Wednesday, December 19, 2007

C++ challenge answer !

Remember the last C++ challenge question ? Here is the answer. It's C++ challenge not C :D.Wonder why ? Well all you have to do is to comment/delete the stdio.h inclusion.This makes the printf function an undeclared function, which you declare :D.The printing is done by using the cout function ;).

#include iostream.h
//#include stdio.h
void printf(char *c,int x)
{
cout<<"Nice trick, eh ? :)";
}
int main()
{
int a=100,b=30;
printf("%d",a+b);
return 0;
}

Doesn't sound that hard now,right ? :)

Monday, December 17, 2007

Linux Tip 2

One of the most used command in unix is cd , meaning "change directory".
To change your directory to an absolute path you have to write this : cd /root/whatever . If you want to change to a relative path you have to execute something like this : cd ./dir3/dir5 . The added dot at the beginning represents the current directory, and the rest of the command represents the path relative to the current directory. You can also skip the "." part and just write cd dir3/dir5.But must not begin with "/" ! If you do so then it will be an absolute path ! To find out the current directory while in linux(or any other unix flavor) you can type : pwd (print working directory).

This commands will help you navigate through your filesystem.