<?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; Browsers</title>
	<atom:link href="http://skypher.com/index.php/category/browsers/feed/" rel="self" type="application/rss+xml" />
	<link>http://skypher.com</link>
	<description>The blog for absolutely nothing!</description>
	<lastBuildDate>Sat, 19 Nov 2011 22:09:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Transformed polygons fractal rendering engine</title>
		<link>http://skypher.com/index.php/2011/11/19/transformed-polygons-fractal-rendering-engine/</link>
		<comments>http://skypher.com/index.php/2011/11/19/transformed-polygons-fractal-rendering-engine/#comments</comments>
		<pubDate>Sat, 19 Nov 2011 22:07:52 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Art]]></category>
		<category><![CDATA[Browsers]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming Languages]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=692</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 finally had some time to work on a project that renders fractals by repeatedly applying transformations to regular polygons. The code&#8217;s not in any state to release (and, sadly, probably will never be), but I did manage to get the kind of output I was hoping for. So, I&#8217;ve uploaded<br />
<a href="http://skylined.deviantart.com/art/Quasicrystal-3-269869870">a sample</a> to my Deviant Art page. The code is written in JavaScript and renders to the 2d canvas. This sample was rendered in Chrome in a few seconds.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2011/11/19/transformed-polygons-fractal-rendering-engine/feed/</wfw:commentRss>
		<slash:comments>0</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>Issue 32 &#8211; Oracle Java plugin2 non-exploitable memory corruption</title>
		<link>http://skypher.com/index.php/2010/10/13/issue-32-oracle-java-plugin2/</link>
		<comments>http://skypher.com/index.php/2010/10/13/issue-32-oracle-java-plugin2/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 12:10:15 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Repro]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=570</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>About two years ago I found what appeared to be a memory corruption issue in SUN (now owned by Oracle) <a href="http://java.com">Java</a> Version 6 Update 10. I failed to find any evidence that the issue allows remote code execution and after investigating, SUN/Oracle reported that it was not a security issue that required immediate patching.</p>
<p>Oracle have released a fix for this issue, which can be found <a href="http://www.oracle.com/technetwork/topics/security/javacpuoct2010-176258.html">here</a>.</p>
<p>Details can be found <a href="http://code.google.com/p/skylined/issues/detail?id=32">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/10/13/issue-32-oracle-java-plugin2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Issue 18 &#8211; Oracle Java APPLET tag children property memory corruption</title>
		<link>http://skypher.com/index.php/2010/10/13/issue-18-oracle-java-applet-childre/</link>
		<comments>http://skypher.com/index.php/2010/10/13/issue-18-oracle-java-applet-childre/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 12:04:17 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Repro]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=572</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>About half a year ago, I found a memory corruption issue in Oracle <a href="http://java.com">Java</a> Version 6 Update 20 which could be triggered by loading Java in <a href="http://www.microsoft.com/windows/internet-explorer/default.aspx">MSIE</a> through the &#8220;<a href="http://msdn.microsoft.com/en-us/library/ms535183(VS.85).aspx">APPLET</a>&#8221; tag and accessing the &#8220;<a href="http://msdn.microsoft.com/en-us/library/ms537446(v=VS.85).aspx">children</a>&#8221; property. It appears that the code suffers from some <a href="http://en.wikipedia.org/wiki/Race_condition">race condition</a> that may be exploited to <a href="http://en.wikipedia.org/wiki/Arbitrary_code_execution">execute arbitrary code</a> in the <a href="http://en.wikipedia.org/wiki/Access_token">context</a> of the user that the iexplore.exe process is running as.</p>
<p>Oracle have released a patch for this issue which can be found <a href="http://www.oracle.com/technetwork/topics/security/javacpuoct2010-176258.html">here</a>.</p>
<p>More details can be found <a href="http://code.google.com/p/skylined/issues/detail?id=18">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/10/13/issue-18-oracle-java-applet-childre/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Issue 23 &#8211; Oracle Java OBJECT tag &#8220;launchjnlp&#8221;/&#8221;docbase&#8221; property stack buffer overflow</title>
		<link>http://skypher.com/index.php/2010/10/13/issue-2-oracle-java-object-launchjnlp-docbase/</link>
		<comments>http://skypher.com/index.php/2010/10/13/issue-2-oracle-java-object-launchjnlp-docbase/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 09:34:09 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[PoC]]></category>
		<category><![CDATA[Repro]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=574</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>About a month and a half ago, <a href="http://www.reversemode.com/index.php?option=com_content&#038;task=view&#038;id=69&#038;Itemid=1">information about an 0-day vulnerability</a> in the <a href="http://www.apple.com/quicktime/">Apple QuickTime</a> plugin was published. It reminded of a project I had planned to implement for a while (since 2004 to be precise): a fuzzer that extracted information about <a href="http://en.wikipedia.org/wiki/COM_object">COM objects</a> installed on a system from the <a href="http://en.wikipedia.org/wiki/Windows_registry">registry</a> and scanned the <a href="http://en.wikipedia.org/wiki/Executable">binaries</a> associated with each COM object for strings. The fuzzer would use the collected information to try to instantiate objects and attempt to fuzz it using the strings as properties, methods and &#8220;<a href="http://en.wikipedia.org/wiki/Magic_number_(programming)">magic</a>&#8221; argument values. As soon as I had hacked something together, it found a simple <a href="http://en.wikipedia.org/wiki/Executable">buffer overflow</a> in Oracle <a href="http://java.com">Java</a> 6 Update 21.</p>
<p>The buffer overflow allows easy control over <a href="http://en.wikipedia.org/wiki/Instruction_pointer">EIP</a> and creating a working <a href="http://en.wikipedia.org/wiki/Exploit_(computer_security)">exploit</a> for targets without <a href="http://en.wikipedia.org/wiki/Data_Execution_Prevention">DEP</a> is as easy as copy+pasting a <a href="http://en.wikipedia.org/wiki/Heap_spray">heap spray</a> into the repro file.</p>
<p>I reported the issue to Oracle, who were <a href="http://www.zerodayinitiative.com/advisories/ZDI-10-206/">already aware</a> of the issue because it had also been reported to them by Stephen Fewer of <a href="http://www.harmonysecurity.com">Harmony Security</a> through <a href="http://www.zerodayinitiative.com/">ZDI</a>. Oracle has release a patch for this issue, which is available <a href="http://www.oracle.com/technetwork/topics/security/javacpuoct2010-176258.html">here</a>.</p>
<p>More details can be found <a href="http://code.google.com/p/skylined/issues/detail?id=23">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/10/13/issue-2-oracle-java-object-launchjnlp-docbase/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

