Friday, November 18, 2011

C# - Draw a Rectangle on a Picture Box on Mouse-Move

private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
 pictureBox1.Refresh();
 System.Drawing.Graphics g = pictureBox1.CreateGraphics();
 System.Drawing.Pen p = new System.Drawing.Pen(System.Drawing.Color.Blue);
 g.DrawRectangle(p, new Rectangle(e.X, e.Y, 40, 80));
 p.Dispose();
 g.Dispose();
}

Thursday, November 17, 2011

Enable Query Log for MySQL

File: my.ini

[mysqld]
#Set General Log
log = "c:/wamp/logs/genquery.log"

Monday, October 17, 2011

අපි හැමදාමත් ආදරෙයි !

අපි ඉස්සර නිවාඩු කාලේ එනකම් බලං ඉන්නේ මාමා හඬ කවපු කාටුන් බලන්න.
අපේ පුංචි කාලේ ලස්සන කරපු මාමාට අපි එදා වගේම අදත් ගොඩාරියක් ආදරෙයි!
මාමාට නිවන් සුව ලැබෙන්න කියලා පුංචි අපි හැමෝම ප්‍රාර්ථනා කරනවා.

Wednesday, September 21, 2011

Drag Drop with a Custom Icon in C#



Code:

        private void frmDragDrop_Load(object sender, EventArgs e)
        {
            //enable the dragged item to be dropped on to the target
            this.txtDropTarget.AllowDrop = true;
            //to make the custom drag icon visible over the form
            //we must allow drop on the form but take no action upon it
            this.AllowDrop = true; 
        }

        private void lblDragSource_MouseDown(object sender, MouseEventArgs e)
        {
            //initiate the drag operation
            //the given DragDropEffect iindicates cursor to use when dropping is allowed
            lblDragSource.DoDragDrop(lblDragSource.Text, DragDropEffects.Copy);
        }

        private void txtDropTarget_DragEnter(object sender, DragEventArgs e)
        {
            //if dragging has data, show the droppable cursor
            //otherwise show the no-drop cursor
            if (e.Data.GetDataPresent(DataFormats.Text))
                e.Effect = DragDropEffects.Copy;
            else
                e.Effect = DragDropEffects.None;
        }

        private void frmDragDrop_DragEnter(object sender, DragEventArgs e)
        {
            //this is where the actual "show drag icon over the form" occurs
            if (e.Data.GetDataPresent(DataFormats.Text))
                e.Effect = DragDropEffects.Copy;
            else
                e.Effect = DragDropEffects.None;
        }

        private void txtDropTarget_DragDrop(object sender, DragEventArgs e)
        {
            //process the drop action
            txtDropTarget.Text = (string)e.Data.GetData(DataFormats.Text);
        }

        private void lblDragSource_GiveFeedback(object sender, GiveFeedbackEventArgs e)
        {
            //customize the drag cursor for the given DragDropEffect for this control
            e.UseDefaultCursors = e.Effect != DragDropEffects.Copy;
            Cursor.Current = new Cursor("1.ico");
        }


Sources:
http://www.switchonthecode.com/tutorials/winforms-using-custom-cursors-with-drag-drop
http://www.switchonthecode.com/tutorials/csharp-tutorial-how-to-use-custom-cursors
http://stackoverflow.com/questions/1733912/how-do-i-handle-dragging-of-a-label-in-c

Wednesday, August 17, 2011

