Articles & Code Snippets

Articles


MySQL update to remove whitespaces

Posted by Cătălin on Wed, 13 Sep 2017

This is how you can replace spaces with MySQL update query

Replace spaces UPDATE `table` SET `col_name` = REPLACE(`col_name`, ' ', '') Remove all tabs characters UPDATE `table` SET `col_name` = REPLACE(`col_name`, '\t', '' ) Remove all new line characters UPDATE `table` SET `col_name` = REPLACE(`col_name`, '\n', '') http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace Remove first and last space(s) of column UPDATE `table` SET `col_name` = TRIM(`col_name`) http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_trim

design

Google Chrome (ERR_EMPTY_RESPONSE)

Posted by Cătălin on Wed, 19 Jul 2017

WHM/cPanel AutoSSL issue with Google Chrome (ERR_EMPTY_RESPONSE)

Today few clients complained about their websites not working in Google Chrome. It seems to be an issue caused by a recent EasyApache 4 update where cPanel included a newer version of OpenSSL to be used with EasyApache, and this version of OpenSSL included some code that uses SSE4.1 or SSE4.2 CPU features. The reason that this problem affects Chrome browsers is because it uses the POLY1305 cryptographic algorithm and this triggers the problem in OpenSSL on the server. Until EA-6544 is resolved, this issue can be prevented by removing C

design

HTML Minifier

Posted by Cătălin on Fri, 14 Jul 2017

HTML Minifier - Minify HTML and any CSS or JS included in your markup

This will do the magic: //start HTML Minifier function sanitize_output($html) { $search = array( '/\>[^\S ]+/s', // strip whitespaces after tags, except space '/[^\S ]+\

design

Compare tables find and update in MySQL

Posted by Cătălin on Thu, 22 Jun 2017

Compare two tables find and update only matching data in MySQL

Find: SELECT id, mailing FROM directory_list a JOIN email_temp b ON a.email=b.email; Update: UPDATE directory_list a JOIN email_temp b ON a.email=b.email SET mailing = concat(COALESCE(mailing, ''), ' --text--');

design

MySQL find duplicates

Posted by Cătălin on Tue, 13 Jun 2017

MySQL query to find duplicates and to select all but ignore duplicates

Find duplicates: SELECT email FROM directory_list GROUP BY email HAVING COUNT(email) >1; Select all but ignore duplicates: SELECT email FROM directory_list WHERE email LIKE '%@%' GROUP BY email ASC;

design

Enable GZIP Compression in WHM

Posted by Cătălin on Fri, 19 May 2017

How to add GZIP compression server-wide in cPanel WHM EasyApache3 or EasyApache4

In cPanel WHM EasyApache3 or EasyApache4, you can add GZIP compression server-wide, including new accounts, by adding the following to Service Configuration → Apache Configuration → Include Editor → Pre Virtualhost Include → All Versions: # Enable GZIP Compression. <IfModule mod_deflate.c> SetOutputFilter DEFLATE <IfModule mod_setenvif.c> BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html # Don

design

Image blur filter

Posted by Cătălin on Wed, 22 Mar 2017

How to apply a Gaussian blur to an image.

CSS The value of ‘radius’ defines the value of the standard deviation to the Gaussian function, or how many pixels on the screen blend into each other, so a larger value will create more blur. If no parameter is provided, then a value 0 is used. The parameter is specified as a CSS length, but does not accept percentage values. .img_blur { -webkit-filter: blur(18px); filter: blur(18px); } Demo codepen.io PHP Imagick::adaptiveBlurImage Adds an adaptive blur filter to image. The intensity of an adaptive blur depends is

design

Encrypt files on OS X

Posted by Cătălin on Thu, 9 Mar 2017

Encrypt any files on OS X with openssl

Encrypt openssl enc -aes-256-cbc -e -in /Users/name/Desktop/file.pdf -out /Users/name/Desktop/file_encrypted.pdf Decrypt openssl enc -aes-256-cbc -d -in /Users/name/Desktop/file_encrypted.pdf -out /Users/name/Desktop/file_decrypted.pdf

