<?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>BOHUCO.NET &#187; javascript</title>
	<atom:link href="http://bohuco.net/blog/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://bohuco.net/blog</link>
	<description>Die Sollbruchstelle des Internets.</description>
	<lastBuildDate>Mon, 30 Apr 2012 10:30:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Javascript MindFuck: Google Maps GeoCoder Callback with Parameters</title>
		<link>http://bohuco.net/blog/2012/04/javascript-mindfuck-google-maps-geocoder-callback-with-parameters/</link>
		<comments>http://bohuco.net/blog/2012/04/javascript-mindfuck-google-maps-geocoder-callback-with-parameters/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 10:29:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[geocoding]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://bohuco.net/blog/?p=1858</guid>
		<description><![CDATA[If you have ever tried to geocode with google maps you have perhaps noticed that you can&#8217;t easy pass more data to the callback function. And geocoding on an array of addresses won&#8217;t work too, because you get always the result for the last entry of your array. To solve that issues you must encapsulate [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever tried to geocode with google maps you have perhaps noticed that you can&#8217;t easy pass more data to the callback function. And geocoding on an array of addresses won&#8217;t work too, because you get always the result for the last entry of your array.</p>
<p><span id="more-1858"></span></p>
<p>To solve that issues you must encapsulate your callback into another anonymous function (closure) that returns itself to the callback.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> locations <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
locations.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>address<span style="color: #339933;">:</span><span style="color: #3366CC;">'hauptplatz 1, 4020 linz, austria'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'otherInfo'</span><span style="color: #339933;">=&gt;</span><span style="color: #3366CC;">'info'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>idx <span style="color: #000066; font-weight: bold;">in</span> locations<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> location <span style="color: #339933;">=</span> locations<span style="color: #009900;">&#91;</span>idx<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> address <span style="color: #339933;">=</span> location<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'address'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    geocoder.<span style="color: #660066;">geocode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'address'</span><span style="color: #339933;">:</span>address<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>location<span style="color: #339933;">,</span> idx<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>results<span style="color: #339933;">,</span> <span style="color: #000066;">status</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">status</span> <span style="color: #339933;">==</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">GeocoderStatus</span>.<span style="color: #660066;">OK</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #003366; font-weight: bold;">var</span> latlng <span style="color: #339933;">=</span> results<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">geometry</span>.<span style="color: #660066;">location</span><span style="color: #339933;">;</span>
&nbsp;
                console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>location<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>idx<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span>location<span style="color: #339933;">,</span> idx<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://bohuco.net/blog/2012/04/javascript-mindfuck-google-maps-geocoder-callback-with-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP5 WebSocket Example &#8211; A Simple Chat</title>
		<link>http://bohuco.net/blog/2011/01/php5-websocket-example-a-simple-chat/</link>
		<comments>http://bohuco.net/blog/2011/01/php5-websocket-example-a-simple-chat/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 08:08:21 +0000</pubDate>
		<dc:creator>DerFichtl</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[chat]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Websockets]]></category>

		<guid isPermaLink="false">http://bohuco.net/blog/?p=1672</guid>
		<description><![CDATA[The classic example for websockets is a chat. This chat example has only 200 lines of code (excl. the Websocket class), is really easy to understand and customizable. The WebSocket class takes a function (or class method) as callback for every socket action, for this example i use the process method of the WebsocketChat Class: [...]]]></description>
			<content:encoded><![CDATA[<p>The classic example for websockets is a chat. This chat example has only 200 lines of code (excl. the Websocket class), is really easy to understand and customizable.</p>
<p><span id="more-1672"></span></p>
<p>The WebSocket class takes a function (or class method) as callback for every socket action, for this example i use the process method of the WebsocketChat Class:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000088;">$chat</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WebsocketChat<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// new WebSocketServer( socket address, socket port, callback function )</span>
<span style="color: #000088;">$webSocket</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WebSocketServer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;84.38.67.247&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8081</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chat</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'process'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$webSocket</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The WebsocketChat Class handles user actions and messages. We have two actions: &#8216;login&#8217; and &#8216;chat&#8217;. &#8216;login&#8217; happens when a new user sets his username, &#8216;chat&#8217; is always when a user sends a new message:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">Class</span> WebsocketChat <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * @var array
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$messages</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> process<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$msg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$server</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$msg</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$msg</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$msg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'login'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$msg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'chat'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>On the client-side we have to send the right actions if someone clicks &#8216;login&#8217; or &#8216;send message&#8217;.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#chat'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	evt.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	send<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'action'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'chat'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'text'</span><span style="color: #339933;">:</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'[name=text]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#login'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	evt.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	send<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'action'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'login'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'username'</span><span style="color: #339933;">:</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'[name=username]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#chat'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#login'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The login action adds a new chat user to the user-array and loads the last five messages for this new user.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$msg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'login'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">filter_var</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$msg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span><span style="color: #339933;">,</span> FILTER_SANITIZE_STRING<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$max</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">messages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$max</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">messages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// on login send last five chat messages</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">messages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #000088;">$max</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span>count<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">messages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">messages</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If the &#8216;chat&#8217; action is called then add a new WebsocketChatMessage to the message array and send it to all current chat-users:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$msg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">action</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'chat'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">filter_var</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$msg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">text</span><span style="color: #339933;">,</span> FILTER_SANITIZE_STRING<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	<span style="color: #000088;">$lastMessage</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WebsocketChatMessage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">messages</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$lastMessage</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUsers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">socket</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$lastMessage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>			
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The WebsocketChatMessage is just a container-class for holding the message data:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">Class</span> WebsocketChatMessage <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$timestamp</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$timestamp</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">text</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$username</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timestamp</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$timestamp</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%s %s: %s'</span><span style="color: #339933;">,</span> <span style="color: #990000;">strftime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%H:%M'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">timestamp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><a href="http://bohuco.net/labs/php-websocket-chat/">View Chat Example</a> on <a href="http://bohuco.net/labs/">BOHUCO Labs</a></p>
<p><a href="http://bohuco.net/labs/php-websocket-chat/?source=server.php">View server.php Code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bohuco.net/blog/2011/01/php5-websocket-example-a-simple-chat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Array Case-insensitive Sorting</title>
		<link>http://bohuco.net/blog/2010/10/javascript-array-case-insensitive-sorting/</link>
		<comments>http://bohuco.net/blog/2010/10/javascript-array-case-insensitive-sorting/#comments</comments>
		<pubDate>Thu, 28 Oct 2010 15:25:30 +0000</pubDate>
		<dc:creator>DerFichtl</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://bohuco.net/blog/?p=1632</guid>
		<description><![CDATA[easy if you know how &#8230; &#160; myarray.sort&#40;function&#40;a, b&#41;&#123; return a.toLowerCase&#40;&#41; &#62; b.toLowerCase&#40;&#41;; &#125;&#41;;]]></description>
			<content:encoded><![CDATA[<p>easy if you know how &#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
myarray.<span style="color: #660066;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> a.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> b.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://bohuco.net/blog/2010/10/javascript-array-case-insensitive-sorting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Google Closure Compiler Local with PHP</title>
		<link>http://bohuco.net/blog/2010/09/use-google-closure-compiler-local-with-php/</link>
		<comments>http://bohuco.net/blog/2010/09/use-google-closure-compiler-local-with-php/#comments</comments>
		<pubDate>Sat, 11 Sep 2010 17:42:33 +0000</pubDate>
		<dc:creator>DerFichtl</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Web Entwicklung]]></category>
		<category><![CDATA[closure]]></category>
		<category><![CDATA[closure compiler]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://bohuco.net/blog/?p=1581</guid>
		<description><![CDATA[In &#8220;Google Closure Compiler with PHP&#8221; i described how you can use the compiler online via http. Now i will show how you do it local on your server with the java command line application &#8230; First download and unpack the Closure java application to your computer or your server, the download url is: http://closure-compiler.googlecode.com/files/compiler-latest.zip [...]]]></description>
			<content:encoded><![CDATA[<p>In &#8220;<a href="http://bohuco.net/blog/2009/11/google-closure-compiler-with-php/">Google Closure Compiler with PHP</a>&#8221; i described how you can use the compiler online via http. Now i will show how you do it local on your server with the java command line application &#8230;</p>
<p><span id="more-1581"></span></p>
<p>First download and unpack the Closure java application to your computer or your server, the download url is:<br />
<a href="http://closure-compiler.googlecode.com/files/compiler-latest.zip">http://closure-compiler.googlecode.com/files/compiler-latest.zip</a></p>
<p>On linux servers you can do the download with wget:</p>
<pre>wget http://closure-compiler.googlecode.com/files/compiler-latest.zip
unzip compiler-latest.zip</pre>
<p>After unpacking u get a file named compiler.jar, that&#8217;s the application, you can execute it only if you have java installed. If not, see the help page for <a href="http://wiki.debian.org/Java">installing java on debian servers</a>.</p>
<pre>java -jar compiler.jar --js hello.js --js_output_file hello-compiled.js</pre>
<p><a href="http://bohuco.net/blog/wp-content/uploads/2010/09/Bildschirmfoto-2010-09-11-um-19.29.00.png"><img src="http://bohuco.net/blog/wp-content/uploads/2010/09/Bildschirmfoto-2010-09-11-um-19.29.00.png" alt="" title="google closure compiler folder" width="278" height="120" class="alignright size-full wp-image-1594" /></a></p>
<p>The command above compiles a hello.js in the current working directory to hello-compiled.js with the default settings. For more infos you can show a help screen with:</p>
<pre>java -jar compiler.jar --help</pre>
<p>Usually you want compile your whole scripts directory. My script reads all files of a given directory, checks if the file is a .js and compiles it to another directory:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000088;">$basePath</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$scriptDir</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$basePath</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/scripts/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$compiledDir</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$basePath</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/compiled/'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$scriptDir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$dh</span> <span style="color: #339933;">=</span> <span style="color: #990000;">opendir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$scriptDir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">readdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dh</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        	<span style="color: #666666; font-style: italic;">// read all files, if file is js and not minified then minify/compile it</span>
        	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.js'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.min.js'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	
&nbsp;
        		<span style="color: #000088;">$compilerCommand</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/usr/bin/java -jar %s/compiler.jar --js %s --js_output_file %s'</span><span style="color: #339933;">,</span>
					<span style="color: #000088;">$basePath</span><span style="color: #339933;">,</span> <span style="color: #000088;">$scriptDir</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$compiledDir</span><span style="color: #339933;">.</span><span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.js'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.min.js'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #990000;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$compilerCommand</span><span style="color: #339933;">,</span> <span style="color: #000088;">$return</span><span style="color: #339933;">,</span> <span style="color: #000088;">$code</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$code</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Fuck! Something went wrong: <span style="color: #009933; font-weight: bold;">%s</span> (<span style="color: #009933; font-weight: bold;">%s</span>)&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$return</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$code</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">%s</span> compiled successfully.&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
        	<span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
        <span style="color: #990000;">closedir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If you get the error code: (1) or (254) check the permissions of your compiler.jar and &#8220;compiled&#8221;-directory. Everyone must be allowed to read and execute the compiler.jar and everyone must can write to the compiled folder:</p>
<pre>-rwx<strong>r-xr-x</strong> 1 root root 4,1M 17. Jun 01:09 compiler.jar
drwxrwxrwx 2 root root    4096 11. Sep 15:12 compiled</pre>
<p>Set the right permissions with:</p>
<pre>chmod a+rx compiler.jar
chmod a+w compiled
</pre>
</pre>
<p>And now see it in action on BOHUCO Labs: <a href="http://bohuco.net/labs/google-closure-compiler-php">bohuco.net/labs/google-closure-compiler-php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bohuco.net/blog/2010/09/use-google-closure-compiler-local-with-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>HTML5 WebSockets Example</title>
		<link>http://bohuco.net/blog/2010/07/html5-websockets-example/</link>
		<comments>http://bohuco.net/blog/2010/07/html5-websockets-example/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 18:07:59 +0000</pubDate>
		<dc:creator>DerFichtl</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Web Entwicklung]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Websockets]]></category>

		<guid isPermaLink="false">http://bohuco.net/blog/?p=1445</guid>
		<description><![CDATA[HTML5 WebSockets makes it possible to open a persistent connection to a server within a web-browser via javascript. UPDATE: Mastering the new Spec-76 WebSockets handshake with PHP. Websockets works already in the latest Webkit-browsers like Safari 5 and Chrome 5. Firefox 4 Beta 1 knows the Websocket-Object but it can&#8217;t open the connection My Websocket [...]]]></description>
			<content:encoded><![CDATA[<p>HTML5 WebSockets makes it possible to open a persistent connection to a server within a web-browser via javascript.</p>
<p><span id="more-1445"></span></p>
<p style="font-weight: bold; border-top: 1px dashed black; padding: 20px; margin: 40px 20px; border-bottom: 1px dashed black;">UPDATE: Mastering the new <a href="http://bohuco.net/blog/2010/07/php-websocket-server-the-handshake/">Spec-76 WebSockets handshake with PHP</a>.</p>
<p>Websockets works already in the latest Webkit-browsers like Safari 5 and Chrome 5. Firefox 4 Beta 1 knows the Websocket-Object but it can&#8217;t open the connection <img src='http://bohuco.net/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>My <a href="http://bohuco.net/dev/websocket/">Websocket test script</a> sends the current mouse position via socket connection to the server and then receives all positions of all current open sockets and prints them to the browser-window. In other words, you can see the mouse cursors of the other users on the page.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> socket<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> host <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;ws://84.38.67.247:8080/dev/websocket/server.php&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
		socket <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> WebSocket<span style="color: #009900;">&#40;</span>host<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		socket.<span style="color: #660066;">onopen</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		socket.<span style="color: #660066;">onmessage</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'var data = '</span> <span style="color: #339933;">+</span> msg.<span style="color: #660066;">data</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">';'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>userId <span style="color: #000066; font-weight: bold;">in</span> data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#91;</span>userId<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">position</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #003366; font-weight: bold;">var</span> pos <span style="color: #339933;">=</span> data<span style="color: #009900;">&#91;</span>userId<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">position</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #003366; font-weight: bold;">var</span> color <span style="color: #339933;">=</span> data<span style="color: #009900;">&#91;</span>userId<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">color</span><span style="color: #339933;">;</span>
					render<span style="color: #009900;">&#40;</span>userId<span style="color: #339933;">,</span> pos<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> pos<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> color<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
			dump<span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		socket.<span style="color: #660066;">onclose</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>ex<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mousemove'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		send<span style="color: #009900;">&#40;</span>evt.<span style="color: #660066;">clientX</span><span style="color: #339933;">,</span> evt.<span style="color: #660066;">clientY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> render<span style="color: #009900;">&#40;</span>u<span style="color: #339933;">,</span> x<span style="color: #339933;">,</span> y<span style="color: #339933;">,</span> c<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>u<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'
&nbsp;
'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>u<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'left'</span><span style="color: #339933;">,</span> x<span style="color: #339933;">+</span><span style="color: #3366CC;">'px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>u<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'top'</span><span style="color: #339933;">,</span> y<span style="color: #339933;">+</span><span style="color: #3366CC;">'px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>u<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'background'</span><span style="color: #339933;">,</span> c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> send<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span>y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> msg <span style="color: #339933;">=</span> x <span style="color: #339933;">+</span> <span style="color: #3366CC;">','</span> <span style="color: #339933;">+</span> y<span style="color: #339933;">;</span>
	socket.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>On the server side i use a PHP5 script. I have written my own server-class but it&#8217;s based on the work of the <a href="http://code.google.com/p/phpwebsocket/">phpwebsocket</a> project. The server.php instantiate the WebSocketServer object and contains the callback function.</p>
<p><strong>New URL for Example: <a href="http://bohuco.net/labs/php-websocket-class/">http://bohuco.net/labs/php-websocket-class/</a></strong></p>
<p><a href="http://bohuco.net/dev/websocket/">http://bohuco.net/dev/websocket/</a></p>
<p>Source Codes:<br />
<a href="http://bohuco.net/dev/websocket/?source=WebSocketServer.php">WebSocketServer.php</a><br />
<a href="http://bohuco.net/dev/websocket/?source=server.php">server.php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bohuco.net/blog/2010/07/html5-websockets-example/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>SproutCore Erfinder eröffnet HTML5-Firma</title>
		<link>http://bohuco.net/blog/2010/07/sproutcore-erfinder-eroffnet-html5-firma/</link>
		<comments>http://bohuco.net/blog/2010/07/sproutcore-erfinder-eroffnet-html5-firma/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 05:39:52 +0000</pubDate>
		<dc:creator>DerFichtl</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Web Entwicklung]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[MobileMe]]></category>
		<category><![CDATA[SproutCore]]></category>

		<guid isPermaLink="false">http://bohuco.net/blog/?p=1428</guid>
		<description><![CDATA[Der SproutCore Erfinder Charles Jolley verlässt Apple und gründet ein Unternehmen das sich mit der Entwicklung neuer Rich-Web Applikationen auf HTML5-basis beschäftigen wird. Jolley war unter anderem für die MobileMe Plattform zuständig und hat für Apple Javascript Frameworks entwickelt. Die neue Firma wird Strobe Digital Publishing heißen und Jolley beschreib sie so: Strobe Digital Publishing [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://bohuco.net/blog/wp-content/uploads/2010/07/Bildschirmfoto-2010-07-09-um-07.37.33.png"><img class="alignright size-full wp-image-1429" title="Bildschirmfoto 2010-07-09 um 07.37.33" src="http://bohuco.net/blog/wp-content/uploads/2010/07/Bildschirmfoto-2010-07-09-um-07.37.33.png" alt="" width="118" height="135" /></a>Der <a href="http://www.sproutcore.com/">SproutCore</a> Erfinder Charles Jolley verlässt <a href="http://www.apple.com">Apple</a> und gründet ein Unternehmen das sich mit der Entwicklung neuer Rich-Web Applikationen auf HTML5-basis beschäftigen wird.</p>
<p><span id="more-1428"></span></p>
<p>Jolley war unter anderem für die MobileMe Plattform zuständig und hat für Apple Javascript Frameworks entwickelt. Die neue Firma wird Strobe Digital Publishing heißen und Jolley beschreib sie so:</p>
<blockquote><p>Strobe Digital Publishing is a better way to put content onto the iPad  and other mobile touch devices.  Based on a blend of HTML5 and native  technology, Strobe content applications offer a great native-style  reading experience with the ability to deep link and share content to  drive traffic.</p></blockquote>
<p>SproutCore ist ein HTML/Javascript Framework das diverse Komponenten für Rich-Web Applikationen zur Verfügung stellt &#8211; <a href="http://demo.sproutcore.com/sample_controls/">Demo</a>.</p>
<p>via <a href="http://news.cnet.com/8301-30685_3-20009681-264.html?part=rss&amp;subj=news&amp;tag=2547-1_3-0-20">cnet</a>, <a href="http://www.maclife.de/ehemaliger-apple-entwickler-gruendet-html5-unternehmen">maclife.de</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bohuco.net/blog/2010/07/sproutcore-erfinder-eroffnet-html5-firma/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Analytics Site Search Tracking</title>
		<link>http://bohuco.net/blog/2010/05/analytics-site-search-tracking/</link>
		<comments>http://bohuco.net/blog/2010/05/analytics-site-search-tracking/#comments</comments>
		<pubDate>Wed, 26 May 2010 05:31:17 +0000</pubDate>
		<dc:creator>DerFichtl</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[Inside Analytics Tracking]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[site search]]></category>
		<category><![CDATA[Tracking]]></category>

		<guid isPermaLink="false">http://bohuco.net/blog/?p=1407</guid>
		<description><![CDATA[Selbst wenn man keine klassische Volltext-Suche auf der Seite hat kann man mit dem Site Search Tracking von Analytics arbeiten. Man kann mittlerweile mehrere Parameter (GET, POST) angeben die in die Messung miteinbezogen werden sollen. Ausserdem kann man Parameter für Suchkategorien definieren. Falls man eine AJAX-Suche hat muß man die Messung manuell auslösen das sieht [...]]]></description>
			<content:encoded><![CDATA[<p>Selbst wenn man keine klassische Volltext-Suche auf der Seite hat kann man mit dem Site Search Tracking von Analytics arbeiten.<br />
<span id="more-1407"></span><br />
Man kann mittlerweile mehrere Parameter (GET, POST) angeben die in die Messung miteinbezogen werden sollen. Ausserdem kann man Parameter für Suchkategorien definieren. Falls man eine AJAX-Suche hat muß man die Messung manuell auslösen das sieht beim asynchronen Analytics so aus:</p>
<p>_gaq.push(['_trackPageview', "/jobs/search?keywords=Oida,Voda&amp;locations=Linz,Wien&amp;categories=Jobs"]);</p>
<p>&#8220;keywords&#8221; und &#8220;locations&#8221; wären in diesem Fall eine kombinierte Query und &#8220;categories&#8221; die Suchkategorien.<br />
<a href="http://bohuco.net/blog/wp-content/uploads/2010/05/Bildschirmfoto-Analytics.png"><img class="aligncenter size-full wp-image-1408" title="Bildschirmfoto Analytics" src="http://bohuco.net/blog/wp-content/uploads/2010/05/Bildschirmfoto-Analytics.png" alt="" width="703" height="393" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://bohuco.net/blog/2010/05/analytics-site-search-tracking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Browser-History mit jQuery auslesen</title>
		<link>http://bohuco.net/blog/2010/02/browser-history-with-jquery-auslesen/</link>
		<comments>http://bohuco.net/blog/2010/02/browser-history-with-jquery-auslesen/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 20:13:46 +0000</pubDate>
		<dc:creator>DerFichtl</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Browser]]></category>
		<category><![CDATA[history]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[privacy]]></category>

		<guid isPermaLink="false">http://bohuco.net/blog/?p=1323</guid>
		<description><![CDATA[Eine wirklich simple Idee &#8230; mittels der Farbunterscheidung zwischen &#8220;visited&#8221;- bzw. &#8220;nicht visited&#8221;-Links kann man die Browser-History eines Benutzers stehlen. Man braucht allerdings eine Linkliste die man vergleichen kann, also ist es kein richtiges stehlen. Im Detail funktioniert es so das man mittels Javascript Links erzeugt und vergleicht in welcher Farbe sie dargestellt werden. So [...]]]></description>
			<content:encoded><![CDATA[<p>Eine wirklich simple Idee &#8230; mittels der Farbunterscheidung zwischen &#8220;visited&#8221;- bzw. &#8220;nicht visited&#8221;-Links kann man die Browser-History eines Benutzers stehlen. Man braucht allerdings eine Linkliste die man vergleichen kann, also ist es kein richtiges stehlen. Im Detail funktioniert es so das man mittels Javascript Links erzeugt und vergleicht in welcher Farbe sie dargestellt werden. So kann man zB feststellen ob der Benutzer vorher schon bei den Konkurrenten vorbeigeschaut hat.</p>
<p>Mein Beispiel-Script kann man unter folgender Adresse finden:<br />
<a href="http://bohuco.net/dev/history/">http://bohuco.net/dev/history/</a></p>
<p>(via <a href="http://dicabrio.com/javascript/steal-history.php">dicabrio</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://bohuco.net/blog/2010/02/browser-history-with-jquery-auslesen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Closure Compiler with PHP</title>
		<link>http://bohuco.net/blog/2009/11/google-closure-compiler-with-php/</link>
		<comments>http://bohuco.net/blog/2009/11/google-closure-compiler-with-php/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 00:04:02 +0000</pubDate>
		<dc:creator>DerFichtl</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[closure]]></category>
		<category><![CDATA[closure compiler]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://bohuco.net/blog/?p=1166</guid>
		<description><![CDATA[Today Google released their new Closure Compiler, you can use it to optimize and minify your javascripts. UPDATE: Use Google Closure Compiler Local with PHP (Command Line) Now i show you how to use the new Google Closure Compiler over the RESTful API with PHP5. First of all, you don&#8217;t need to install anything, we [...]]]></description>
			<content:encoded><![CDATA[<p>Today Google released their new <a href="http://code.google.com/closure/compiler/">Closure Compiler</a>, you can use it to optimize and minify your javascripts.</p>
<p><span id="more-1166"></span></p>
<div style="margin:30px 0; padding:20px; background:#ccc; ">
<strong>UPDATE: <a href="http://bohuco.net/blog/2010/09/use-google-closure-compiler-local-with-php/">Use Google Closure Compiler Local with PHP</a> (Command Line)</strong>
</div>
<p>Now i show you how to use the new <a href="http://code.google.com/closure/compiler/">Google Closure Compiler</a> over the RESTful API with PHP5. First of all, you don&#8217;t need to install anything, we will connect the free API via <a href="http://www.php.net/manual/en/book.curl.php">cURL</a> usually activated in PHP5.</p>
<p>The API (<a href="http://code.google.com/closure/compiler/docs/api-ref.html">see reference</a>) resides under the following URL and requires four params:</p>
<p>http://closure-compiler.appspot.com/compile</p>
<pre>

<strong>compilation_level</strong>
is one of three options: WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, ADVANCED_OPTIMIZATIONS,
i use simple optimizations, it don't need further config (like advanced) but is
better than whitespace only.

<strong>output_format</strong>
is "text" if you want compile a javascript

<strong>output_info</strong>
is "compiled_code" if you want compile a javascript

<strong>js_code</strong>
is your javascript source code, instead you can submit "code_url" param, an url
to a javascript-file

&nbsp;
</pre>
<p>enough with theory, now the PHP code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000088;">$script</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.domain.com/scripts/script.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://closure-compiler.appspot.com/compile'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #0000ff;">'output_info=compiled_code&amp;output_format=text&amp;compilation_level=SIMPLE_OPTIMIZATIONS&amp;js_code='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$script</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>i use it in a deployer script and replace the content of my script files with the compiled versions. you can <a href="http://bohuco.net/testing/google/closure-compiler.php">tryout the compiler</a> with a simple html-form.</p>
]]></content:encoded>
			<wfw:commentRss>http://bohuco.net/blog/2009/11/google-closure-compiler-with-php/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>iPhone Lagesensor via Javascript</title>
		<link>http://bohuco.net/blog/2009/07/iphone-lagesensor-via-javascript/</link>
		<comments>http://bohuco.net/blog/2009/07/iphone-lagesensor-via-javascript/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 19:11:22 +0000</pubDate>
		<dc:creator>DerFichtl</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[safari]]></category>

		<guid isPermaLink="false">http://bohuco.net/blog/?p=1080</guid>
		<description><![CDATA[Über den Lagesensor kann man ermitteln ob das iPhone gerade hochkant oder horizontal gehalten wird. Safari am iPhone besitzt dazu ein spezielles window-attribut. In window.orientation steht entweder 0 (für vertikal) oder +/-90 wenn das iPhone quer gehalten wird, je nachdem welche Richtung es gedreht wurde. Um auf eine Änderung reagieren zu können gibt es den [...]]]></description>
			<content:encoded><![CDATA[<p>Über den Lagesensor kann man ermitteln ob das iPhone gerade hochkant oder horizontal gehalten wird. Safari am iPhone besitzt dazu ein spezielles window-attribut. In window.orientation steht entweder 0 (für vertikal) oder +/-90 wenn das iPhone quer gehalten wird, je nachdem welche Richtung es gedreht wurde.</p>
<p>Um auf eine Änderung reagieren zu können gibt es den Event-Handler onorientationchange den man zum Beispiel im BODY-Tag verwenden kann:</p>
<div style="width:90%;">

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&nbsp;
    &lt;body onorientationchange=&quot;alert(window.orientation);&quot;&gt;&lt;/body&gt;</pre></div></div>

</div>
<p>&raquo;&nbsp;<a href="http://bohuco.net/dev/iphone/orientation.html">Beispiel-Seite</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bohuco.net/blog/2009/07/iphone-lagesensor-via-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

