Welcome to Gary Han's den on the web.
This portal records Gary's everyday thoughts and notes on programming and life.
Please enjoy...

Wednesday, December 6, 2017 - 10:45pm

  • Wednesday, December 6, 2017 - 10:45pm

    OK! After selling my 4 bitcoins I had left back in the days for $10,000 few months ago to now what claimed to be $16k for 1??!!!

    I had to write something about bitcoin...

    First of all, the idea of crypto-currency is very promising. HOWEVER how bitcoin implemented the currency has huge issues.

    1. The so called mining process uses a trial and error method to find the next nonce value that will create a hash value that is smaller than the previous hash value. And the time to find that next nonce is the "work" you need to do. (which i think is stupid and waste of power)

Saturday, October 8, 2016 - 8:08pm

  • Saturday, October 8, 2016 - 8:08pm

    few ways to get the user information:

    -User user= (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    this pulls the whole user object.

    - Principal userPrincipal = request.getUserPrincipal();
    this pulls the user principal, which has access to the username by doing:
    userPrincipal.getName();

    - User currentUser = request.getSession(false).getAttribute("SPRING_SECURITY_CONTEXT").getAuthentication().getPrincipal();
    you may do a few null checks, but this is the long and early way to get the user. Works in the filters too.

Monday, September 19, 2016 - 4:29pm

  • Monday, September 19, 2016 - 4:29pm

    Just a fun note,

    I was having a discussion with a group of programmers from different backgrounds.

    And I was asked the question whats a better language and why do you prefer Java.

    So my answer is, I like to build using Lego not PlayDoh.

    When I program in Java, I feel my program is very safe and consistent.

    when I program in PHP, Python or Ruby, I feel my program is very squishy.

    A simply example is:

Monday, September 22, 2014 - 7:15pm

  • Monday, September 22, 2014 - 7:15pm

    We can go on and on about feature differences on Oracle and Mysql. Table locking, stored proc, recovery, transaction control blah blah blah...
    As a software user (yes, they are just regular software we use) I don't really care as long as it works and does what I need.

    So today I want to get to the point and take note of the performance differences in Oracle and Mysql.

    The key difference in Oracle over Mysql is its ability to perform fast CRUDs even under large number of threads and transactions.

Wednesday, April 9, 2014 - 4:36pm

  • Wednesday, April 9, 2014 - 4:36pm

    Since so many people are talking about this issue, I will join too.

    Openssl has a very simple yet dangerous flaw in the programming when they implemented the heartbeat feature.

    Heartbeat is used to keep the session alive by having client server send a request over and the hosting server sends a response back.

    But the issue with that is the request contains both the package and the package size.

    and openssl simply echos back the original package and append anything after it with whatever package size it was specified?
    REALLY? SERIOUSLY?

Tuesday, October 8, 2013 - 5:50pm

  • Tuesday, October 8, 2013 - 5:50pm

    Websphere is a pain in the butt to deal with.

    So whenever you have issues deploying a war file or any kind of issues,

    first thing to try is to clear the websphere cache! I will do the trick 99% of the time!

    to do so:

    shut down websphere server.

    /{websphereInstallPath}/IBM/WebSphere/AppServer/bin/clearClassCache.sh
    rm -rf /{websphereInstallPath}/IBM/WebSphere/AppServer/profiles/AppSrv01/logs/*
    rm -rf /{websphereInstallPath}/IBM/WebSphere/AppServer/profiles/AppSrv01/wstemp/*
    rm -rf /{websphereInstallPath}/IBM/WebSphere/AppServer/profiles/AppSrv01/temp/*

Wednesday, August 21, 2013 - 8:43pm

  • Wednesday, August 21, 2013 - 8:43pm

    If you are putting your database to maintenance, and you want to kill off all sessions from connecting your db so you can do whatever you want with it.

    Do the follow for a quick clean up:

    STARTUP FORCE;
    ALTER SYSTEM ENABLE RESTRICTED SESSION;

    now you are free to do whatever you want with your database.

    when you are done:

    ALTER SYSTEM UNQUIESCE;

    now all other connections can start hitting your database again.

Wednesday, June 5, 2013 - 5:14pm

  • Wednesday, June 5, 2013 - 5:14pm

    simple reminder to enable ftp on server:

    yum -y install vsftpd

    vi /etc/vsftpd/vsftpd.conf

    ensure a line listen_port=21 is added to the config file,
    and remove #connect_from_port_20=YES

    vi /etc/vsftpd/ftpusers
    remove root as not allowed user

    vi /etc/vsftpd/user_list
    remove root as not allowed user

Tuesday, April 23, 2013 - 4:21pm

  • Tuesday, April 23, 2013 - 4:21pm

    When working with special characters we sometimes run into the issue where the string is not recognizing these characters.
    Especially when trying to parse files from one platform from another.

    I had the following line in a txt file on windows: (saved as ANSI)

    éèêë

    I had the following code that parses and replaces these characters:
    (Java file is saved as UTF-8)
    -------------------
    File file = new File("/windowsPathMappedOnLinux");
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    DataInputStream dis = null;
    String fileContent = "";

Tuesday, August 9, 2011 - 10:56pm

  • Tuesday, August 9, 2011 - 10:56pm

    When you get a database dump from a server and try to import it to one another, often u will face errors like:

     DEFAULT '1753-01-01 00:00:00', "end_date" DATE DEFAULT '1753-01-01
    ORA-39083: Object type TABLE failed to create with error:
    ORA-01861: literal does not match format string

     

    This indicates that the database dump might be using a string format which is different from your server.

    To prove this, login to sqlplus, and do:

    select sysdate from dual;

    if the result is not of: