Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Sunday, March 4, 2012

java program without main method :)


This is very unconventional but a valid code and it will run!!, the magic is the static initializer block. this block is hidden from every class by default but it executes when the class is first loaded, it prints out “Hello World” without writing a main method and the execution is stopped using System.exit() command, so preventing “main method not found” error.


public class HelloWorldWithoutMain {
    static {
        System.out.println(“Hello World!”);
        System.exit(0); // prevents “main method not found” error
    }
}

Tuesday, April 12, 2011

php - keyboard input

I was thinking yesterday that is it possible in PHP to take input from keyboard. I started to digg and find out it is possible but no one use it because PHP was not designed to take input from keyboard :) anyway i am posting code here take a look :

#!/usr/bin/php
[php open tag]
function getinput(){
print("Your input: ");
$stdin = fopen("php://stdin", 'r');
$input = fgets($stdin, 1024);
$input = trim($input);
fclose($stdin);
return $input;
}

function output($message){
print $message."\n";
}

$message = getinput();
output($message);
[php end tag]

Wednesday, August 11, 2010

QTableWidget bug

to remove rows from QTableWidget you have to
run the loop in reverse order. like this:

in python do this:

for x in reversed(range(self.tableWidget.rowCount())):
self.tableWidget.removeRow(x)

for c++ do this:

for (int i=view->rowCount()-1; i >= 0; --i)
removeRow(i);
for (int i=view->columnCount()-1; i>=0; --i)
removeColumn(i);

list open ports and unix sockets

To do this I use netstat command to list all open ports: $ sudo netstat -tuplen to list open ports and unix sockets: $ sudo netstat -...