<?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>Skypher &#187; Chrome</title>
	<atom:link href="http://skypher.com/index.php/category/browsers/chrome-browsers/feed/" rel="self" type="application/rss+xml" />
	<link>http://skypher.com</link>
	<description>The blog for absolutely nothing!</description>
	<lastBuildDate>Sat, 25 Feb 2012 11:27:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Web Development on a Chromebook (2)</title>
		<link>http://skypher.com/index.php/2012/02/25/web-development-on-a-chromebook-2/</link>
		<comments>http://skypher.com/index.php/2012/02/25/web-development-on-a-chromebook-2/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 11:27:57 +0000</pubDate>
		<dc:creator>Cipher</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=704</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>Two weeks ago I posted about a web based IDE. And said I&#8217;d continue the work. So I did. It took a bit longer than expected (I was busy) but I&#8217;ve completed the following improvements:</p>
<ul>
<li>added jQuery, some JS abstraction</li>
<li>removed more unused code</li>
<li>fixed edit field height (but promptly broke it again)</li>
<li>added new file option</li>
<li>added open/add: made changes detection</li>
<li>added feedback bar</li>
<li>folder support (opening a file in a folder loses the status though <img src='http://skypher.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> , fix soon. )</li>
<li>ctrl+s saves your file</li>
</ul>
<div>It&#8217;s still <strong>extremely unsecured</strong>. Please use a htaccess file or another form of security which you find usefull.</div>
<p>You can read more about it on <a href="http://dippety.com/ide">dippety.com</a>! The download is also there.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2012/02/25/web-development-on-a-chromebook-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript 1K poptart cat</title>
		<link>http://skypher.com/index.php/2011/05/05/javascript-1k-poptart-cat/</link>
		<comments>http://skypher.com/index.php/2011/05/05/javascript-1k-poptart-cat/#comments</comments>
		<pubDate>Thu, 05 May 2011 11:29:04 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[1k]]></category>
		<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Funny]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=678</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>I wrote another 1K JavaScript demo: <a href="http://skypher.com/SkyLined/demo/1K/poptartcat/">a 1k version of poptart cat</a>. See <a href="http://knowyourmeme.com/memes/nyan-cat-pop-tart-cat">this site</a> for more information about <a href="http://www.prguitarman.com/index.php?id=348">this meme</a>.</p>
