<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FSW</title>
	<atom:link href="http://wawrzak.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://wawrzak.com</link>
	<description>Just another L3K Blogs site</description>
	<lastBuildDate>Sun, 16 Oct 2011 12:27:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>5 minutes website desaturation using single PHP script and mod_rewrite</title>
		<link>http://wawrzak.com/5-minutes-website-desaturation-using-single-php-script-and-mod_rewrite/</link>
		<comments>http://wawrzak.com/5-minutes-website-desaturation-using-single-php-script-and-mod_rewrite/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 16:31:57 +0000</pubDate>
		<dc:creator>fsw</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://fsw.blog.l3k.org/?p=83</guid>
		<description><![CDATA[Recently I&#8217;ve challenged a task of creating a &#8220;Grieving&#8221; version of a ready website. It was supposed to have a switch in the CMS to turn the &#8220;grieve&#8221; on/off. First idea was to use some javascript library. But everything I found was either faulty and/or killing the client browser. Most obvious way to do this [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve challenged a task of creating a &#8220;Grieving&#8221; version of a ready website. It was supposed to have a switch in the CMS to turn the &#8220;grieve&#8221; on/off.</p>
<p><span id="more-83"></span></p>
<p>First idea was to use some javascript library. But everything I found was either faulty and/or killing the client browser.</p>
<p>Most obvious way to do this on the server side would be to create black and white version of all images and &#8220;desaturated&#8221; css files to use when the grieve is on. The disadvantage of this solution is it would require to edit all templates and would be non re-usable at all.</p>
<p>The idea we got was to create a simple php script that would be able to process all css files and images on the server side without even touching the site backend / framework / templates etc. It is not the best solution but it is really quick to implement so maybe someone would find it useful.</p>
<h3>Pre requirements:</h3>
<ul>
<li>your templates and/or HTML files are not using colours in inline CSS</li>
<li>your images and CSS files are regular files served by apache.</li>
<li>performance is not your highest priority. ( script is able to cache desaturated images but still needs some resources to process new ones as it does so pixel by pixel with libGD. And even with all files cached apache needs to invoke php for every image/css request so with large number of files and requests this can add some extra load to your web server. )</li>
</ul>
<h3>Concept:</h3>
<ul>
<li>all CSS files and images are rewrited to &#8220;desaturate.php?file=path&#8221; script with .htaccess</li>
<li>desaturate.php is using regular expressions to desaturate styles and libGD to desaturate images and outputs them</li>
</ul>
<h3>Installation (can be also found in desaturate.php):</h3>
<ul>
<li>Place desatureate.php on your web server.</li>
<li>Add following rewrite rules to your .htaccess</li>
</ul>
<pre>RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)\.(jpeg|jpg|gif|bmp|png|css)$ desaturate.php?type=$2&amp;file=$1.$2 [L]</pre>
<ul>
<li>(optional but recommended) edit desaturate.php and point CACHE_DIR constant to writeable directory</li>
<li>(optional) If you dont want to edit .htaccess to enable/disable desaturation each time you can edit desaturate.php and make DESATURATE constant be read from a database or so.</li>
</ul>
<h3>Client cache problem</h3>
<p>urls to CSSes and images are not changing so if the client previously visited non-desaturated site he might see files cached by his browser and will have to reload the page to see it fully desaturated. If this is a problem for you the only solution I can think of would be to add &#8220;?desaturated&#8221; and &#8220;?notdesaturated&#8221; to urls in your templates.</p>
<h3>Download:</h3>
<p>Here is a git repo with this thing:</p>
<p><a href="https://github.com/fsw/desaturate.php">https://github.com/fsw/desaturate.php</a></p>
<p>credit goes to my mate vent for helping with the concept</p>
]]></content:encoded>
			<wfw:commentRss>http://wawrzak.com/5-minutes-website-desaturation-using-single-php-script-and-mod_rewrite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weather thingie with jQuery, PHP and secret Google API</title>
		<link>http://wawrzak.com/weather-thingie-with-jquery-php-and-secret-google-api/</link>
		<comments>http://wawrzak.com/weather-thingie-with-jquery-php-and-secret-google-api/#comments</comments>
		<pubDate>Sat, 18 Sep 2010 12:09:10 +0000</pubDate>
		<dc:creator>fsw</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://wawrzak.com/blog/?p=4</guid>
		<description><![CDATA[download all files: I challenged a task of creating a weather forecast on a website. After researching few weather APIs I decided that Google&#8217;s is best for my needs. Others are either non-free or too complicated. Google&#8217;s Weather API was created for iGoogle. It is very simple and clear however it&#8217;s usage is risky as [...]]]></description>
			<content:encoded><![CDATA[<p>download all files:</p>
Note: There is a file embedded within this post, please visit this post to download the file.
<p>I challenged a task of creating a weather forecast on a website. After researching few weather APIs I decided that Google&#8217;s is best for my needs. Others are either non-free or too complicated.</p>
<p><span id="more-9"></span></p>
<p>Google&#8217;s Weather API was created for iGoogle. It is very simple and clear however it&#8217;s usage is risky as it is not supported and not documented anywhere. You can read more <a href="http://dennisdel.com/?p=99">here</a>.</p>
<p>It is easy to find some <a href="http://www.dynamicguru.com/php/weather-forecast-script-in-php-using-google-weather-api/">PHP/CURL usage examples</a>. This was not satisfying for me as weather forecast on website I was working on was supposed to be just a tiny, optional addition working in the background and risking CURL delays with this unsupported API was unacceptable.</p>
<p>Getting data from other domains is outside the AJAX concept and most browsers are blocking such requests for security reasons. Best way to avoid this is to create a simple PHP proxy on our web server. If your web service will use finite set of locations to check weather in, you can extend this proxy easily to buffer the results in a database.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

/**
Simple CURL Proxy for google weather service to be used with AJAX
**/

// secret Google API params
$weather = (@$_GET['weather']?$_GET['weather']:'New York');
$hl = (@$_GET['hl']?$_GET['hl']:'en');

$session = curl_init('http://www.google.com/ig/api?weather='.urlencode($weather).'&amp;hl='.urlencode($hl));

//we will need header to convert encoding
curl_setopt( $session, CURLOPT_HEADER, true );
curl_setopt( $session, CURLOPT_RETURNTRANSFER, true );

$response = curl_exec($session);
$curl_info = curl_getinfo($session);

// split response into header and content
$headers_size = $curl_info[header_size];
$headers = substr($response, 0, $headers_size);
$content = substr($response, $headers_size);

// search for encoding in headers
$e_start = strpos( $headers, &quot;charset=&quot; );
$e_end = strpos( $headers, &quot;\n&quot;, $e_start + 1 );
$encoding = substr( $headers, $e_start+8, $e_end-$e_start-9 );

// we convert encoding to UTF8 to avoid problems in javascript
header('Content-Type: text/xml; charset=UTF-8');
echo mb_convert_encoding( $content, 'UTF-8', $encoding );

curl_close( $session );

?&gt;
</pre>
<p>Simple JavaScript function will use our proxy and add formatted results to HTML element.</p>
<pre class="brush: jscript; title: ; notranslate">
/*

Shows weather forecast in element.
Requires gwproxy.php to be present on webserver
container is a jQuery element or selector
locale and location are strings.
location could be whatever google accepts like
'New York' or ',,,22500000,31000000' to get weather for lat=22.5 and long=31

*/

function showWeather(container,location,locale){

        $(container).text('Please wait. Loading weather...');

        $.get( 'gwproxy.php?weather=' + encodeURI(location) + '&amp;hl='+encodeURI(locale), function(xml) {

                function addForecastDiv( day, condition, temp, icon ){

                        daydiv = $(&quot;&lt;div class='day'&gt;&lt;/div&gt;&quot;);
                        daydiv.append( &quot;&lt;img src='&quot; + icon + &quot;' /&gt;&quot; );
                        daydiv.append( &quot;&lt;div class='name'&gt;&quot; + day + &quot;&lt;/div&gt;&quot; );
                        daydiv.append( &quot;&lt;p class='condition'&gt;&quot; + condition + &quot;&lt;/p&gt;&quot; );
                        daydiv.append( &quot;&lt;p class='temp'&gt;&quot; + temp + &quot;&lt;/p&gt;&quot;);
                        $(container).append(daydiv);

                }

                $(container).text('');

                var t_unit = '&amp;deg;F';

                if( $(xml).find('forecast_information').find('unit_system').attr('data') == 'SI' )
                        t_unit = '&amp;deg;C';

                addForecastDiv(
                        'Now',
                        $(xml).find('current_conditions').find('condition').attr('data') + '&lt;br/&gt;' +
                        $(xml).find('current_conditions').find('humidity').attr('data') + '&lt;br/&gt;' +
                        $(xml).find('current_conditions').find('wind_condition').attr('data'),
                        $(xml).find('current_conditions').find('temp_f').attr('data') + '&amp;deg;F, ' +
                        $(xml).find('current_conditions').find('temp_c').attr('data') + '&amp;deg;C',
                        $(xml).find('current_conditions').find('icon').attr('data')
                );

                $(xml).find('forecast_conditions').each(function(){
                        addForecastDiv(
                                $(this).find('day_of_week').attr('data'),
                                $(this).find('condition').attr('data'),
                                $(this).find('low').attr('data') + t_unit + ' - ' +
                                $(this).find('high').attr('data') + t_unit,
                                $(this).find('icon').attr('data')
                        );
                });

        },'xml');

}
</pre>
<p>CSS for the element. Sorry it is ugly. Modify for your needs.</p>
<pre class="brush: css; title: ; notranslate">
div#weatherdisplay {
        overflow: auto;
        padding: 10px;
        margin: 10px;
        background: #ccc;
}

div#weatherdisplay div.day {
        font-family: Verdana;
        float: left;
        border: 1px dashed #777;
        background: #bbf;
        width: 150px;
        margin: 5px;
        padding: 5px;
}

div#weatherdisplay img {
        float: left;
        height: 32px;
}

div#weatherdisplay div.name {
        font-weight: bold;
        height: 24px;
        padding: 4px 4px 4px 40px;
}

