Skip to main content

Posts

SQL query optimization

SELECT query {EXPLAIN | DESCRIBE | DESC}  We usually use this command to check to see if how many rows the query goes through. Especially for the INDEX column checking. Search LIKE '%key%' consumes more resource than LIKE 'key%' Denormalisation This database design helps to speed up the data reading. Because the SQL query no need to join data between tables.
Recent posts

Some popular design patterns

Singleton design pattern This pattern makes sure only one object is created and used though out the system. Create a static instance in the single class public class SingleObject { //create an object of SingleObject private static SingleObject instance = new SingleObject (); //make the constructor private so that this class cannot be //instantiated private SingleObject (){} //Get the only object available public static SingleObject getInstance (){ return instance ; } public void showMessage (){ System . out . println ( "Hello World!" ); } } Use this instance through the system. public class SingletonPatternDemo { public static void main ( String [] args ) { //illegal construct //Compile Time Error: The constructor SingleObject() is not visible //SingleObject object = new SingleObject(); //Get the only object available SingleObject object = S

Sub-program (procedure and function) in SQL

What is sub-program in SQL? Sub-program is a programming unit which is created in a database to perform some tasks on data. Basic usages of sub-program? Create CREATE PROCEDURE or CREATE FUNCTION Delete DROP PROCEDURE or DROP FUNCTION Two kinds of sub-program: PROCEDURE: perform an action but NOT return a value, but we can get output value by OUT variables. and FUNCTION: compute and return a value Create procedure: CREATE [ OR REPLACE ] PROCEDURE procedure_name [( parameter_name [ IN | OUT | IN OUT ] type [, ...])] { IS | AS } BEGIN < procedure_body > END procedure_name ; Create function: CREATE [ OR REPLACE ] FUNCTION function_name [( parameter_name [ IN | OUT | IN OUT ] type [, ...])] RETURN return_datatype { IS | AS } BEGIN < function_body > END [ function_name ]; What is cursor? A cursor holds the rows (one or more) returned by a SQL statement. Triggers are stored programs, which are automatically executed or fired wh

Fix cross domain in ajax request

Follow this sample ajax request $.ajax({    "type": 'POST',    "url": url,     "crossDomain": true,    "data": params,    "dataType": 'json',    "async": false,    "success": function(data){ done_fn(data, is_test);    },    "error": function (jqXHR) { var data = $.parseJSON(jqXHR.responseText); $("#results").text(data.message);    } }); The keys are crossDomain: true and async: false Hope to help many people.

Jenkins: SSH connect with username and password to AWS Linux instance

Jenkins  2.46.1 does not support to have a ssh connection with default pem file from aws. To do the automatically deployment from Jenkins server, a ssh connection should be establish from Jenkins server to the instance. These are steps to do to enable the SSH connection: AWS instance: Create a new user on the instance Edit the SSH config file to enable Password authentication for SSH and especially, specify some special encryption algorithms that supports Jenkins  File: /etc/ssh/sshd_config Put this at the end of the file KexAlgorithms diffie-hellman-group1-sha1,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1 Use the new created user for Jenkins  

New features in PHP 7

1. Performance   PHP 7 helped to reduce the memory usage and increase the performance. Some benchmarks show that the new performance is as twice as PHP 5.6. PHP 7 can handle 2580 requests per second comparing to 1400 requests per second (Drupal). In my case, the wordpress site of our company needed 25s to fully load, after I apply PHP 7, the loading time is only 8s. Why is PHP 7 faster? + New core engine PHP 4 uses Zend Engine (not confused with Zend framework) PHP 5 uses Zend Engine II PHP 7 uses PHPNG, a refactored Zend Engine II The refactoring makes the new generation of engine consume less memory (bucket size, HashTable size, etc), less CPU resource. 2. Declare type for variables In PHP 5 does not require developers to declare type. Type declaration helps developers to get the expected result. But in PHP 5, dev also can declare type using Type hinting, however, this is limited to function parameters declaration only and also limited to Class type and Array

Recommender engine - Part 2: How does Recommendation work and how to use it?

3. How does it work? Content-based recommendation User-behaviour-based recommendation  4. How to apply it to your website?  Third-party service  Do it your own, coursera website  https://articles.uie.com/recommendation_systems/ http://fortune.com/2012/07/30/amazons-recommendation-secret/ https://www.quora.com/How-much-sales-lift-is-attributed-to-Amazons-recommendation-engine http://glinden.blogspot.com/2006/12/35-of-sales-from-recommendations.html https://articles.uie.com/recommendation_systems/ https://www.quora.com/What-are-the-benefits-of-using-product-recommendations-on-my-e-commerce-site