Programming Notes

  • 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 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

    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

    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

    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.

  • 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

    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:

  • Thursday, March 3, 2011 - 4:00pm

    Many of us might have came to the probelm where in IE or Chrome, when visiting the secure pages an alert message pops up saying that some of the content of the page is not encrypted.
    This is usually due to non-relative links on our page.
     
    i.e.:
    in: https://www.garyhan.com/secure but some how all your images and css are showing up as http.
    This is because usually when setting up a load balancer, the encryption is handled on the balancer(LB) level, then the LB transfers requests to each of your servers on http port.

  • Wednesday, November 3, 2010 - 9:49pm

    Just a reminder,
     
    when you have connection failures trying to connect to localhost, while everything else seems fine.
     
    First thing is try 127.0.0.1
    because sometimes the application does not know how to resolve localhost.
     
     

  • Thursday, October 28, 2010 - 5:41pm

    This is just a reminder that when you go to a Oracle database and when u do:
    select * from table_name;
    it returns view or table not exist
     
    yet the table does exist.
     
    Please try:
     
    select * from "table_name";
     
    In Oracle, if you create a table with case sensitive (the " " around your table name) you must also reference it by " " when u run queries.
     
    if you create table table_name (without the " ")
    then you may do:

  • 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 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

    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

    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

    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.

  • 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

    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:

  • Thursday, March 3, 2011 - 4:00pm

    Many of us might have came to the probelm where in IE or Chrome, when visiting the secure pages an alert message pops up saying that some of the content of the page is not encrypted.
    This is usually due to non-relative links on our page.
     
    i.e.:
    in: https://www.garyhan.com/secure but some how all your images and css are showing up as http.
    This is because usually when setting up a load balancer, the encryption is handled on the balancer(LB) level, then the LB transfers requests to each of your servers on http port.

  • Wednesday, November 3, 2010 - 9:49pm

    Just a reminder,
     
    when you have connection failures trying to connect to localhost, while everything else seems fine.
     
    First thing is try 127.0.0.1
    because sometimes the application does not know how to resolve localhost.
     
     

  • Thursday, October 28, 2010 - 5:41pm

    This is just a reminder that when you go to a Oracle database and when u do:
    select * from table_name;
    it returns view or table not exist
     
    yet the table does exist.
     
    Please try:
     
    select * from "table_name";
     
    In Oracle, if you create a table with case sensitive (the " " around your table name) you must also reference it by " " when u run queries.
     
    if you create table table_name (without the " ")
    then you may do:

  • Tuesday, December 22, 2009 - 12:33am

    I have worked with many javascript libraries, and many are worthy to be remembered.

     

    The Prototype Javascript Framework

        This is one of the oldest framework existed on the web. In the earlier versions, the framework provided simple tools for manipulating the DOM tree. Things like element.addClassName, element.addMethods etc.

  • Wednesday, December 16, 2009 - 11:54pm

        AJAX seems to be the big thing about web programming now adays.

        The purpose of this tutorial is to quickly remind myself what AJAX is incase I forget.

         AJAX stands for Asynchronous JavaScript and XML

     

  • Wednesday, December 16, 2009 - 11:44pm

    The following makes up the foundation of an AJAX call for most javascripts.

    The core of AJAX programming is to make http requests, then displaying the response to the page without refreshing the whole page.

    For more information on AJAX, please check out the AJAX Tutorial

    I found it understands better when putting the whole tutorial on the same page.

    ------------------------------------------------