div#weatherdisplay .condition {
        font-size: 12px;
        padding: 0;
        margin: 5px 0;
        text-align: center;
        height: 58px;
        overflow: hidden;
}

div#weatherdisplay .temp {
        padding: 0;
        margin: 0;
        text-align: center;
}
</pre>
<p>Complete HTML with usage example.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;html&gt;
&lt;head&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;http://code.jquery.com/jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;weather.js&quot;&gt;&lt;/script&gt;

&lt;script type='text/javascript'&gt;

$(document).ready( function() {
        showWeather($('#weatherdisplay'),'Paris','fr');
} );

&lt;/script&gt;

&lt;link rel='stylesheet' href='weather.css' type='text/css' /&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;h1&gt;Weather API Test&lt;/h1&gt;

&lt;div&gt;
location: &lt;input id='weather' type='edit' name='weather' value='Paris' /&gt;
language: &lt;input id='hl' type='edit' name='hl' value='fr' /&gt;
&lt;input type='button' value='check weather' name='submit'
onClick=&quot;showWeather($('#weatherdisplay'),$('#weather').val(),$('#hl').val())&quot; /&gt;
&lt;/div&gt;

&lt;div id='weatherdisplay'&gt;&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>And this is how it should look like:</p>
<div id="attachment_77" class="wp-caption alignnone" style="width: 947px"><a href="http://wawrzak.com/files/2010/09/screenshot1.jpeg"><img class="size-full wp-image-77" src="http://wawrzak.com/files/2010/09/screenshot1.jpeg" alt="" width="937" height="260" /></a><p class="wp-caption-text">weather thingie screenshot</p></div>
<p>download all files:</p>
Note: There is a file embedded within this post, please visit this post to download the file.
]]></content:encoded>
			<wfw:commentRss>http://wawrzak.com/weather-thingie-with-jquery-php-and-secret-google-api/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

