Tuesday, June 1, 2010

Openoffice.org- Play starwars galaxy easter egg OpenOffice Spreadsheet

If you are working with OpenOffice and you need a break, do this ;).


Lets start :

Open OpenOffice Spreadsheet application, then in a blank cell put this
=GAME("StarWars")

Screenshot

Click thumbnails to enlarge image
Original post:
http://www.unixmen.com/gaming-on-linux/618-openofficeorg-play-starwars-galaxy-easter-egg-in-calc
http://wiki.services.openoffice.org/wiki/Easter_Eggs

Thursday, May 27, 2010

Finding Duplicates with SQL

Here's a query for finding duplicates in a table.
SELECT id_company,
  COUNT(id_company) AS occurrences
FROM company
GROUP BY id_company
HAVING ( COUNT(id_company) > 1 )

You could also use this technique to find rows that occur exactly once as bellow
SELECT id_company
FROM company
GROUP BY id_company
HAVING ( COUNT(id_company) = 1 )

Monday, May 24, 2010

How to Create Auto Increment Columns in Oracle

CREATE TABLE test_table
(
ID NUMBER NOT NULL,
ID_COMPANY VARCHAR2(20 BYTE)
)

Table created.

CREATE SEQUENCE test_sequence
START WITH 1
INCREMENT BY 1;

Sequence created.

CREATE OR REPLACE TRIGGER test_trigger
BEFORE INSERT
ON test_table
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN
SELECT test_sequence.nextval INTO :NEW.ID FROM dual;
END;
/

Trigger created.

Now, test adding sample data


SQL> INSERT INTO test (ID_COMPANY) VALUES ('ABC123');
1 row created.

ps : Oracle is sucks. MySQL is sexy!

Wednesday, May 5, 2010

Port Scanner

File list

1) Scar.jar
2) scan.sh (runner for linux)
3) scan.bat (runner for windows)
4) README (RTFM)

ps : This is very simple port scanner, does not support proxy and no error handler, but still can be used. I just spend less than an hour for this, if there is any bug, please let me know.

Download here

Ping Specific port in JAVA

This class is for testing the connectivity to a database. Very useful to avoid data missing during db server is down. Data can be save in file or store in another db server temporarily.

package com.blogspot.lxnx;

import java.io.*;
import java.net.*;


public class Pinger {
  public static void main(String args[]) {
    try {
      InetAddress addr = InetAddress.getByName("localhost"); 
      int port = 3306; 
      SocketAddress sockaddr = new InetSocketAddress(addr, port); 
      
      // Create an unbound socket 
      Socket sock = new Socket(); 
      // This method will block no more than timeoutMs. 
      // If the timeout occurs, SocketTimeoutException is thrown. 
      int timeoutMs = 2000; // 2 seconds 
      sock.connect(sockaddr, timeoutMs); 
      System.out.println("Alive!");
    } catch (UnknownHostException e) {
      System.err.println("Unable to lookup");
    } catch (SocketTimeoutException e) {
      System.err.println("Connection timeout");
    } catch (IOException e) { 
      System.err.println("Unable to reach");
    } 
  
   }
}


credit to http://www.exampledepot.com/egs/java.net/CreateClientSocket.html

Thursday, April 15, 2010

Find Developers who Grok Coding

I just read, a post about this FizzBuzz thing, here then go to the original post. Then, i write the code in Java just for poc.

Here is my code

public class FizzBuzz {
  public static void main(String[] args) {
    for(int i = 1; i < 101; i++) {
      if (i % 3== 0 || i % 5 == 0) {
        if (i % 3 == 0)
        System.out.print("Fizz");
        if (i % 5 == 0)
        System.out.print("Buzz");
      }
      else
      System.out.print(i);
      System.out.println("");
    }
  }
} 

Thursday, March 18, 2010

How to reset ROOT password for MySQL Server 5.0

  1. Stop my sql server
  2.  Start Menu -> Control Panel -> Administrative Tools -> Services  
    

    Find mysql, right click and select stop

  3. Open Command Prompt
  4.  Run -> type "cmd"  
    
  5. Execute the following command in the command prompt
  6.  cd C:\Program Files\MySQL\MySQL Server 5.0\bin  
     mysqld-nt.exe -u root --skip-grant-tables  
    
  7. Leave the current command prompt as it is, and open a command prompt window.
  8. Execute the following command in the command prompt in the second command prompt.
  9.  cd C:\Program Files\MySQL\MySQL Server 5.0\bin  
     mysql  
    
    You should have this
     C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql  
     Welcome to the MySQL monitor. Commands end with ; or \g.  
     Your MySQL connection id is 1  
     Server version: 5.0.67-community-nt MySQL Community Edition (GPL)  
     Type 'help;' or '\h' for help. Type '\c' to clear the buffer.  
     mysql>  
    
  10. Execute the following command to update the password in the sql command windows.
  11.  UPDATE user SET Password = PASSWORD('NEW_PASSWORD') WHERE User = 'root';   
    
    Where 'NEW_PASSWORD' will be your new ROOT password

  12. After you are finished close the first command prompt and type "exit;" in the second command prompt windows to disconnect successfully. You can now start the MySQL service.
  13. *Note for Haslyn : Sorry, I just forgot mysql pass in your PC, so i write this for u.*