<p><iframe style="width:420px; height: 420px; overflow: hidden; border: 0px;" src="http://skypher.com/SkyLined/demo/1K/poptartcat/"></iframe></p>
<p>Minimization tricks include:</p>
<ul>
<li>storing all sprites in a string by encoding each pixel in a sprite in 2 bits and storing 6 bits in each character. Each 2 bit chunk can have one of these values: 0=CR/lF (end of line/start of next line in sprite), 1=transparent (do not draw but move to next pixel), 2 = color 1, 3 = color 2. The colors are chosen from a palette, which is a string containing a number of RGB colors encoded in 3 hex chars (&#8216;fff&#8217;=white, &#8217;000&#8242;=black, &#8216;f00&#8242;=red, etc&#8230;). Each sprite has an associated palette based on the number of the sprite. Most sprites use one of two palettes: a one color palette (&#8216;fff&#8217;) for the background stars) or a two color palette (&#8217;999000&#8242;) for the cat&#8217;s face, paws and tail. A few other palettes are used for the poptart.</li>
<li>storing all sprite maps (meaning which sprites to draw where for each frame) in an array of 6 strings, one for each frame, by encoding each position and sprite number in 3 bits. The background stars are not included; their vertical position is based on their number, by multiplying the number of each star by a certain value. Their horizontal position is based on time, by multiplying the time by a certain value modulus the width of the image and adding a &#8220;random&#8221; value using the value of a different character from the sprites string for each star.</li>
<li>drawing squares instead of sprites to fill larger regions, as sprites need a lot more bytes to store when they get bigger then code to draw a single square does.
<li>using one function for two purposes: to draw a specific sprite at a specific location using a specific palette on the canvas, or to draw a square at a specific location, with specific dimensions and a specific color on the canvas. The function will draw a sprite if there are only 4 arguments provided and a square if there are 5.</li>
<li>using a bit of math to offset multiple sprites based on which frame is being drawn and adding sprites to the sprite. This is done to have the individual sprite maps for each frame contain the same information as much as possible, which makes them easier to compress.
</ul>
<p>I assumed it would be easy to code this one in 1K, but it turned out that it was pretty hard to minimize my code.</p>
<ul>
<li>I started with a large file that draw only the (animated) cat. This wasn&#8217;t optimized in any way: it used one big sprite for each frame, with each pixel being stored as byte containing a value 0-8, representing an index into a palette.</li>
<li>I then cut the cat into smaller individual sprites that I could reuse between frames (eg. the face is always the same, just at a different location). I stored a sprite mapping, meaning which sprite to draw where for each frame. I stored all this information in a string using values between 0-36 encoded using &#8216;[char] = [value].toString(36)&#8221; and read using &#8220;[value] = parseInt([char], 36)&#8221;.</li>
<li>I chose to give each sprite only two colors + transparent (3 values), so I can store each pixel in 2 bits (4 values) and use the unused value to signal &#8216;end of line&#8217; and using &#8216;end of line&#8217; twice for &#8216;end of sprite&#8217;. This meant I could store the entire sprite as 2 bit values. I encoded 3 of these 2 bit values per byte using &#8220;[char] = String.fromCharCode([values]+offset)&#8221; and red them using &#8220;[values] = [char].charCodeAt(0)-offset&#8221;.</li>
<li>I stored the values in the sprite maps as 3 bit values and encoded 2 of these 3 bit values per byte as well.</li>
<li>I wrote code that choses an &#8216;offset&#8217; to use in encoding sprites/sprite maps that caused the resulting string to contain as many of the same bytes as the code, which allows better compression.</li>
<li>At this point I was down to ~1.2K compressed. By reusing code for two purposes (eg. the &#8216;f&#8217; function) and rearranging/rewriting code to have it contain as many repeated strings as possible to allow better compression, I as able to get it down to ~1.01K.</li>
<li>Finally, I optimized my png compressor code to work together with the poptart cat code; eg. do not use &#8216;eval&#8217; to run the decompressed code, which then uses setTimeout to start the animation, but use &#8216;setTimeout&#8217; directly. This allowed me to squeeze everything into 1K.</li>
</ul>
<p>Because manually editing 2/3 bit values stored in 8 bit characters + offset is impractical, and because some of the values where calculated rather than hand-picked. I wrote  my development code to generate the final code and data automatically. This means I have a somewhat documented, readable version of the <a href="http://skypher.com/SkyLined/demo/1K/poptartcat/1knyan6.html">test container HTML</a> and the actual <a href="http://skypher.com/SkyLined/demo/1K/poptartcat/1knyan6.js">JavaScript</a> code. The test container will load the code, which will show the animation slowed down to 1 frame per second and output the final code below the animation. The final code is what I pumped through my to-be-released <a href="http://code.google.com/p/jssfx/">JsSfx</a> png compressor.</p>
<p>Afterwards, I realized that there are a few ways in which I could have improved on the code by doing a few things differently:</p>
<ul>
<li>Save data as unicode strings; this allows storing not 6 bits per byte, but (effectively) 16 per 2 bytes. This could reduce the size of the data by about 128 bytes, but would use more bytes to store the non-unicode characters outside of the strings.</li>
<li>Save each entry for each sprite map in a separate string, meaning store the x coordinates in one string, the y coordinates in another and the sprite number in a third. This should result in data that can be compressed better.</li>
<li>Use scaling for sprites to be able to draw the background, rainbow and body of poptart cat using sprites as well instead of separate code to draw squares. This would use less bytes than having code to draw the cat using both sprites and squares.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2011/05/05/javascript-1k-poptart-cat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Mandelbrot fractal rendering engine</title>
		<link>http://skypher.com/index.php/2011/01/13/javascript-mandelbrot-fractal-rendering-engine/</link>
		<comments>http://skypher.com/index.php/2011/01/13/javascript-mandelbrot-fractal-rendering-engine/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 00:33:59 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=668</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve put a few pieces of JavaScript together to create an interactive Mandelbrot fractal rendering engine <a href="http://skypher.com/SkyLined/demo/FractalZoomer/Mandel.html">here</a>. You can zoom into any area and adjust the number of iterations.</p>
<p>Suggestions and comments are appreciated; I have a few ideas of my own, such as allowing you to link to specific zoom settings, but I&#8217;m not sure when I&#8217;ll have time to add them.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2011/01/13/javascript-mandelbrot-fractal-rendering-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Window Zoom Chrome Extension</title>
		<link>http://skypher.com/index.php/2011/01/02/window-zoom-chrome-extension/</link>
		<comments>http://skypher.com/index.php/2011/01/02/window-zoom-chrome-extension/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 12:40:08 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming Languages]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=664</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve released my first <a href="https://chrome.google.com/extensions">Chrome Extension</a>, which allows you to zoom certain HTML element to full window size. This is especially useful with embedded videos: where you can normally choose between watching as a tiny element embedded in a website or watching full screen, this extension gives you a third option: full window.<br />
While viewing an element full window, you can resize the window and the element will be resized accordingly.</p>
<p>Source code <a href="http://code.google.com/p/chrome-window-zoom-extension/">here</a>, install it <a href="https://chrome.google.com/webstore/detail/mpgjeecnfhippncndbojafcnpocpekcj/">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2011/01/02/window-zoom-chrome-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Merry Christmas and a Happy New Year!</title>
		<link>http://skypher.com/index.php/2010/12/22/merry-christmas-and-a-happy-new-year/</link>
		<comments>http://skypher.com/index.php/2010/12/22/merry-christmas-and-a-happy-new-year/#comments</comments>
		<pubDate>Wed, 22 Dec 2010 17:11:54 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Chrome]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=656</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>In case you don&#8217;t get my card: Merry Christmas and a Happy New Year, JavaScript style:<br />
<a href="http://skypher.com/SkyLined/demo/PerlinSimplexNoiseSnow/snow.html">http://skypher.com/SkyLined/demo/PerlinSimplexNoiseSnow/snow.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/12/22/merry-christmas-and-a-happy-new-year/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Perlin flames source</title>
		<link>http://skypher.com/index.php/2010/11/30/javascript-perlin-flames-source/</link>
		<comments>http://skypher.com/index.php/2010/11/30/javascript-perlin-flames-source/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 15:01:40 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[1k]]></category>
		<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=642</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>Many people have asked me for the uncompressed source of my <a href="http://skypher.com/index.php/2010/11/28/perlin-flames/">Perlin flames script</a>. At first I though about keeping it private, so people would have to reverse engineer the compressed code. After all, reverse engineering is how I learned the majority of what I know about programming today. But I realized that not everybody may have time to waste on such efforts when I wanted to have a copy of the original source of <a href="http://www.p01.org/releases/WOLF1K/wolf1k.js">WOLF1k</a> and couldn&#8217;t be bothered to decode it myself. So, I&#8217;ve made the uncompressed source available <a href="http://skypher.com/SkyLined/demo/PerlinFlames/p4.js">here</a>. This is the source after I manually optimized it for size and it doesn&#8217;t have any useful inline documentation: I found it much easier to memorize what each part of 1k of script does than continuously update documentation as I wrote it.</p>
<p>I still believe it is a good exercise to extract the source from the encoded version, as you learn a lot more that way, but I&#8217;ll leave that choose to you.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/11/30/javascript-perlin-flames-source/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript Perlin flames in 1k</title>
		<link>http://skypher.com/index.php/2010/11/28/perlin-flames/</link>
		<comments>http://skypher.com/index.php/2010/11/28/perlin-flames/#comments</comments>
		<pubDate>Sun, 28 Nov 2010 22:50:29 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[1k]]></category>
		<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=617</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p><a href="http://encyclopediadramatica.com/TL;DR">TL;DR</a> =&gt; see the Perlin noise flames script in action <a href="http://skypher.com/SkyLined/demo/PerlinFlames/p4sfx.html">here</a>. The rest of this article details how the script works and how I reduced its size to under 1k.</p>