PHP mail() on WAMP

  1. Install the fake sendmail. (http://glob.com.au/sendmail/)

  2. Configure fake sendmail to use a valud SMTP server.

    example: Gmail
    smtp_server=smtp.gmail.com
    auth_username=your gmail username
    auth_password=your gmail password


    sources:
    https://mail.google.com/support/bin/answer.py?answer=13287
    http://www.geekzone.co.nz/tonyhughes/599

  3. Configure "php.ini" to use fake sendmail.

    example:
    sendmail_path = "c:\wamp\sendmail\sendmail.exe -t"

    source:
    http://www.joshstauffer.com/send-test-emails-with-wampserver/

  4. Restart Apache/WAMP.

  5. Write a call to mail() in PHP & run it.

Monday, July 25, 2011

Weather Report

It was autumn, and the Red Indians asked their New Chief 'the winter is going to be cold or mild?' Since he was a Red Indian chief in a modern society, he couldn't tell what the weather was going to be.

Nevertheless, to be on the safe side, he replied to his Tribe that the winter was indeed going to be cold and that the members of the village should collect wood to be prepared.

But also being a practical leader, after several days he got an idea. He went to the phone booth, called the National Weather Service and asked 'Is the coming winter going to be cold?'

'It looks like this winter is going to be quite cold indeed,'the weather man Responded.

So the Chief went back to his people and told them to collect even more wood. A week later, he called the National Weather Service again. 'Is it going to be a very cold winter?'

'Yes,' the man at National Weather Service again replied, 'It's definitely going to be a very cold winter.'

The Chief again went back to his people and ordered them to collect every scrap of wood they could find. Two weeks later, he called the National Weather Service again. 'Are you absolutely sure that the winter is going to be very cold?'

'Absolutely,' The Man replied. 'It's going to be one of the coldest winters ever..''

'How can you be so sure?' the Chief asked.

The weatherman replied, 'The Red Indians are collecting wood like Crazy!!!'

Friday, July 22, 2011

Reset MySQL Root Password

Resetting the root password of a MySQL database is trivial if you know the current password if you don't it is a little tricker. Thankfully it isn't too difficult to fix, and here we'll show one possible way of doing so.

If you've got access to the root account already, because you know the password, you can change it easily:

steve@steve:~$ mysql --user=root --pass mysql  Enter password:    mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root'; Query OK, 2 rows affected (0.04 sec) Rows matched: 2  Changed: 2  Warnings: 0   mysql> flush privileges; Query OK, 0 rows affected (0.02 sec)  mysql> exit Bye

However if you don't know the current password this approach will not work - you need to login to run any commands and without the password you'll not be able to login!

Thankfully there is a simple solution to this problem, we just need to start MySQL with a flag to tell it to ignore any username/password restrictions which might be in place. Once that is done you can successfully update the stored details.

First of all you will need to ensure that your database is stopped:

root@steve:~# /etc/init.d/mysql stop 

Now you should start up the database in the background, via the mysqld_safe command:

root@steve:~# /usr/bin/mysqld_safe --skip-grant-tables & [1] 6702 Starting mysqld daemon with databases from /var/lib/mysql mysqld_safe[6763]: started 

Here you can see the new job (number "1") has started and the server is running with the process ID (PID) of 6702.

Now that the server is running with the --skip-grant-tables flag you can connect to it without a password and complete the job:

root@steve:~$ mysql --user=root mysql Enter password:  mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root'; Query OK, 2 rows affected (0.04 sec) Rows matched: 2  Changed: 2  Warnings: 0  mysql> flush privileges; Query OK, 0 rows affected (0.02 sec)  mysql> exit Bye 

Now that you've done that you just need to stop the server, so that you can go back to running a secure MySQL server with password restrictions in place. First of all bring the server you started into the foreground by typing "fg", then kill it by pressing "Ctrl+c" afterwards.

This will now allow you to start the server:

root@steve:~# /etc/init.d/mysql start Starting MySQL database server: mysqld. Checking for corrupt, not cleanly closed and upgrade needing tables.. 

Now everything should be done and you should have regained access to your MySQL database(s); you should verify this by connecting with your new password:

root@steve:~# mysql --user=root --pass=new-password-here Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 5 to server version: 5.0.24a-Debian_4-log  Type 'help;' or '\h' for help. Type '\c' to clear the buffer.  mysql> exit Bye

Source: http://www.debian-administration.org/articles/442

Thursday, July 21, 2011

Audit

Once upon a time there was a shepherd looking after his sheep on the side of a deserted road. Suddenly a brand new Porsche screeches to a halt. The driver, a man dressed in an Armani suit, Cerutti shoes, Ray-Ban sunglasses, TAG-Heuer wrist-watch, and a Pierre Cardin tie gets out and asks the shepherd, "If I can tell you how many sheep you have, will you give me one of them?" The shepherd looks at the young man, and then looks at the large flock of grazing sheep and replies, "Okay."

The young man parks the car, connects his laptop to the mobile-fax, enters a NASA Website, scans the ground using his GPS, opens a database and 60 Excel tables filled with algorithms and pivot tables. He then prints out a 150-page report on his high-tech mini-printer, turns to the shepherd and says "You have exactly 1,586 sheep." The shepherd cheers, "That's correct, you can have your sheep." The young man takes one of the animals from the flock and puts it in the back of his Porsche.

The shepherd looks at him and asks, "If I guess your profession, will you return my animal to me?" The young man answers, "Yes, why not?" The shepherd says, "You are an auditor." "How did you know?" asks the young man. "Very simple", answers the shepherd. "First, you came here without being wanted. Secondly, you charged me a fee to tell me something I already knew. Thirdly, you don't understand anything about my business..... Now can I have my dog back?"