Posts

How to fetch the no: of weekly inserted records in MySQL

Image
SELECT   COUNT(*) AS reports_in_week,   DATE_ADD(created_at, INTERVAL(1-DAYOFWEEK(created_at)) DAY) as start_day,   DATE_ADD(created_at, INTERVAL(7-DAYOFWEEK(created_at)) DAY) as end_day FROM   your_table_name GROUP BY   YEAR(created_at) + .01 * WEEK(created_at) The desired output will be.

How to add Startup Script for MySQL or any other services in Centos/RedHat

Note: Perform the below steps as root user 1) Find out the name of service’s script from /etc/init.d/ directory e.g. mysqld or httpd 2) Add it to chkconfig chkconfig --add mysqld 3) Make sure it is in the chkconfig chkconfig --list mysqld 4) Set it to autostart chkconfig mysqld on Note: To stop a service from auto starting on boot chkconfig mysqld off If you have IPTables you need to flush them  and save that, So that on every reboot we get a flushed iptable. 1) iptables -F 2)  service iptables save

How to redirect a URL in NGINX

How to redirect a http://test.com to http://www.com Your main server block will be like server {             listen       80;             server_name  www.test.com;             client_max_body_size   10M;             client_body_buffer_size   128k;             root       /home/test/test/public;             passenger_enabled on;             rails_env production;             error_page   500 502 503 504  /50x.html;       ...

ImageMagick Installation in Centos

Run the commands as root user  yum install ImageMagick ImageMagick-perl yum install ImageMagick-devel gem install rmagick Now restart your server and you are ready to shoot..!!

How to reset MySQL Root password

service mysqld stop (To stop the currently running MySQL instance) mysqld_safe --skip-grant &   (To enter into MySQL in safe mode) use mysql; update user set password=PASSWO RD("NEW-ROOT-PASSWORD" ) where User='root';   (To set the new root password) service mysqld restart (To restart the MySQL instance)

How to set GIT (master or branch) to a previous commit version

First you need to switch to the desired location master or branch git checkout master or branch_name Then git push -f origin commit_id:mast er  (For master) git push -f origin commit_id:branch_name ( For branch) Then you also need to cancel your local commit git reset --hard commit_id (from the desired location)

How to Ignore certain files from Git commit (modified but never need to commit)

Sometimes we may need to ignore certain modified files from Git commit (Eg: config/database.yml). This can be done by issuing  the following command from your project path git update-index --assume-unchanged config/database.yml Or in case of folder git update-index --assume-unchanged folder-name/ In the case of a new folder or file (Not added to GIT before) we can ignore by adding it to .gitignore file Create a .gitignore file if doesn't exist in your project path Add the required folder or file path in it.            # Ignore bundler config              .bundle          # Ignore the default SQLite database.             db/*.sqlite3          # Ignore all logfiles and tempfiles.            log/*.log            tmp