Find us on Google+ Kill the code: July 2012

Friday 27 July 2012

How to create a python server ?

Initially,you must have Python installed.

After the installation,do following.

Open a notepad file and type the following code there:

from http.server import HTTPServer, CGIHTTPRequestHandler
port = 8080
httpd = HTTPServer((”, port), CGIHTTPRequestHandler)
print(“Starting simple_httpd on port: ” + str(httpd.server_port))
httpd.serve_forever()

Save it and remember the location of it.

Thereby,

For Windows user

1.Go to Start –>All Programs–>Python 3.2–>IDLE
2.Press Ctrl+O to open the file saved above.
3.Press F5.



Above window with message “Staring simple_httpd on port 8080″ shows success of our work.

For Unix And Mac OS X Users

You need to do two things to prepare your CGI script for execution:

1. Set the executable bit for your CGI using the chmod +x command.
2. Add the following line of code to the very top of your program:
#! /usr/local/bin/python3

Thereby do another thing:
1. Open Terminal (or Shell).
2. Type python

That’s it,server is running on your *NIX OS.

That’s all how a simple “home-made” Python server is made and run,simply with above 4 steps.Send your queries below in the comments.

Thursday 12 July 2012

Windmill effect in Java Applet




Code:


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication2;

import java.applet.Applet;
import java.awt.Dimension;
import java.awt.Graphics;
import java.lang.Math;

/**
 *
 * @author zero
 */
public class NewApplet extends Applet implements Runnable {
    Dimension d = getSize();
    int b = 200;
    int c = 200;
    int a = 0;
    int x = (int)(100 * Math.cos(Math.toRadians(a)));
    int y = (int)(100 * Math.cos(Math.toRadians(a)));
    int i = 1;
    public void run() {
        while(true) {
         
            for(i = 90; i >= 0; i--) {
                try {
                Thread.sleep(5);
                }
                catch(Exception e) {
                }
                a = i;
                x = (int)(100 * Math.cos(Math.toRadians(a)));
                y = (int)(100 * Math.sin(Math.toRadians(a)));
                //showStatus(x + "," + y);
                repaint();
            }
        }
    }

    /**
     * Initialization method that will be called after the applet is loaded into
     * the browser.
     */
    public void init()
        Thread t = new Thread(this);
        t.start();
    }
 
    public void paint(Graphics g) {
        g.drawLine(b, c, b, c + 200);
        g.drawLine(b, c, b + x, c + y);
        g.drawLine(b, c, b - x, c - y);
        g.drawLine(b, c, c + y, b - x);
        g.drawLine(b, c, c - y, b + x);
        //g.drawRect(0, 0, 550, 550);
    }
 
    // TODO overwrite start(), stop() and destroy() methods
}

Tare Zammen Par effect in Java Applet




Code :

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication2;

import java.applet.Applet;
import java.awt.Dimension;
import java.awt.Graphics;
import java.lang.Math;


/*<applet code=NewApplet1' width='500' height='500'></applet>*/
/**
 *
 * @author zero
 */
public class NewApplet1 extends Applet implements Runnable {
    int a, b;
    Dimension d = getSize();
    /**
     * Initialization method that will be called after the applet is loaded into
     * the browser.
     */
    public void init() {
        Thread t = new Thread(this);
        t.start();
    }
   
    public void run() {
        while(true) {
           
                d = getSize();
                try {
                Thread.sleep(1);
                }
                catch(Exception e) {
                }
           
                a = (int)(d.width * Math.random());
                b = (int)(d.height * Math.random());
                showStatus(d.width + "," + d.height);
                repaint();
           
        }
    }
   
    public void paint(Graphics g) {
        g.drawOval(a, b, 1, 1);
    }
   
    public void update(Graphics g) {
        paint(g);
    }
    // TODO overwrite start(), stop() and destroy() methods
}