Saturday, April 14, 2012

Wildcard Host doesn't work in MySQL 5.5.22

I haven't used MySQL for a while. After reinstalled my laptop with Ubuntu 12.04 Beta 2, I decided to use MySQL instead of PostgreSQL to continue my JPA study.

sudo apt-get install mysql-server

I used MySQL Administrator long time ago and now it's replaced with powerful MySQL Workbench. If you have difficulties in installing it, please follow this tutorial.

Everything seems fine, just like when I developed myTunes 6 years ago, except that % for any host doesn't work any more. So if you get

ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: YES)

Update Host column from % to localhost for your user account and restart MySQL will solve it.

Update: you can also remove anonymous accounts by executing delete from user where user=''; (Thank you, Dan)

Sunday, March 04, 2012

Everybody Loves FizzBuzz

One of my career objectives is implementing business requirements in a way that makes
  • customer / employer happy
  • developers happy, and
  • infrastructure happy
at the same time. I'd like to take FizzBuzz puzzle as an example to illustrate how attention to detail helps me achieve this goal in Java.
Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

public class FizzBuzz {

    public static void main(String[] args) {
        boolean fizzOrBuzz;

        for (int i = 1; i <= 100; i++) {
            fizzOrBuzz = false;

            if (i % 3 == 0) {
                fizzOrBuzz = true;
                System.out.print("Fizz");
            }

            if (i % 5 == 0) {
                fizzOrBuzz = true;
                System.out.print("Buzz");
            }

            if (!fizzOrBuzz) {
                System.out.print(i);
            }

            System.out.println();
        }
    }
}

Update (06/12/2014): https://github.com/codingsince1985/FizzBuzz