<p>One of my side projects is creating JavaScript <a href="http://en.wikipedia.org/wiki/Demo_(computer_programming)">demos</a>. Unfortunately, I hardly ever find time to finish and <a href="http://pouet.net/user.php?who=24551">release</a> anything. You may recognize the following: I think of a new effect that would be really cool. I start working on some code and get a proof-of-concept working. The code proves how awesome the end result would be, but it&#8217;s nowhere near production quality. Then I waste a lot of time on fine-tuning some aspects of the code (size, speed, various design/implementation details). Finally I get bored with it and/or distracted by a new project. I have a zillion of such projects doing nothing on my harddrive.</p>
<p>Luckily, this is not always the case. I was going through some of the awesome codes of the <a href="http://js1k.com/">js1k</a> contest recently and got interested in <a href="http://en.wikipedia.org/wiki/Perlin_noise">Perlin noise</a>. I started working on my own version and after only a few iterations I had a pretty decent flame effect going. The amazing thing about Perlin noise is how easy it is to create a decent looking effect with very little effort.</p>
<p>The code starts by creating an array with <a href="http://en.wikipedia.org/wiki/Random_number_generation">random numbers</a>. The code needs to have a way of requesting the same random number twice and getting the same value and an array is the fasted way to do this. Using an index into the array as a seed, the code can read the same random number as often as it wants without changes. One side effect is that because the size of the array is limited, you will at some point have to reuse the same data. However, if you make sure the size of this array is sufficiently large (and a prime), this will not be noticed by the average user. Next the code creates three canvas elements. Two are used as off-screen buffers to generate the flames and smoke in, the third is visible and used to combine the two into the final effect. Two one dimentional arrays of perlin data are generated, one for the shape of the flames and one which is used as a <a href="http://en.wikipedia.org/wiki/Map_projection">projection map</a> for the movement of the flames. For each pixel, the projection map tells the code where in the shape map it should read a byte to use as the color value for that pixel. The color value is converted to an RGB value using two table, one for the flames and one for the smoke. The pixels are drawn at the bottom of the off-screen buffers and all pixels in these buffers are shifted upwards. For the flames, all pixels in the buffer are darkened, causing them to die out as the move up.</p>
<p>When I got his working, I got obsessed, as one does, with size and speed: I wanted to have it run at 60fps and shrink the size of the code to 1k or less. Guaranteeing the frame rate is hard to achieve because the effect needs a few CPU intensive operations to calculate each frame. I could reduce the quality to achieve a higher frame rate, but that would defeat the original goal of creating a nice looking effect. After a bit of tweaking, it is now running at 60fps on my machine without too much loss of quality. However, it may be less on older machines.</p>
<p>Shrinking the size of JavaScript is mostly about rewriting/rearranging your algorithms to be more size efficient. How to best do this depends on the algorithm and many such optimizations are one-offs: they apply only to that one code construct and you&#8217;ll probably never use the same trick again. However, there are a few tricks that I find I can commonly use on all scripts to reduce their size:</p>
<ol>
<li>Use one character, global variable and function names:
<ul>
<li>&quot;<strong>var iCounter = 0</strong>&quot; =&gt; &quot;<strong>i=0</strong>&quot;</li>
</ul>
</li>
<li>Do not use expensive keywords:
<ul>
<li>&quot;<strong>x=new Array();</strong>&quot; =&gt; &quot;<strong>x=[];</strong>&quot;</li>
<li>&quot;<strong>while(){}</strong>&quot;, &quot;<strong>do {} while ()</strong>&quot; =&gt; &quot;<strong>for(){}</strong>&quot;</li>
<li>&quot;<strong>x=Math.floor(x);</strong>&quot; =&gt; &quot;<strong>x=x&gt;&gt;0;</strong>&quot;</li>
<li>&quot;<strong>x=Math.round(x);</strong>&quot; =&gt; &quot;<strong>x=x-.5&gt;&gt;0;</strong>&quot;</li>
<li>&quot;<strong>x=Math.ceil(x);</strong>&quot; =&gt; &quot;<strong>x=x+.999&gt;&gt;0;</strong>&quot;
<div>(if you don&#8217;t mind rounding errors)</div>
</li>
<li>&quot;<strong>x=Math.pow(2,x);</strong>&quot; =&gt; &quot;<strong>x=1&lt;&lt;x;</strong>&quot;</li>
<li>&quot;<strong>x=x/256;</strong>&quot; =&gt; &quot;<strong>x=x>>8;</strong>&quot;
<div>(if you don&#8217;t mind the result being rounded down to an integer)</div>
</li>
</ul>
</li>
<li>Choose the most efficient notation for numbers:
<ul>
<li>&quot;<strong>0&#215;10</strong>&quot; =&gt; &quot;<strong>16</strong>&quot;</li>
<li>&quot;<strong>0&#215;20000</strong>&quot; =&gt; &quot;<strong>1&lt;&lt;17</strong>&quot;</li>
<li>&quot;<strong>1000</strong>&quot; =&gt; &quot;<strong>1e3</strong>&quot;</li>
<li>&quot;<strong>.0001</strong>&quot; =&gt; &quot;<strong>1e-4</strong>&quot;</li>
</ul>
</li>
<li>Optimize how you use the <a href="http://en.wikipedia.org/wiki/For_loop#Three-expression_for_loops">three-expression</a> in for-loops:
<ul>
<li>&quot;<strong>for(x=0;x&lt;50;x++){}</strong>&quot; =&gt; &quot;<strong>for(x=50;x&#8211;;){}</strong>&quot;</li>
<li>&quot;<strong>for(x=50;x&#8211;;){}y=5;</strong>&quot; =&gt; &quot;<strong>for(x=50;x&#8211;;y=5){}</strong>&quot;
<div>(this saves 1 semi-colon, but may slow your script down a little)</div>
</li>
</ul>
</li>
<li>Remove comments and unneeded curly braces, white-space and semi-colons:
<ul>
<li>&quot;<strong>for (&#8230;) { a+=b; c*=a; }</strong>&quot; =&gt; &quot;<strong>for(&#8230;)a+=b,c*=a;</strong>&quot;</li>
<li>&quot;<strong>function () {a+=b;}</strong>&quot; =&gt; &quot;<strong>function(){a+=b}</strong>&quot;</li>
</ul>
<div>(Some of this can be done automatically and I&#8217;ve recently added code to do this to <a href="http://code.google.com/p/jssfx/">JsSfx</a>)</div>
</li>
<li>Save often used complex values in variables:
<ul>
<li>&quot;<strong>x=document.createElement(&#8230;);document.body.appendchild(x);</strong>&quot; =&gt; &quot;<strong>d=document;x=d.createElement(&#8230;);d.body.appendchild(x);</strong>&quot;</li>
<li>&quot;<strong>y=x*x*x+x*x-4;z=x*x*x+x*x+5;</strong>&quot; =&gt; &quot;<strong>y=(q=x*x*x+x*x)-4;z=q+5;</strong>&quot;</li>
</ul>
</li>
<li>Combine setting values:
<ul>
<li>&quot;<strong>x=0;y=0;</strong>&quot; =&gt; &quot;<strong>x=y=0;</strong>&quot;</li>
<li>&quot;<strong>x=0;y=[0];</strong>&quot; =&gt; &quot;<strong>y=[x=0];</strong>&quot;</li>
</ul>
</li>
</ol>
<p>This list does not claim to be complete. If you feel that I have omitted something useful, please leave a comment.</p>
<p>After manual optimization of code size, you can probably shrink the size of you script a lot further using some form of compression and self-extraction. I <a href="http://skypher.com/index.php/2010/08/10/jssfx/">published</a> <a href="http://code.google.com/p/jssfx/">JsSfx</a>, which implements a custom compression and generates self-extracting JavaScript. I developed the compression technique it uses based on a number of assumptions:</p>
<ol>
<li>JavaScript often contains the same character sequence a number of times (eg. strings like &quot;<strong>for(</strong>&quot; will appear quite often)</li>
<li>JavaScript normally uses <a href="http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters">a small sub-set</a> of all the bytes <a href="http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf">valid in JavaScript</a>.</li>
<li>The size of the script to be compressed is assumed to be small. Therefore, compression can save only so many bytes and the size of the decoder will have a large impact on the size of the final script. A large decoder negates the benefit of a good compression ratio.</li>
</ol>
<p>The compression used in JsSfx works by replacing all instances of an often repeated string with one character that is not used in the script. It saves the character and the string it replaced as well. In a way this is similar to the manual step number 6 I explained above. Here&#8217;s an example:<br />
<code><br />
code="o = document.createElement('a');\r\ndocument.body.appendChild(o);"<br />
&nbsp;<br />
</code><br />
May be compressed as:<br />
<code><br />
keys="A"<br />
code="o = AcreateElement('a');\r\nAbody.appendChild(o);Adocument.";<br />
&nbsp;<br />
</code><br />
In the above example, &#8220;document.&#8221; was replaced by &#8220;A&#8221;. The keys variable contains the list of the characters used to replace strings (in this case only &#8220;A&#8221;). The code variable stores the original string, with the replacements, followed by the key and the replaced string. The original code can be restored by splitting the code string into sub-strings using the keys. In the above example this leads to an array of sub-strings like this:<br />
<code><br />
sub_string=["o = ", "createElement('a');\r\n", "body.appendChild(o);", "document."];<br />
&nbsp;<br />
</code><br />
By removing the last string from the array and joining the remaining strings back together using this string, the decoder can recreate the original.</p>
<p>The original Perlin noise flames script was about 3.2k in size (excluding comments and whitespace). I manually reduced this to ~1.2k (a lot of gain comes from replacing long variables names with one character). Using JsSfx, I got it just below 1k.</p>
<p>I&#8217;d like to thank the people at <a href="http://pouet.net/prod.php?which=56334">pouet.net</a> for feedback that allowed me to get this script to run on all browsers except MSIE. I&#8217;ve tested it on MSIE9 platform preview, but it doesn&#8217;t work (for unknown reasons).</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/11/28/perlin-flames/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Apple QuickTime memory corruption when loading BMP file</title>
		<link>http://skypher.com/index.php/2010/04/12/apple-quicktime-memory-corruption-when-loading-bmp-file/</link>
		<comments>http://skypher.com/index.php/2010/04/12/apple-quicktime-memory-corruption-when-loading-bmp-file/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 11:53:01 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[PoC]]></category>
		<category><![CDATA[Safari]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=455</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>From <a href="http://support.apple.com/kb/HT4104">http://support.apple.com/kb/HT4104</a>:<br />
CVE-ID: CVE-2010-0536</p>
<p>Impact: Opening a maliciously crafted BMP image may lead to an unexpected application termination or arbitrary code execution</p>
<p>Description: A memory corruption issue exists in the handling of BMP images. Opening a maliciously crafted BMP image may lead to an unexpected application termination or arbitrary code execution. This update addresses the issue by performing additional validation of BMP images.</p>
<p>More details here:<br />
<a href="http://code.google.com/p/skylined/issues/detail?id=11">http://code.google.com/p/skylined/issues/detail?id=11</a></p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/04/12/apple-quicktime-memory-corruption-when-loading-bmp-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Advances in heap spraying #1: when size matters.</title>
		<link>http://skypher.com/index.php/2010/01/18/advances-in-heap-spraying-size/</link>
		<comments>http://skypher.com/index.php/2010/01/18/advances-in-heap-spraying-size/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 15:08:02 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=146</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p><a href="http://skypher.com/SkyLined/heap_spray/small_heap_spray_generator.html">http://skypher.com/SkyLined/heap_spray/small_heap_spray_generator.html</a></p>
<p>I&#8217;ve created a <a href="http://en.wikipedia.org/wiki/Heap_spraying">heap-spray</a> generator. It generates a small piece of JavaScript that sprays the heap using the following customizable settings:<br />
<UL><br />
  <LI><strong>Shellcode</strong>, easy to enter using hexadecimal byte values (see also <a href="http://code.google.com/p/beta3/">BETA3</a>).</LI><br />
  <LI><strong>Target address</strong> and <strong>block size</strong>.</LI><br />
  <LI><strong>heap header size</strong> based on target browsers or manual value.</LI><br />
</UL><br />
The resulting code is smaller than any heap-spray I&#8217;ve seen in the wild:<br />
<UL><br />
  <LI>The heap-spray code itself is <strong>just over 70 bytes</strong>.</LI><br />
  <LI>The shellcode can be encoded using a <strong>custom-build 7-bit encoding</strong>.</LI><br />
</UL><br />
Most exploits contain shellcode encoded as &#8220;\uXXXX&#8221; or even &#8220;%uXXXX&#8221;. The resulting encoded shellcode data contains 3 bytes for every byte in the original shellcode. Because this is very wasteful, it is quite easy to improve on this by creating a custom en-/decoder. The &#8220;7-bit&#8221; encoding I created converts the 16-bit characters in the unicode string that contains the shellcode to a series of 7-bit values, which are encoded into <a href="http://en.wikipedia.org/wiki/ISO/IEC_8859-1">latin-1</a> characters. The resulting encoded shellcode data contains only 1.125 bytes for every byte in the shellcode, a saving of almost 63% compared to conventional encodings.<br />
The heap-spray will of course need some additional code to decode the shellcode, so the combined code+data will only be smaller for large enough shellcodes. Because my decoder is also rather small (just under 130 bytes), the break-even point is just under 70 bytes of shellcode. For a a 100 byte shellcode, you save about 50 bytes and for a 200 bytes shellcode, you save about 200 bytes!</p>
<p>You can try out the heap-spray generator <a href="http://skypher.com/SkyLined/heap_spray/small_heap_spray_generator.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/01/18/advances-in-heap-spraying-size/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cross browser parallel asynchronous XMLHttpRequests with timeout.</title>
		<link>http://skypher.com/index.php/2009/09/29/cross-browser-parallel-asynchronous-xmlhttprequests-with-timeout/</link>
		<comments>http://skypher.com/index.php/2009/09/29/cross-browser-parallel-asynchronous-xmlhttprequests-with-timeout/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 20:50:33 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=232</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p><B>AsyncXMLHttpRequest</B> is an extension of <B>XMLHttpRequest</B> with the following improvements:<br />
<UL><br />
  <LI> Uniform behavior on multiple different browsers (Apple Safari, Google Chrome, Microsoft Internet Explorer, Mozilla Firefox and Opera).</LI><br />
  <LI> Event handlers are called with the <B>AsyncXMLHttpRequest</B> object to which they apply as the first argument. This makes it easy to have multiple parallel requests because there is no need to find out for which object an event has fired.</LI><br />
  <LI> A <B>timeout</B> attribute can be set to a number of milliseconds , the request is aborted if it didn&#8217;t complete within the given number of milliseconds after calling <B>send()</B>.</LI><br />
  <LI> A <B>timedout</B> attribute has been added that is <B>false</B> as long as the request has not been aborted because of a time out and <B>true</B> when it has.</LI><br />
  <LI> Arguments passed to the <B>open()</B> and <B>send()</B> methods are saved in attributes of the object for later reference. These attributes are: <B>method</B>, <B>url</B>, <B>user</B> and <B>password</B> for <B>open()</B> and <B>body</B> for <B>send()</B>.</LI><br />
  <LI> Three additional events have been added: <B>onload</B>, <B>onerror</B> and <B>ontimeout</B>. These are called when the <B>readyState</B> has changed to 4 and the request has, respectively, succeeded (no timeout, <B>status</B> == 2xx), failed (no timeout, <B>status</B> != 2xx) or has timed out.</LI><br />
</UL></p>
<p><BIG><B> Cross Browser Uniform Behavior </B></BIG><br />
To make <B>AsyncXMLHttpRequest</B> work uniformly across different browsers, it catches and handles some exceptions that are throw in some browsers, but not in others. Specifically, Firefox, MSIE and Opera throw exceptions when calling the <B>open()</B> and <B>send()</B> methods for certain invalid or cross-origin urls. If any of these exceptions are caught and handled, the request will fail similar to other browser by having <B>status</B> == 0 after the <B>readyState</B> has changed to 4.</p>
<p><BIG><B> Parallel Requests </B></BIG><br />
To allow any number of parallel requests to take place and still keep track of which request is in what state, all event handlers are passed the <B>AsyncXMLHttpRequest</B> object to which they apply. In other words, when a certain <B>AsyncXMLHttpRequest</B> object is done (<B>readyState</B> == 4), the <B>onreadystatechange</B> event handler is called with the <B>AsyncXMLHttpRequest</B> object to which it applies as the first argument of the call.</p>
<p><BIG><B> Source </B></BIG><br />
Available through <A href="http://code.google.com/p/asyncxmlhttprequest/">Google code</A>.</p>
<p><BIG><B> Example </B></BIG><br />
This example shows that you can create any number of parallel requests (the browser or OS may have a built in limit) without having to keep track of which object an event is firing for because it is passes as an argument to the event handler:</p>
<p><CODE><br />
&lt;HTML&gt;<br />
  &lt;BODY onload=&#8221;go()&#8221;&gt;&lt;/BODY&gt;<br />
  &lt;SCRIPT src=&#8221;AsyncXMLHttpRequest.js&#8221;&gt;&lt;/SCRIPT&gt;<br />
  &lt;SCRIPT&gt;<br />
    function go() {<br />
      for (var i = 0; i &lt; 30; i++) {<br />
        request(location + &#8220;?&#8221; + i);<br />
      }<br />
    }<br />
    function request(url) {<br />
      span = document.createElement(&#8220;DIV&#8221;);<br />
      document.body.appendChild(span);<br />
      span.innerHTML = &#8220;&lt;B&gt;&#8221; + url + &#8220;&lt;/B&gt;&#8221;;<br />
      xmlhttp = new AsyncXMLHttpRequest();<br />
      xmlhttp.span = span;<br />
      xmlhttp.onload = load;<br />
      xmlhttp.onerror = error;<br />
      xmlhttp.ontimeout = timeout;<br />
      xmlhttp.timeout = 1000;<br />
      xmlhttp.onreadystatechange = rs;<br />
      xmlhttp.open(&#8220;GET&#8221;, url);<br />
      xmlhttp.send();<br />
    }<br />
    function rs(xmlhttp) {<br />
      xmlhttp.span.innerHTML += &#8221; rs:&#8221; + xmlhttp.readyState;<br />
    }<br />
    function load(xmlhttp) {<br />
      xmlhttp.span.innerHTML += &#8221; load:&#8221; + xmlhttp.status;<br />
    }<br />
    function error(xmlhttp) {<br />
      xmlhttp.span.innerHTML += &#8221; error:&#8221; + xmlhttp.status;<br />
    }<br />
    function timeout(xmlhttp) {<br />
      xmlhttp.span.innerHTML += &#8221; timeout:&#8221; + xmlhttp.status;<br />
    }<br />
  &lt;/SCRIPT&gt;<br />
&lt;/HTML&gt;<br />
&nbsp;<br />
</CODE></p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2009/09/29/cross-browser-parallel-asynchronous-xmlhttprequests-with-timeout/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