design

How to force HTTPS using the .htaccess file

Posted by Cătălin on Wed, 8 Feb 2017

How to force HTTPS using the .htaccess file using mod_rewrite.

RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] To force a specific domain to use HTTPS, use the following lines of code in the .htaccess file in your website's root folder: RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] If you want to force SSL on a specific URL (without www) helpful to avoid duplicate URLs in SEO RewriteCond %{HTTP_HOST} ^www.example.com RewriteRule

design

CentOS cleaning Yum cache

Posted by Cătălin on Wed, 8 Feb 2017

How to lean the cache of YUM on your CentOS?

yum clean packages Now remove any cached XML-based metadata yum clean metadata Remove any cached database files yum clean dbcache Following this you will want to clean all the files to confirm the preceding instructions and to ensure that unnecessary disk space is not used yum clean all Rebuild the Yum cache by typing yum makecache For CPanel or DNSOnly you can also remove manually all the Cpanel_* temp files rm -fv /home/*/tmp/Cpanel_* rm -fv /tmp/Cpanel_*

design

Useful library repository

Posted by Cătălin on Thu, 26 Jan 2017

Useful CDN Javascript and CSS library repository

CDNJS* is a library repository which hosted on cloudflare.com. It’s freely available CDN for common Javascript and CSS libraries. Currently there are 2756 libraries, check it out at: https://cdnjs.com/libraries/ * CDN stands for Content Delivery Network.

design

Encrypt sensitive data with PHP

Posted by Cătălin on Sat, 7 Jan 2017

Encrypt sensitive data with PHP and MySQL

Class created with construct now add methods to encrypt and decrypt: class Encryption { const CIPHER = MCRYPT_RIJNDAEL_128; // Rijndael-128 is AES const MODE = MCRYPT_MODE_CBC; private $key; public function __construct($key) { $this->key = $key; } public function encrypt($plaintext) { $ivSize = mcrypt_get_iv_size(self::CIPHER, self::MODE); //Gets the size of the IV belonging to a specific cipher/mode combination. $iv = mcrypt_create_iv($ivSize, MCRYPT_DEV_RANDOM); //Creates an

design

GST/HST calculator

Posted by Cătălin on Tue, 8 Nov 2016

GST/HST calculator to find out the amount of tax that applies to sales in Canada.

Province or territory SelectAlbertaBritish ColumbiaManitobaNew BrunswickNewfoundland and LabradorNorthwest TerritoriesNova ScotiaNunavutOntarioPrince Edward IslandQuebecSaskatchewanYukon Amount Amount entered is:        Before taxes       After taxes Calculate HST: = Fed. (%):  + Prov. (%):  GST (%):  PST (%):  QST (%):  Total before tax:  Total after tax:  Please enter a numeric value in the Amount fie

design

Script to Backup Mysql Databases

Posted by Cătălin on Mon, 31 Oct 2016

Shell Script to Backup Mysql Databases, you can keep as many versions as you like

Create a cron with this script to backup your databases: #!/bin/sh # List of databases to be backed up separated by space dblist="DATABASE1 DATABASE2 DATABASE3" # Directory for backups backupdir=/PATH/FOR/MYSQL/BACKUPS/gz # Number of versions to keep numversions=7 # Full path for MySQL hotcopy command (find location with: locate mysqldump) hotcopycmd="/usr/local/mysql/bin/mysqldump --user=YOUR-USER --password=YOUR-PASSWORD --lock-tables --lock-tables --databases" # Create directory if needed mkdir -p "$backupdir" if [ !

design

Archive with tar excluding certain files/folders

Posted by Cătălin on Wed, 26 Oct 2016

Here is how to run the tar command with the --exclude functionality

Here is how to run the tar command with the --exclude functionality tar -czvf backup.tar.gz /path/site.com --exclude='/path/site.com/uploads'

design

Find files containing specific text on Linux?

Posted by Cătălin on Mon, 24 Oct 2016

How to find all files containing specific text on Linux?

How to find all files containing specific text on Linux? grep -rnw '/path/to/folder/' -e "string"

design

Linux - How to fix “Read-only file system”?

Posted by Cătălin on Thu, 6 Oct 2016

Passion for DETAILS. Dedicated to QUALITY

# /etc/init.d/apache2 start Starting web server: apache2(30)Read-only file system: apache2: could not open error log file /var/log/apache2/error.log. Unable to open logs Action 'start' failed. The Apache error log may have more information. failed! Fix: sudo fsck.ext4 -f /dev/sda1

design

Resolving Finder Problems in OS X 10.9.5 - OS X

Posted by Cătălin on Mon, 29 Aug 2016

Resolving Finder Problems in OS X 10.9.5 - OS X

Open terminal and paste this line: rm ~/Library/Preferences/com.apple.finder.plist && killall -HUP Finder

design

Let's Encrypt plugin for cPanel/WHM

Posted by Cătălin on Wed, 20 Apr 2016

Let's Encrypt plugin for cPanel/WHM

This is a cPanel/WHM plugin for the Let's Encrypt client. This plugin uses Perl and the WHM API, and requires a server running cPanel and WHM on it. /usr/local/cpanel/3rdparty/bin/git clone https://github.com/Prajithp/letsencrypt-cpanel.git cd letsencrypt-cpanel ./install.sh More info here

design

Authentication with .htpasswd On Mac OS X

Posted by Cătălin on Mon, 1 Jun 2015

Authentication with .htpasswd On Mac OS X

Open Terminal and type: $ htpasswd -c /www/domain.com/.htpasswd yourusername After running the command it will ask for your password. Create a .htaccess file at the directory you want to protect, suppose /www/domain.com/.htaccess. With the following lines: AuthName "Login" AuthUserFile /www/domain.com/.htpasswd AuthGroupFile /dev/null AuthType Basic< LIMIT GET POST >require valid-user< /LIMIT >Now save .htaccess and try running the page, that's it!

design

Apache mod_rewrite

Posted by Cătălin on Wed, 27 May 2015

Apache mod_rewrite

How to redirect domain URL path to main domain: Force Non-www Domain Access RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.(([a-z0-9_]+\.)?example\.com)$ [NC] RewriteRule .? http://%1%{REQUEST_URI} [R=301,L] Force www Domain Access RewriteEngine on RewriteCond %{HTTP_HOST} ^([a-z.]+)?example\.com$ [NC] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule .? http://www.%1example.com%{REQUEST_URI} [R=301,L] Force file Domain Access RewriteEngine on RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ R

design

Remove IP from firewall

Posted by Cătălin on Mon, 4 May 2015

Remove IP from firewall

Check if IP is blocked by firewall: iptables -L -v -n | grep 1.2.3.4 Response: 7769 409K DROP all -- * * 1.2.3.4 0.0.0.0/0 Find chain with: iptables -L -n | less Remove IP: iptables -D fail2ban-sasl -s 1.2.3.4 -j DROP

design

How Uninstall Attracta in WHM

Posted by Cătălin on Tue, 28 Apr 2015

How Uninstall Attracta in WHM

You can run below script as root. It disables all traces of Attracta from the server. /usr/local/cpanel/3rdparty/attracta/scripts/uninstall-attracta

design

Secure connection failed in Webmin

Posted by Cătălin on Tue, 2 Dec 2014

Secure connection failed in Webmin

How to bypass the “secure connection failed” warning in Firefox 33 Firefox 33 no longer supports keys less than 1024 bits You can fix this right from Webmin if you: use another browser that lets you bypass this type of error or if you temporarily disable SSL in webmin by setting ssl=0 in /etc/webmin/miniserv.conf and restart webmin with /etc/init.d/webmin restart or login to the Webmin and select: Webmin -> Webmin Configuration -> SSL Encryption -> Self Signed Certificate Fill in the form (or leave the d

design

Find and remove IP blocked in Linux

Posted by Cătălin on Mon, 6 Oct 2014

Find and remove IP blocked in Linux

Find: iptables -L -n | grep 63.227.119.xx DROP all -- 63.227.119.xx 0.0.0.0/0 DROP all -- 63.227.119.xx 0.0.0.0/0 Remove iptables -D fail2ban-SSH -s 63.227.119.xx -j DROP

design

Hide or show content for devices in Bootstrap

Posted by Cătălin on Fri, 3 Oct 2014

Hide or show content for devices in Bootstrap

Using hidden <div class="hidden-sm hidden-md"> hidden-sm hidden-md </div> <div class="hidden-sm hidden-lg"> hidden-sm hidden-lg </div> <div class="hidden-md hidden-lg"> hidden-md hidden-lg </div> <div class="hidden-xs"> hidden-sm hidden-md hidden-lg </div> Equivalent using visible <div class="visible-lg"> hidden-sm hidden-md </div> <div class="visible-md"> hidden-sm hidden-lg </div> <div class="visible-sm"> hidden-md hidden-lg </div> <div class="visible-xs">

design

How To Check If Your Linux Is Vulnerable to Shellshock

Posted by Cătălin on Sat, 27 Sep 2014

How To Check If Your Linux Is Vulnerable to Shellshock

You can test your system by running this test command from Terminal: env x='() { :;}; echo vulnerable' bash -c 'echo hello' If you're not vulnerable, you'll get this result: bash: warning: x: ignoring function definition attempt bash: error importing function definition for `x' hello If you are vulnerable, you'll get: vulnerable hello You can also check the version of bash you're running by entering: bash --version

design

Terminal search files by text that the file names contain

Posted by Cătălin on Mon, 21 Jul 2014

Terminal search files by text that the file names contain

sudo find / -type f -name "*string*"

design

Finding a text string in Linux

Posted by Cătălin on Tue, 15 Jul 2014

Finding a text string in Linux

In this example, search for a string called "jquery-1.6.2" in all text (*.js) files located in "/home/user/public_html/" directory, use: $ grep "jquery-1.6.2" /home/user/public_html/*.js OR $ grep "jquery-1.6.2" ~/*.js Search all subdirectories recursively You can search for a text string all files under each directory, recursively with -R option: $ grep -R "jquery-1.6.2" /home/user/public_html/ Only display filenames By default, the grep command prints the matching lines. You can pass -H option to print the filen

design

How to count all the files recursively?

Posted by Cătălin on Mon, 23 Jun 2014

How to count all the files recursively?

How to count all the files recursively through directories in Linux: find -maxdepth 1 -type d | while read -r dir; do printf "%s:\t" "$dir"; find "$dir" -type f | wc -l; done

design

How to find IPs in the same network?

Posted by Cătălin on Mon, 24 Mar 2014

How to find IPs in the same network?

Open Terminal and type: arp -a it will list all the computers on the network and the host names.

design

Installing SSL Certificate on Apache with mod_ssl

Posted by Cătălin on Sun, 2 Feb 2014

Installing SSL Certificate on Apache with mod_ssl

Generate your certificate.csr and private.key with on Apache with mod_ssl cd /etc/ssl/domain.tld openssl genrsa -des3 -out private.key 4096 openssl req -new -key private.key -out certificate.csr Extract all of the contents of the ZIP file that was sent by your SSL provides to you and upload them to your server. The extracted contents will typically be named: yourDomainName.crt and yourDomainName.ca-bundle Move all of the certificate related files to their appropriate directories. Move the Private Key that was generate

design

Renew SSL certificate at StartSSL

Posted by Cătălin on Sun, 2 Feb 2014

Renew SSL certificate at StartSSL

In case you are approved for a certificate renewal here is how you do it: The web server SSL certificates from startssl is free for class 1 and needs to be renewed every year. Two weeks before SSL certificates expiration, you will receive an email notification. But you need to validate your email first as email validation only for 30 days. (Go to control panel in www.startssl.com, click Authenticate, click validations Wizard, and click email validation). You may also need to renew S/MIME authenticate certificate, which is

design

How to burn ISO image on Mac?

Posted by Cătălin on Wed, 22 Jan 2014

How to burn ISO image on Mac?

To burn ISO image on Mac is very easy. Open your Terminal and type: hdiutil burn /Users/path/xxx.iso Instead of typing the path you can also drag and drop the ISO file into terminal and press enter. That's it! Preparing data for burn Opening session Opening track Writing track ..........

design

Unblock IP from Fail2Ban

Posted by Cătălin on Fri, 17 Jan 2014

Unblock IP from Fail2Ban

Search for IP 192.168.1.1 to see its been blocked by firewall iptables -L -n | grep 192.168.1.1 DROP all -- 192.168.1.1 0.0.0.0/0 Remove 192.168.1.1 iptables -D fail2ban-sasl -s 192.168.1.1 -j DROP

design

Remove specific directories at once in Linux

Posted by Cătălin on Tue, 10 Dec 2013

Remove specific directories at once in Linux

find specific folder, ex: "_notes" find /home/www -name "_notes" delete all folders "_names" find /home/www/ -name '_notes' -print0 | xargs -0 rm -rf

design

Backup MySQL with cron

Posted by Cătălin on Tue, 10 Dec 2013

Backup MySQL with cron

#!/bin/sh # List of databases to be backed up separated by space dblist="database1 database2 mysql information_schema" # Directory for backups backupdir=/Users/username/Documents/backups/mysql/gz # Number of versions to keep numversions=6 # Full path for MySQL hotcopy command Please put credentials into /root/.my.cnf hotcopycmd="/Applications/XAMPP/xamppfiles/bin/mysqldump --lock-tables --databases" # Create directory if needed mkdir -p "$backupdir" if [ ! -d "$backupdir" ]; then echo "Invalid directory: $backupdir"

design

Vacation plugin issue with Roundcube 0.95

Posted by Cătălin on Wed, 23 Oct 2013

Vacation plugin issue with Roundcube 0.95

Vacation plugin not compatible with Roundcube 0.95, due to changes in the way roundcube access database. To fix this, replace: $db = new rcube_mdb2($dsn, '', FALSE); with: if (!class_exists('rcube_db')) { $db = new rcube_mdb2($dsn, '', FALSE); } else { $db = rcube_db::factory($dsn, '', FALSE); } in /plugins/vacation/lib/drivers/sql.php lines 34 and 173

design

.htaccess redirect

Posted by Cătălin on Mon, 7 Oct 2013

.htaccess redirect

Your website can be accessed with www.domain.com and domain.com. Since Google penalizes this due to duplicated content reasons, you have to stick your domain to either www.domain.com or domain.com. You can fix this easily with .htaccess: Apache .htaccess redirect Ex: to redirect all traffic from http://domain.com to http://www.domain.com RewriteEngine on RewriteCond %{HTTP_HOST} !^www\.domain\.com RewriteRule (.*) http://www.domain.com/$1 [R=301,L] To redirect http://www.domain.com/index.php to http://www.domain.com Rewrite

design

Capture hostname and uri using tshark

Posted by Cătălin on Tue, 24 Sep 2013

Capture hostname and uri using tshark

Web traffic (port 80): tshark -i eth0 -f 'port 80' -l -t ad -n -R 'http.request' -T fields -e http.host -e http.request.uri -e ip.src

design

Linux Find Large Files

Posted by Cătălin on Tue, 24 Sep 2013

You can easily list all large files along with size, by using the following syntax

You can easily list all large files along with size, by using the following syntax: Search or find big files Linux (50MB) in current directory, enter: $ find . -type f -size +50000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }' Search in my /var/log directory: # find /var/log -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

design

Mount USB flash in Linux

Posted by Cătălin on Mon, 15 Jul 2013

Mount USB flash in Linux

Detecting USB flash: # fdisk -l Creating mount point: mkdir /mnt/usbflash Mount USB flash: mount /dev/sdb1 /mnt/usbflash

design

Temporarily stopping the X server

Posted by Cătălin on Wed, 10 Jul 2013

Temporarily stopping the X server

Close the graphical session by selecting “System -> Logout” in the top menu. Press Ctrl+Alt+F1 This shuts down the X server, and we land in an alphanumerical window. However, the windows manager is still running at this point. Login as root and run the command “/etc/init.d/gdm3 stop” (you may need to replace “gdm3″ with the actual name of the script corresponding to the windows manager installed in your system: “gdm”, “kdm”, xdm”,etc…) Start again the X server To start again the X server and the wind

design

Largest top files on Linux

Posted by Cătălin on Thu, 27 Jun 2013

Largest top files on Linux

How do you find the largest top files and directories on a Linux? du -sh * Specific folder: du -a /var | sort -n -r | head -n 20

design

mySQL password (Mac OS X Lion)

Posted by Cătălin on Fri, 22 Mar 2013

mySQL password (Mac OS X Lion)

Setup root password for MySQL: /usr/local/mysql/bin/mysqladmin -u root -p password

design

Leverage browser caching

Posted by Cătălin on Wed, 27 Feb 2013

Leverage browser caching

How to add Expires headers <IfModule mod_expires.c>ExpiresActive On ExpiresDefault "access plus 1 month" ExpiresByType image/x-icon "access plus 1 year” # Images ExpiresByType image/gif "access plus 1 month" ExpiresByType image/png "access plus 1 month" ExpiresByType image/jpg "access plus 1 month" ExpiresByType image/jpeg "access plus 1 month" # CSS ExpiresByType text/css "access 1 month” # Javascript ExpiresByType text/javascript "access plus 1 week" ExpiresByType application/x-javascript "access

design

Apache Error

Posted by Cătălin on Sat, 16 Feb 2013

Apache Error

Fix for "Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName" Error sudo /etc/init.d/apache2 restart Reloading web server config: apache2apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName To fix this problem, you need to edit the httpd.conf file. Open your terminal and type: sudo gedit /etc/apache2/httpd.conf Add the following line to httpd.conf: ServerName localhost Save the file and restart the server: sudo

design

GPG error for Debian

Posted by Cătălin on Sun, 10 Feb 2013

GPG error for Debian

Problem When updating the Debian based system, apt-get may display an error message like: W: GPG error: http://download.webmin.com sarge Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY D97A3AE911F63C51 Solution Type the following commands: gpg --keyserver pgpkeys.mit.edu --recv-key D97A3AE911F63C51 gpg -a --export D97A3AE911F63C51 | sudo apt-key add -

design

.ca whois response

Posted by Cătălin on Sun, 20 Jan 2013

.ca whois response

The CIRA whois response don't contain 'AVAIL' any longer, all available domain name for registration will contain: 'Domain Status: available' Please note that you need to add 9 spaces between the colon of 'status:' and the word 'available' whois.cira.ca|Domain status: available

design

Mounting an NTFS drive in Debian

Posted by Cătălin on Sun, 2 Dec 2012

Mounting an NTFS drive in Debian

# apt-get install libfuse2 # apt-get install ntfs-3g # fdisk -l | grep NTFS sample: /dev/sdb1 1 121601 976760001 7 HPFS/NTFS # mkdir /media/YOUR-FOLDER # mount -t ntfs-3g /dev/sdb1 /media/YOUR-FOLDER To auto mount it whenever the system starts, modify the file fstab located in etc in your text editor of choice. Be careful! If you damage this file it will not boot. # vi /etc/fstab and add the line /dev/sdb1 /media/YOUR-FOLDER ntfs-3g defaults 0 0 Save this, and now every time you boot your machine yo

design