Thursday, November 23, 2017

Apache - Enable gzip compression with .htaccess

Today I found a simple method to enable gzip compression on your homepage, when you are using Apache webserver. You just have to create a .htaccess file with this code, assuming you have mod_deflate enabled in your Apache config.


<IfModule mod_deflate.c>
<FilesMatch "\\.(js|css|html|xml|jpg|png)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>

This code snippet provides gzip compression for all js, css, html, xml, jpg and png files.
Ok. Images are most time already compressed, but I added them as well.
Very simple and very useful. :-)

Thursday, November 16, 2017

SQL - Use PARSENAME function to extract individual parts from a string

Today I discovered a very cool feature in T-SQL from Microsoft SQL Server.
It happens (unfortunately) again and again that several records are written in a single column and one is forced to extract individual parts from it. So far, I have always written a SQL function of my own, but this is will be history from now on with the help of the PARSENAME function. :-)

See this examples. I think, this explains it very well:

DECLARE @exampleString nvarchar(max) = 'Test;Test1;Test2' 
SELECT PARSENAME(REPLACE(@exampleString,';','.'),1)

--Result: Test2

SELECT PARSENAME(REPLACE(@exampleString,';','.'),2)

--Result: Test1

SELECT PARSENAME(REPLACE(@exampleString,';','.'),3)

--Result: Test