27 Feb 2015
Apache’s handy mod_rewrite
module is helping to correct this unfortunate human typos.
At first let’s check whether the Apache’s mod_rewrite
is enabled.
# a2enmod rewrite
Module rewrite already enabled
If it was not, then reload configuration
# service apache2 reload
* Reloading web server config apache2 [OK]
to assure that the rewrite will work you need to assure the one more thing, it is AllowOverride
option in the VirtualHost
configuration
<VirtualHost *:80>
...
<Directory /var/www/example.com/htdocs>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
....
</VirtualHost>
Now put the following snippet into .htaccess
located in the folder of your website (/var/www/example.com/htdocs
)
RewriteEngine On
# remove trailing slash
RewriteCond %{HTTPS} off
RewriteRule ^(.+[^/])/$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteRule ^(.+[^/])/$ https://%{HTTP_HOST}/$1 [R=301,L]
That’s it, happy re-writing!
27 Feb 2015
The follwoing will encode your string to HTML
entities
jQuery('<div />').text('Some text with <div>html</div>').html()
and the output will look like
"Some text with <div>html</div>"
To decode we just switch methods
jQuery('<div />').html('Some text with <div>html</div>').text()
produces
"Some text with <div>html</div>"
The jQuery magic!
24 Feb 2015
Delete recursively the .svn
directories
$ rm -rf `find . -type d -name .svn`
Find files not under the version control
$ svn status | grep -e ^?
How to remove all deleted files from repository
$ svn st | grep '^!' | awk '{print $2}' | xargs svn delete --force
grep
on folder with excluding of .svn
dirs
$ grep -r 'content_graphic' assets/js --exclude=*\.svn*
17 Feb 2015
Search across all databases (schemas) for tables without primary key
The following query obtains the list of tables without primary key, those who destroys the database performance
SELECT
t.TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES AS t
LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS k
ON (
t.TABLE_NAME = k.TABLE_NAME
AND k.CONSTRAINT_SCHEMA = t.TABLE_SCHEMA
AND k.constraint_name = 'PRIMARY'
)
WHERE
t.TABLE_SCHEMA NOT IN ('information_schema', 'performance_schema', 'mysql', 'sys')
AND k.constraint_name IS NULL;
In this example, the INFORMATION_SCHEMA.TABLES
table is used to find all t. The TABLE_NAME
column is selected, and the WHERE
clause is used to filter system related databases.
LEFT JOIN
is used to join with table KEY_COLUMN_USAGE
and filter the tables that do not have a primary key.
Restrict search for tables without primary key to a specific databases (schema)
SELECT
t.TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES AS t
LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS k
ON (
t.TABLE_NAME = k.TABLE_NAME
AND k.CONSTRAINT_SCHEMA = t.TABLE_SCHEMA
AND k.constraint_name = 'PRIMARY'
)
WHERE
t.TABLE_SCHEMA NOT IN ('information_schema', 'performance_schema', 'mysql', 'sys')
AND t.TABLE_SCHEMA = '<database name>' -- put database name here
AND k.constraint_name IS NULL;
A friendly advise, the result list of these queries should be an Empty set
.
Happy querying!
17 Feb 2015
Hope this tip will save to someone time for fun coding, if you suddenly get this error while installing the RMagick gem on linux
$ sudo gem install rmagick
Building native extensions. This could take a while...
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.
Can't install RMagick 2.13.4. Can't find Magick-config
That means the devel package is not installed, so you pick it up on Ubuntu > 12.04 with this command
$ sudo apt-get install libmagick++-dev
and voilà
$ sudo gem install rmagick
Building native extensions. This could take a while...
Please report any bugs. See https://github.com/gemhome/rmagick/compare/RMagick_2-13-2...master and https://github.com/rmagick/rmagick/issues/18
Successfully installed rmagick-2.13.4
Parsing documentation for rmagick-2.13.4
Installing ri documentation for rmagick-2.13.4
Done installing documentation for rmagick after 7 seconds
1 gem installed
checkout if everything is OK
$ dpkg -l | grep imagemagick
ii imagemagick 8:6.7.7.10+dfsg-4ubuntu1 amd64 image manipulation programs
ii imagemagick-common 8:6.7.7.10+dfsg-4ubuntu1 all image manipulation programs -- infrastructure
$ gem list | grep rmagick
rmagick (2.13.4)