Thursday, August 2, 2012

Mysql grant


mygrants()
{
  mysql -B -N $@ -e "SELECT DISTINCT CONCAT(
    'SHOW GRANTS FOR ''', user, '''@''', host, ''';'
    ) AS query FROM mysql.user" | \
  mysql $@ | \
  sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}'
}

Put the above command to /root/.bashrc and when typing mygrants command, it will show the mysql privilege

Tuesday, July 24, 2012

htaccess redirect to www

To redirect a domain from a non www to a www domain, just add .htaccess


RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


to reverse redirect a domain from a www to a non www


RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]
RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]


Another way using the conf

redirect permanent / https://insert-url-of-your-site/

Example of using multiple url to point to the same site

  ServerName domain1.net
  DocumentRoot /opt/rlcache/www/moodle_prod
  Alias /sandbox /opt/rlcache/www/moodle_sand



  ServerName  domain2.net
  Redirect permanent / http://domain1.net/









Wednesday, July 18, 2012

Add column to existing table in mysql


ALTER TABLE contacts ADD email VARCHAR(60);

This first statement will add the email column to the end of the table. To insert the new column after a specific column, such as name, use this statement:

ALTER TABLE contacts ADD email VARCHAR(60) AFTER name;

If you want the new column to be first, use this statement:

ALTER TABLE contacts ADD email VARCHAR(60) FIRST;

To remove a column
ALTER TABLE table_name
DROP COLUMN column_name

Sunday, June 10, 2012

Create zip file in linux

zip -r archivefilename.zip foldertocompres/

Quick hint to use vi

vi Cheatsheet 
dd to delete line
/string Search forward for string
?string Search back for string
:s/pattern/string/flags Replace pattern with string according to flags.
g Flag - Replace all occurences of pattern
c Flag - Confirm replaces.
& Repeat last :s command

A to go to end of line and Insert mode
$ to go to end of line

I to go to first of line and Insert mode
0 to go to first of line

1G Move to the first line of the file
G Move to the last line of the file
nG Move to nth line of the file
:n Move to nth line of the file

Thursday, June 7, 2012

Redirect to https using .htaccess

Create .htaccess file to redirect site to https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Monday, June 4, 2012

Moodle 2 restore questionnaire

Backup from moodle 1.9 to moodle 2 will not include the questionnaire. However, now there is a fix already. Here is the information http://tracker.moodle.org/browse/CONTRIB-3044?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel Simply download lib.php and place it to mod/questionnaire/backup/moodle1/lib.php