Friday, December 25, 2015

30th Coding Anniversary


I was selected into a interest group learning programming in BASIC (using Apple IIe and Laser-310) in December 1985, when I was in year 8. It was fun. I learned coding so hard that I got first prize award (equal 1st, Year 7-9) in programming competition in my home city few months later in 1986. One question in the competition was swapping the values in 2 variables without using a 3rd variable. My name was published on newspaper and I told my parents I'm famous.
Admission ticket, 1986

I got three more first prize awards later, 4th place (Y7-9) in 1987, 3rd place (Y10-12) in 1988 and 2nd place (Y10-12) in 1989. The last one in June 4th 1989 was the most difficult. I got mumps below my left ear and had been stayed at home and almost couldn't eat anything for a week just before the competition, which I sit in No. 15 Middle School, very close to my then home.
First prize certificate, 1986

These are few things happened before I went to university studying computer science and software engineering. I have come a long way and these things always remind me of where I came from, and where the determined boy wanted to go three decades ago.

Merry Christmas and Happy Coding!

Wednesday, November 18, 2015

Delete photos from phone (but keep them in Google Photos)

With Google's Back up & sync, if you delete a photo from your phone in Google Photos, the photo will be deleted from any where. In case this is what you intend to do, here're the steps
  1. Open Google Photos
  2. Click the hamburger button at the top left corner, or swipe right from left edge of screen
  3. Select "Device folders"
You know how to do the next.

Sunday, October 18, 2015

Merit Certificate in Science Talent Search 2015

The boy got a merit certificate this year. This is also the end of his fantastics 7-year STS journey. The next chapter is waiting for him to explore, so it's right time to move on.

It's my privilege to be able to work with him all the way. The little boy curious about how computer programs work has become a pretty mature problem solver. I'll never forget the very first time he went out from the judging room, told me he was asked a question 'what's a variable?'.

If you have a Pebble smartwatch, you may want to try his application here.

Tuesday, June 16, 2015

Don't mock microservices

Didn't I just post Use Caching Service as Mocked Microservices? Yes, that post is basically saying that instead of each test case/suite starts its own mocked HTTP server, sets expectation, sends request to it then shuts it down, as a side-product, a caching service can be use as an alternative.

The idea behind is, client calls dependency services in test environment in the same way it calls dependency servies in production environment. How about we go one step further, always call a real service instead of its mocked version?

This used to be hard for monolithic architecture. With shifting to microservices, it's just a matter of few more deployments, a service can provide test / staging / UAT environments to clients. This removes client's burden to set up and tear down test fixtures, so that test code can reuse production application context configuration, if you use Spring Framework. But that's not all.

The biggest benifit in my opinion is, it removes the grey area of responsibility between service provider and consumer. Who's job it is to update a mock service's behavior when the real service changes its behavior? Just imagine how many times your unit tests pass but still fail in integration test or production, simply because the real service now returns B, but your mocked service still returns A.

Better communication within team doesn't solve this problem, real-time communication between service consumer and provider does.

Thursday, May 07, 2015

Use Caching Service as Mocked Microservices

For a long period of time, we've been using mocking framework to ease unit testing. The idea behind is,
  • in production, object A's method a() calls object B's method b()
  • in test, we
    • pre-define b()'s behaviour
    • inject mocked object B into object-under-test A
    • fire a() and verify the output
With the shift from monolithic style to microservices oriented software design, we call remote APIs (RESTful or RPC) more often than we did before. Quite a few HttpMock products were created to allow us to test remote APIs the way we used to test local APIs.

But if we have a real HTTP server somewhere, in order to mock response from remote, all we need is to set up endpoint with the response and later tear it down. As a side-product, caching service is such a HTTP server that can easily be used to mock remote APIs object-under-test consume. It works this way
  • in product, object A's method a() send HTTP request to service B's endpoint b
  • in test, we
    • pre-populate (POST) expected response in cache server for endpoint b
    • send (GET) HTTP request to it (instead of the production endpoint) from A.a()
    • get response from cache server and verify a()'s output
    • remove (DELETE) the response from cache server
Now you see how the idea of microservices may also change the way you test your microservice oriented production code.

Happy testing!

Thursday, April 09, 2015

Push specific local commit to remote

Like what's asked in this Stack Overflow question, sometimes we keep local commits for a while, amending commit message, merging multiple commits into a more meaningful one, trying something in a branch from unpublished commits and so on. And finally, we decide to push some oldest commits to remote. Here are the steps.
  1. Check in all changes locally

  2. Branch it (not only for backup, but also to keep commit history when resetting)
  3. git branch backup

  4. Reset to the oldest unpublished commit
  5. git reset --hard {sha of commit to push}

  6. Push it to remote
  7. git push origin {branch}

  8. Go to step 2 if you have more commit to push

  9. Reset to latest local commit
  10. git reset --hard {sha of latest commit}

  11. Delete backup branch
  12. git branch -d backup

Happy coding!