<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: fix code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 26 Jul 2008 22:40:58 GMT</pubDate>
    <description>DZone Snippets: fix code</description>
    <item>
      <title>Simple javascript XHR object with fix for missing onreadystatechange event in Firefox (for synchronous calls)</title>
      <link>http://snippets.dzone.com/posts/show/5416</link>
      <description>This code fixes the issue in Firefox where the onreadystatechange event is not called for synchronous XHR requests. It is based on the XHConn script from http://xkr.us/code/javascript/XHConn/, patched with the fix documented at http://lukav.com/wordpress/2007/04/12/firefox-firebug-and-synchronos-calls-problem/&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **&lt;br /&gt; ** Code licensed under Creative Commons Attribution-ShareAlike License      **&lt;br /&gt; ** http://creativecommons.org/licenses/by-sa/2.0/                           **/&lt;br /&gt;/**&lt;br /&gt; * Modified slightly from original to support synchoronous transactions&lt;br /&gt; * CDB 2007-05-16, 2007-06-05&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;function XHConn()&lt;br /&gt;{&lt;br /&gt;	var xmlhttp, bComplete = false;&lt;br /&gt;	try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }&lt;br /&gt;	catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }&lt;br /&gt;	catch (e) { try { xmlhttp = new XMLHttpRequest(); }&lt;br /&gt;	catch (e) { xmlhttp = false; }}}&lt;br /&gt;	if (!xmlhttp) return null;&lt;br /&gt;	this.connect = function(sURL, sMethod, sVars, fnDone, bAsynch)&lt;br /&gt;	{&lt;br /&gt;		if (!xmlhttp) return false;&lt;br /&gt;		bComplete = false;&lt;br /&gt;		sMethod = sMethod.toUpperCase();&lt;br /&gt;&lt;br /&gt;		if (bAsynch == null) bAsynch = true; //treat asynch as an optional argument&lt;br /&gt;&lt;br /&gt;		try {&lt;br /&gt;			if (sMethod == "GET")&lt;br /&gt;			{&lt;br /&gt;				xmlhttp.open(sMethod, sURL+"?"+sVars, (bAsynch == true));&lt;br /&gt;				sVars = "";&lt;br /&gt;			}&lt;br /&gt;			else&lt;br /&gt;			{&lt;br /&gt;				xmlhttp.open(sMethod, sURL, (bAsynch == true));&lt;br /&gt;				xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");&lt;br /&gt;				xmlhttp.setRequestHeader("Content-Type",&lt;br /&gt;					"application/x-www-form-urlencoded");&lt;br /&gt;			}&lt;br /&gt;&lt;br /&gt;			xmlhttp.onreadystatechange = function(){&lt;br /&gt;				if (xmlhttp.readyState == 4 &amp;&amp; !bComplete)&lt;br /&gt;				{&lt;br /&gt;					bComplete = true;&lt;br /&gt;					fnDone(xmlhttp);&lt;br /&gt;				}&lt;br /&gt;			};&lt;br /&gt;			xmlhttp.send(sVars);&lt;br /&gt;&lt;br /&gt;			/**&lt;br /&gt;			 * Firefox &lt;= 2.0.0 doesn't fire onreadystatechange for synchronous requests.&lt;br /&gt;			 * See http://lukav.com/wordpress/2007/04/12/firefox-firebug-and-synchronos-calls-problem/&lt;br /&gt;			 */&lt;br /&gt;			var isGecko = (document.addEventListener) ? true : false;&lt;br /&gt;			try {&lt;br /&gt;				if (!bAsynch &amp;&amp; isGecko &amp;&amp; xmlhttp.onreadystatechange == null) {&lt;br /&gt;					bComplete = true;&lt;br /&gt;					fnDone(xmlhttp);&lt;br /&gt;					return true;&lt;br /&gt;				}&lt;br /&gt;			}&lt;br /&gt;			catch (e) { return false; }&lt;br /&gt;			/**&lt;br /&gt;			 * End synchronous request patch&lt;br /&gt;			 */&lt;br /&gt;		}&lt;br /&gt;		catch(z) { return false; }&lt;br /&gt;		return true;&lt;br /&gt;	};&lt;br /&gt;	return this;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 21 Apr 2008 17:35:19 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5416</guid>
      <author>ChrisBloom7 (Chris Bloom)</author>
    </item>
    <item>
      <title>Exception class fix for php 4 //PHP Class</title>
      <link>http://snippets.dzone.com/posts/show/2450</link>
      <description>&lt;code&gt;&lt;br /&gt;if(!class_exists('Exception')){&lt;br /&gt;	class Exception{&lt;br /&gt;		var $_message = '';&lt;br /&gt;		var $_code = 0;&lt;br /&gt;		var $_line = 0;&lt;br /&gt;		var $_file = '';&lt;br /&gt;		var $_trace = null;&lt;br /&gt;&lt;br /&gt;		function Exception($message = 'Unknown exception', $code = 0){&lt;br /&gt;			$this-&gt;_message = $message;&lt;br /&gt;			$this-&gt;_code = $code;&lt;br /&gt;			$this-&gt;_trace = debug_backtrace();&lt;br /&gt;			$x = array_shift($this-&gt;_trace);&lt;br /&gt;			$this-&gt;_file = $x['file'];&lt;br /&gt;			$this-&gt;_line = $x['line'];&lt;br /&gt;		}&lt;br /&gt;&lt;br /&gt;		function __construct($message = 'Unknown exception', $code = 0){&lt;br /&gt;			$this-&gt;Exception($message, $code);&lt;br /&gt;		}&lt;br /&gt;&lt;br /&gt;		function getMessage(){&lt;br /&gt;			return $this-&gt;_message;&lt;br /&gt;		}&lt;br /&gt;		function getCode(){&lt;br /&gt;			return $this-&gt;_code;&lt;br /&gt;		}&lt;br /&gt;		function getFile(){&lt;br /&gt;			return $this-&gt;_file;&lt;br /&gt;		}&lt;br /&gt;		function getLine(){&lt;br /&gt;			return $this-&gt;_line;&lt;br /&gt;		}&lt;br /&gt;		function getTrace(){&lt;br /&gt;			return $this-&gt;_trace;&lt;br /&gt;		}&lt;br /&gt;		function getTraceAsString(){&lt;br /&gt;			$s = '';&lt;br /&gt;			foreach($this-&gt;_trace as $i=&gt;$item){&lt;br /&gt;				foreach($item['args'] as $j=&gt;$arg)&lt;br /&gt;					$item['args'][$j] = print_r($arg, true);&lt;br /&gt;				$s .= "#$i " . (isset($item['class']) ? $item['class'] . $item['type'] : '') . $item['function']&lt;br /&gt;				. '(' . implode(', ', $item['args']) . ") at [$item[file]:$item[line]]\n";&lt;br /&gt;			}&lt;br /&gt;			return $s;&lt;br /&gt;		}&lt;br /&gt;		function printStackTace(){&lt;br /&gt;			echo $this-&gt;getTraceAsString();&lt;br /&gt;		}&lt;br /&gt;		function toString(){&lt;br /&gt;			return $this-&gt;getMessage();&lt;br /&gt;		}&lt;br /&gt;		function __toString(){&lt;br /&gt;			return $this-&gt;toString();&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 20 Aug 2006 21:29:55 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2450</guid>
      <author>jonasraoni (Jonas Raoni Soares Silva)</author>
    </item>
    <item>
      <title>Array.indexOf fix //JavaScript Function</title>
      <link>http://snippets.dzone.com/posts/show/2437</link>
      <description>Just an idiot fix to increase the number of my posts =b&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//+ Jonas Raoni Soares Silva&lt;br /&gt;//@ http://jsfromhell.com&lt;br /&gt;[].indexOf || (Array.prototype.indexOf = function(v){&lt;br /&gt;       for(var i = this.length; i-- &amp;&amp; this[i] !== v;);&lt;br /&gt;       return i;&lt;br /&gt;});&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;example&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;var x = [0,1,2,3];&lt;br /&gt;&lt;br /&gt;alert(x.indexOf(2));&lt;br /&gt;alert(x.indexOf(4));&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 18 Aug 2006 06:22:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2437</guid>
      <author>jonasraoni (Jonas Raoni Soares Silva)</author>
    </item>
    <item>
      <title>Replace old style PHP tags to new style tags</title>
      <link>http://snippets.dzone.com/posts/show/2064</link>
      <description>Sometimes you have to work with scripts that contain old-style PHP tags. This little snippets fixes those scripts, so they use the new style PHP tags.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;find * -type f -exec perl -i -wpe 's/&lt;\?php/&lt;\?/g' {} \;&lt;br /&gt;find * -type f -exec perl -i -wpe 's/&lt;\?/&lt;\?php/g' {} \;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 18 May 2006 00:21:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2064</guid>
      <author>yoghoyogho ()</author>
    </item>
  </channel>
</rss>
