Wednesday, May 27, 2015

[Codeigniter][Resolved] Remove index.php from url

To remove the “index.php” away from url, following the official documents only is not always works. After some searching in google found following a tutorial from Formget.com can do a good jobs and let share here:

Edit Config.php file:
 look for the "application/config/config.php" file, change the value of $config['index_page'] from "index.php" to "".
 From
$config['index_page'] = "index.php"; 
To
$config['index_page'] = "";


And Then change the value of $config['uri_protocol'] from "AUTO" to "REQUEST_URI":



.htaccess
Create an empty files named ".htaccess" at your Codeigniter project root, and paste these code inside the file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] 







Reference:
https://ellislab.com/codeigniter/user-guide/general/urls.html
http://www.formget.com/codeigniter-htaccess-remove-index-php/

Monday, May 18, 2015

[Linux] Command to list out all user group / check user in which group

command to list out all user group:

groups


For this case, there is one user group only : root

command to check user in which group:

groups username

In this simple, user "kana" is not in any group, johnwong in "root" group


Reference:
http://www.howtogeek.com/howto/ubuntu/see-which-groups-your-linux-user-belongs-to/

Saturday, May 16, 2015

[Java][Answer] CodingBat Array-2 > sum28

Given an array of ints, return true if the sum of all the 2's in the array is exactly 8.

sum28([2, 3, 2, 2, 4, 2]) → true
sum28([2, 3, 2, 2, 4, 2, 2]) → false
sum28([1, 2, 3, 4]) → false

Answer 1:

public boolean sum28(int[] nums) {
  int sum =0;
  for(int i=0;i<nums.length;i++){
    sum += nums[i]==2?2:0;
  }
  return sum == 8;
}

Answer 2:

public boolean sum28(int[] nums) {
  int sum = 0;
  boolean is8 = false;
 
  for (int i = 0; i < nums.length; i++) {
    if (nums[i] == 2)
      sum += 2;
  }
  if (sum == 8)
    is8 = true;
  return is8;
}

Reference

http://www.javaproblems.com/2013/11/java-array-2-sum28-codingbat-solution.html

Monday, May 11, 2015

[MySQL][sql] Select first four characters only from returned field

You can use the MySQL LEFT() function:

Syntax
LEFT (string, length)

Example:
SELECT date AS year FROM news


SELECT left(date,4) AS year FROM news 



Reference:
http://stackoverflow.com/questions/12504985/how-to-take-last-four-characters-from-a-varchar