<?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>ADM Blog &#187; Programming</title> <atom:link href="http://blog.another-d-mention.ro/category/programming/feed/" rel="self" type="application/rss+xml" /><link>http://blog.another-d-mention.ro</link> <description>No matter how you see things, reality changes when you reach understanding</description> <lastBuildDate>Fri, 22 Jul 2011 06:56:49 +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>Pixel Programming</title><link>http://blog.another-d-mention.ro/programming/pixel-programming/</link> <comments>http://blog.another-d-mention.ro/programming/pixel-programming/#comments</comments> <pubDate>Fri, 22 Jul 2011 06:56:22 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Programming]]></category> <category><![CDATA[64k]]></category> <category><![CDATA[demo]]></category> <category><![CDATA[photoshop]]></category> <category><![CDATA[pixel]]></category> <category><![CDATA[programming]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=856</guid> <description><![CDATA[If you're old enough you may have seen the times when programmers wrote code as optimal as possible given the computers available back then. I remember 3D shooter games that would average 300 - 400 KB in size and you would play countless levels for days. Here's for example a 96 KB 3D shooter game [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/' rel='bookmark' title='Permanent Link: JavaScript Object-Oriented Programming (OOP) &#8211; jClass'>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</a></li><li><a
href='http://blog.another-d-mention.ro/misc/stories-for-a-it-audience/programming-is-like-sex/' rel='bookmark' title='Permanent Link: Programming is like sex'>Programming is like sex</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/' rel='bookmark' title='Permanent Link: Open and Save files to Desktop without going to Server'>Open and Save files to Desktop without going to Server</a></li></ol>]]></description> <content:encoded><![CDATA[<p>If you're old enough you may have seen the times when programmers wrote code as optimal as possible given the computers available back then. I remember 3D shooter games that would average 300 - 400 KB in size and you would play countless levels for days. Here's for example a 96 KB 3D shooter game called <a
href="http://www.theprodukkt.com/kkrieger">.kkriger </a> that will leave you breathless.</p><p><a
target="_blank" href="http://blog.another-d-mention.ro/wp-content/uploads/2011/07/full1.jpg"><img
src="http://blog.another-d-mention.ro/wp-content/uploads/2011/07/full1-300x225.jpg" alt="full1 300x225 Pixel Programming" title="full1" width="300" height="225" class="aligncenter size-medium wp-image-857" /></a></p><p>If you try now to explain people these days that it takes less space to write a 3 minutes HD animated video and music clip than than it takes to store a 32×32 pixel icon they won't believe you. Not now when a plain jpeg image used on some website is > 50KB. So here's a guy called <a
target="_blank" href="http://www.iquilezles.org/">Iñigo Quílez</a> who demonstrates just that using the image analogy. He writes a x86 real mode demo using Photoshop. The entire program is done by creating a 9x9 pixels image, filling each pixels with carefully chosen colors to represent the correct opcodes (who needs compilers, right ?) The image is then saved in a .raw format (no headers) then renames it to a .com file so that Windows recognize it as a executable. The animation is a infinite moving tunnel with a gray colored texture created with an XOR pattern, blurred, and deformed using a <a
target="_blank" href="http://www.iquilezles.org/www/articles/deform/deform.htm">plane deformation</a> technique to produce the animation.</p><p>This is the "source code" resized 10 times in a png extension</p><p><img
src="http://blog.another-d-mention.ro/wp-content/uploads/2011/07/pixel01.png" alt="pixel01 Pixel Programming" title="" width="90" height="90" class="aligncenter size-full wp-image-858" /></p><p>And here's the guy in action proving his mad skills.</p><div
style="text-align:center"> <iframe
width="640" height="510" src="http://www.youtube.com/embed/FvS_DG8yIqQ?hd=1" frameborder="0" allowfullscreen></iframe></div><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/' rel='bookmark' title='Permanent Link: JavaScript Object-Oriented Programming (OOP) &#8211; jClass'>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</a></li><li><a
href='http://blog.another-d-mention.ro/misc/stories-for-a-it-audience/programming-is-like-sex/' rel='bookmark' title='Permanent Link: Programming is like sex'>Programming is like sex</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/' rel='bookmark' title='Permanent Link: Open and Save files to Desktop without going to Server'>Open and Save files to Desktop without going to Server</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/pixel-programming/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Read data directly from base64 without decoding</title><link>http://blog.another-d-mention.ro/programming/java-script/read-data-directly-from-base64-without-decoding/</link> <comments>http://blog.another-d-mention.ro/programming/java-script/read-data-directly-from-base64-without-decoding/#comments</comments> <pubDate>Fri, 01 Jul 2011 13:06:55 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[base64]]></category> <category><![CDATA[decode]]></category> <category><![CDATA[javascript]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=855</guid> <description><![CDATA[So here's the catch. You have a binary input you want to mess with in your browser for whatever reason. First problem you encounter is when you load the file. In IE you will have trouble reading a binary string because it uses null terminated strings, and your file will end at the first 0x00 [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/' rel='bookmark' title='Permanent Link: Serialize JavaScript object to JSON'>Serialize JavaScript object to JSON</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/' rel='bookmark' title='Permanent Link: jQuery.quickEach'>jQuery.quickEach</a></li></ol>]]></description> <content:encoded><![CDATA[<p>So here's the catch. You have a binary input you want to mess with in your browser for whatever reason. First problem you encounter is when you load the file. In IE you will have trouble reading a binary string because it uses null terminated strings, and your file will end at the first 0x00 byte found. If you manage to overcome that but trust me it is very CPU intensive. See the source of <a
href="http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/">Read/Load files from ZIP in Javascript</a> post. You will have to create a vbScript that will convert the received AJAX response into an array with decimal values for each byte in the file. Depending on your file size, it will take accordingly (10+ seconds * file KB). For every other browser it works just fine with plain strings.</p><p>Okay, one other potential issue may come if you need to receive the data into a JSON string or XML or whatever beside a plain binary file. Then you have to use BASE64 encoding and decode your data into a variable but must keep in mind the first issue with the null characters. My solution to this problem is to create a method to read directly from the BASE64 encoded string at arbitrary locations without decoding the entire thing.</p><p>Here's an example of a binary file:</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;">Offset<span style="color: #009900;">&#40;</span>h<span style="color: #009900;">&#41;</span>00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
&nbsp;
00000000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F     ...............
00000010 <span style="color: #CC0000;">19</span> <span style="color: #CC0000;">84</span> <span style="color: #CC0000;">74</span> <span style="color: #CC0000;">68</span> <span style="color: #CC0000;">69</span> <span style="color: #CC0000;">73</span> <span style="color: #CC0000;">20</span> <span style="color: #CC0000;">69</span> <span style="color: #CC0000;">73</span> <span style="color: #CC0000;">20</span> <span style="color: #CC0000;">61</span> <span style="color: #CC0000;">20</span> <span style="color: #CC0000;">74</span> <span style="color: #CC0000;">65</span> <span style="color: #CC0000;">73</span> <span style="color: #CC0000;">74</span>     ..<span style="color: #000066; font-weight: bold;">this</span> <span style="color: #000066; font-weight: bold;">is</span> a test</pre></div></div><p>You have 32 bytes in this file, with BASE64 encoding you get a 46 chars length string:</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;">   AAECAwQFBgcICQoLDA0ODxmEdGhpcyBpcyBhIHRlc3Q<span style="color: #339933;">=</span></pre></div></div><p>A usage example:</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;">    <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Base64Native<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;AAECAwQFBgcICQoLDA0ODxmEdGhpcyBpcyBhIHRlc3Q=&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs 32;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">readBoolean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs false; - reads a byte and casts it to a boolean value</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">readByte</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs 1;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">readWord</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs 515; - reads a 16 bit number</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">readInt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs 67438087; - reads a 32 bit number</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">seek</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">28</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// moves the pointer to byte 28 (0x1C)</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">readString</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">bytesAvailable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs 'test'; reads a string from position 28 to the end of the file</span></pre></div></div><p>And here's the class</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Base64Native <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> keyStr <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=&quot;</span><span style="color: #339933;">,</span>
        length <span style="color: #339933;">=</span> data.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">length</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/=/g</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        ptr <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> keyIdx<span style="color: #009900;">&#40;</span>idx<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> keyStr.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</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>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> readByte<span style="color: #009900;">&#40;</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: #339933;">!</span><span style="color: #009900;">&#40;</span>length <span style="color: #339933;">-</span> ptr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">throw</span> Error<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'End of stream!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
        <span style="color: #003366; font-weight: bold;">var</span> blockIndex <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>ptr <span style="color: #339933;">/</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span> subIndex <span style="color: #339933;">=</span> ptr<span style="color: #339933;">++</span> <span style="color: #339933;">%</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> ptrChr <span style="color: #339933;">=</span> blockIndex <span style="color: #339933;">+</span> subIndex<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #339933;">!</span>subIndex <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>keyIdx<span style="color: #009900;">&#40;</span>ptrChr<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span>keyIdx<span style="color: #009900;">&#40;</span>ptrChr <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> subIndex <span style="color: #339933;">===</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">&amp;&amp;</span>
               <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>keyIdx<span style="color: #009900;">&#40;</span>ptrChr<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #CC0000;">15</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span>keyIdx<span style="color: #009900;">&#40;</span>ptrChr <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>keyIdx<span style="color: #009900;">&#40;</span>ptrChr<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span>  <span style="color: #339933;">&lt;</span> <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">6</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span>  keyIdx<span style="color: #009900;">&#40;</span>ptrChr <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #009966; font-style: italic;">/* Returns the available bytes left in the file to read */</span>
        bytesAvailable <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> length <span style="color: #339933;">-</span> ptr<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009966; font-style: italic;">/* Reads and returns a 8 bit number and increments the position of the index accordingly */</span>
        readByte <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> readByte<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: #339933;">,</span>
        <span style="color: #009966; font-style: italic;">/* Reads and returns a 32 bit number and increments the position of the index accordingly */</span>
        readInt <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><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>readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #CC0000;">24</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span>readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #CC0000;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span>readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #CC0000;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> readByte<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: #339933;">,</span>
        <span style="color: #009966; font-style: italic;">/* Reads 1 byte and returns the boolean value of it and increments the position of the index accordingly */</span>
        readBoolean <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> Boolean<span style="color: #009900;">&#40;</span>readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009966; font-style: italic;">/* Reads and returns a 16 bit number and increments the position of the index accordingly */</span>
        readWord <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #CC0000;">8</span> <span style="color: #339933;">|</span> readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009966; font-style: italic;">/* Reads and returns a string of length 'len' and increments the position of the index accordingly */</span>
        readString <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #006600; font-style: italic;">/*String*/</span>len<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                data <span style="color: #339933;">+=</span> String.<span style="color: #660066;">fromCharCode</span><span style="color: #009900;">&#40;</span>readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">return</span> data<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009966; font-style: italic;">/* Moves the index into the file at location newpos */</span>
        seek <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>newpos<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            ptr <span style="color: #339933;">=</span> newpos<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009966; font-style: italic;">/* Returns the position of the index in the file */</span>
        position <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> ptr<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009966; font-style: italic;">/* The length of the data */</span>
        length <span style="color: #339933;">:</span> length
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div> </pre><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/' rel='bookmark' title='Permanent Link: Serialize JavaScript object to JSON'>Serialize JavaScript object to JSON</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/' rel='bookmark' title='Permanent Link: jQuery.quickEach'>jQuery.quickEach</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/java-script/read-data-directly-from-base64-without-decoding/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>jQuery.quickEach</title><link>http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/</link> <comments>http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/#comments</comments> <pubDate>Wed, 04 May 2011 09:13:08 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[plugin]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=847</guid> <description><![CDATA[With jQuery, when you need to iterate all elements with a specific class for example, you use the each() method and inside the callback function you must convert the DOM element you receive as this to a jQuery object in order to access it's jQuery specific methods: $(this) This is not such a big issue [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/on-typing-complete-jquery-plugin/' rel='bookmark' title='Permanent Link: On typing finished jQuery plugin'>On typing finished jQuery plugin</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/parse-xml-in-javascript-with-jquery/' rel='bookmark' title='Permanent Link: Parse XML in JavaScript with jQuery'>Parse XML in JavaScript with jQuery</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li></ol>]]></description> <content:encoded><![CDATA[<p>With jQuery, when you need to iterate all elements with a specific class for example, you use the <code>each()</code> method and inside the callback function you must convert the DOM element you receive as <code>this</code> to a jQuery object in order to access it's jQuery specific methods: <code>$(this)</code><br
/> This is not such a big issue but if you have a lot of items and/or do this often, then times ads up. It would be a blast to have the <code>this</code> object directly as a jQuery instance. So here's a $ little plugin that does exactly that</p><p>Source website:<br
/> <a
href="http://jsperf.com/jquery-each-vs-quickeach" target="_blank">http://jsperf.com/jquery-each-vs-quickeach</a></p><p>The code:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">quickEach</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><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> jq <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span>
       el<span style="color: #339933;">,</span> len <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">++</span>i <span style="color: #339933;">&lt;</span> len <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>el <span style="color: #339933;">=</span> jq<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> c.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>jq<span style="color: #339933;">,</span> i<span style="color: #339933;">,</span> el<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</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>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">delete</span> jq<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">throw</span> e<span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #000066; font-weight: bold;">delete</span> jq<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>If you run the test on that page, on most browsers you'll see that quickEach() is about 80% faster than native each()</pre><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/on-typing-complete-jquery-plugin/' rel='bookmark' title='Permanent Link: On typing finished jQuery plugin'>On typing finished jQuery plugin</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/parse-xml-in-javascript-with-jquery/' rel='bookmark' title='Permanent Link: Parse XML in JavaScript with jQuery'>Parse XML in JavaScript with jQuery</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>For Javascript devs</title><link>http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/</link> <comments>http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/#comments</comments> <pubDate>Wed, 30 Mar 2011 08:08:18 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[html]]></category> <category><![CDATA[htmtag]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[querytag]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=846</guid> <description><![CDATA[If you write Javascript apps you may want to dynamically add some HTML here and there and having HTML strings that need concatenation with different variables is bad and ugly at the same time. So here is a little nugget you might find useful. 1 2 3 4 5 // standard style x = '&#60;div [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/' rel='bookmark' title='Permanent Link: Serialize JavaScript object to JSON'>Serialize JavaScript object to JSON</a></li><li><a
href='http://blog.another-d-mention.ro/programming/communicate-betwen-c-and-an-embeded-flash-application/' rel='bookmark' title='Permanent Link: Communicate betwen C# and an embeded Flash application'>Communicate betwen C# and an embeded Flash application</a></li><li><a
href='http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/' rel='bookmark' title='Permanent Link: JavaScript Object-Oriented Programming (OOP) &#8211; jClass'>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</a></li></ol>]]></description> <content:encoded><![CDATA[<p>If you write Javascript apps you may want to dynamically add some HTML here and there and having HTML strings that need concatenation with different variables is bad and ugly at the same time. So here is a little nugget you might find useful.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">    <span style="color: #006600; font-style: italic;">// standard style</span>
    x <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;div class=&quot;'</span> <span style="color: #339933;">+</span> classnames <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; rel=&quot;'</span> <span style="color: #339933;">+</span> somevar <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; id=&quot;'</span> <span style="color: #339933;">+</span> othervar <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span> content <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// html tag style</span>
    x <span style="color: #339933;">=</span> htmlTag<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #003366; font-weight: bold;">class</span><span style="color: #339933;">:</span>classname<span style="color: #339933;">,</span> rel<span style="color: #339933;">:</span>somevar<span style="color: #339933;">,</span> id<span style="color: #339933;">:</span>othervar<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><h3>Usage</h3><p> <code>htmlTag(tagName [, attributes [, content]])</code><br
/> or<br
/> <code>htmlTag(tagName [, content [, attributes]])</code></p><p>The function can be called with one, two or three arguments. Beside the first one which is the name of the tag (string), the other two are optional and can be placed in whatever order you like.<br
/> For <strong>img</strong> tags, the content argument is set as <i>src</i> attribute or as <i>value</i> attribute for <strong>input</strong> tags if the attributes argument doesn't specify otherwise</p><p><i>attributes</i> argument must be an object with key:value pairs and will be expanded as attributes of the tag<br
/> <i>content</i> argument is a string or number</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">    <span style="color: #003366; font-weight: bold;">var</span> classname <span style="color: #339933;">=</span> <span style="color: #3366CC;">'test'</span><span style="color: #339933;">,</span> somevar <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> id <span style="color: #339933;">=</span> <span style="color: #3366CC;">'mydiv'</span><span style="color: #339933;">,</span> content <span style="color: #339933;">=</span> <span style="color: #3366CC;">'hello'</span><span style="color: #339933;">;</span>
&nbsp;
    htmlTag<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #003366; font-weight: bold;">class</span><span style="color: #339933;">:</span>classname<span style="color: #339933;">,</span> rel<span style="color: #339933;">:</span>somevar<span style="color: #339933;">,</span> id<span style="color: #339933;">:</span>othervar<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    htmlTag<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> content<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #003366; font-weight: bold;">class</span><span style="color: #339933;">:</span>classname<span style="color: #339933;">,</span> rel<span style="color: #339933;">:</span>somevar<span style="color: #339933;">,</span> id<span style="color: #339933;">:</span>othervar<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// will both return &lt;div class='test' rel='2' id='mydiv'&gt;hello&lt;/div&gt;</span>
&nbsp;
    htmlTag<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img'</span><span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span>
    <span style="color: #006600; font-style: italic;">// &lt;img src='hello' /&gt;</span>
    htmlTag<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>src<span style="color: #339933;">:</span><span style="color: #3366CC;">'myImage.jpg'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span>
    <span style="color: #006600; font-style: italic;">// &lt;img src='myImage.jpg' /&gt; content is discarded and attributes src is used as source</span>
&nbsp;
    htmlTag<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>type<span style="color: #339933;">:</span><span style="color: #3366CC;">'text'</span><span style="color: #339933;">,</span> <span style="color: #000066;">name</span><span style="color: #339933;">:</span>id<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span>
    <span style="color: #006600; font-style: italic;">// &lt;input type=&quot;text&quot; name=&quot;mydiv&quot; value=&quot;hello&quot; /&gt;</span></pre></td></tr></table></div><h3>The code</h3><p></p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> htmlTag<span style="color: #009900;">&#40;</span>type<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> r<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&lt; &quot;</span><span style="color: #339933;">+</span>type<span style="color: #339933;">,</span>o<span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>v<span style="color: #339933;">=</span><span style="color: #3366CC;">''</span><span style="color: #339933;">,</span>x<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>a<span style="color: #339933;">=</span>arguments<span style="color: #339933;">;</span>
    a.<span style="color: #660066;">length</span><span style="color: #339933;">==</span><span style="color: #CC0000;">3</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">typeof</span> a<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'object'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>o<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span><span style="color: #339933;">-</span>~<span style="color: #339933;">!</span>x<span style="color: #009900;">&#93;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>v<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span><span style="color: #339933;">-</span>~x<span style="color: #009900;">&#93;</span><span style="color: #339933;">||</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span>a.<span style="color: #660066;">length</span><span style="color: #339933;">==</span><span style="color: #CC0000;">2</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> a<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'object'</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>o<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#40;</span>v<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">||</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</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><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">in</span> o<span style="color: #009900;">&#41;</span>r<span style="color: #339933;">+=</span><span style="color: #3366CC;">&quot; &quot;</span><span style="color: #339933;">+</span>i<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;='&quot;</span><span style="color: #339933;">+</span>o<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#40;</span>type<span style="color: #339933;">==</span><span style="color: #3366CC;">'img'</span><span style="color: #339933;">||</span>type<span style="color: #339933;">==</span><span style="color: #3366CC;">'br'</span><span style="color: #339933;">||</span>type<span style="color: #339933;">==</span><span style="color: #3366CC;">'input'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>o.<span style="color: #660066;">src</span><span style="color: #339933;">&amp;&amp;</span>v<span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>type<span style="color: #339933;">==</span><span style="color: #3366CC;">'img'</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>r<span style="color: #339933;">+=</span><span style="color: #3366CC;">&quot; src='&quot;</span><span style="color: #339933;">+</span>v<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;' /&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#40;</span>type<span style="color: #339933;">==</span><span style="color: #3366CC;">'input'</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>r<span style="color: #339933;">+=</span><span style="color: #3366CC;">&quot; value='&quot;</span><span style="color: #339933;">+</span>v<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;' /&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#40;</span>r<span style="color: #339933;">+=</span><span style="color: #3366CC;">' /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#40;</span>r<span style="color: #339933;">+=</span><span style="color: #3366CC;">&quot;&gt;&quot;</span><span style="color: #339933;">+</span>v<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt; &quot;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;/&quot;</span><span style="color: #339933;">+</span>type<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> r<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> queryTag<span style="color: #009900;">&#40;</span>type<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>htmlTag.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>queryTag function just wraps the newly created html in a jQuery object so you can have something like this</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">     $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#menu&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>
             queryTag<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #003366; font-weight: bold;">class</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'menuItem'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Click me'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                      <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'clicked'</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: #009900;">&#41;</span></pre></td></tr></table></div><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/' rel='bookmark' title='Permanent Link: Serialize JavaScript object to JSON'>Serialize JavaScript object to JSON</a></li><li><a
href='http://blog.another-d-mention.ro/programming/communicate-betwen-c-and-an-embeded-flash-application/' rel='bookmark' title='Permanent Link: Communicate betwen C# and an embeded Flash application'>Communicate betwen C# and an embeded Flash application</a></li><li><a
href='http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/' rel='bookmark' title='Permanent Link: JavaScript Object-Oriented Programming (OOP) &#8211; jClass'>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Read/Load files from ZIP in JavaScript</title><link>http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/</link> <comments>http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/#comments</comments> <pubDate>Fri, 01 Oct 2010 10:40:05 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[chrome]]></category> <category><![CDATA[firefox]]></category> <category><![CDATA[ie]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[load]]></category> <category><![CDATA[opera]]></category> <category><![CDATA[parse]]></category> <category><![CDATA[read]]></category> <category><![CDATA[safari]]></category> <category><![CDATA[zip]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=837</guid> <description><![CDATA[At work we do a lot of JavaScript applications that have little to no HTML files (beside the index), everything is generated by JavaScript and we have tons of .js files that load at runtime and to reduce the size we have to minify them and that is really hard to debug and watch in [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/' rel='bookmark' title='Permanent Link: Open and Save files to Desktop without going to Server'>Open and Save files to Desktop without going to Server</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/read-data-directly-from-base64-without-decoding/' rel='bookmark' title='Permanent Link: Read data directly from base64 without decoding'>Read data directly from base64 without decoding</a></li><li><a
href='http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/' rel='bookmark' title='Permanent Link: JavaScript Object-Oriented Programming (OOP) &#8211; jClass'>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</a></li></ol>]]></description> <content:encoded><![CDATA[<p>At work we do a lot of JavaScript applications that have little to no HTML files (beside the index), everything is generated by JavaScript and we have tons of .js files that load at runtime and to reduce the size we have to minify them and that is really hard to debug and watch in the browser if something goes wrong. So I've made this JavaScript class that comes to help. What can you do is Zip up all your assets (js, images, css) and use ZipLoader class to read the zip and unpack your resources whenever you need them. It's small (10KB), easy to use and quite fast considering the extraction is made by JavaScript.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">   <span style="color: #006600; font-style: italic;">// loads and caches the zip file</span>
   <span style="color: #003366; font-weight: bold;">var</span> loader <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ZipLoader<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'files.zip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #006600; font-style: italic;">// creates a style node in the document header and appends the style</span>
   loader.<span style="color: #660066;">LoadCSS</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'files.zip://style.css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #006600; font-style: italic;">// creates a script node in the document header and appends the script</span>
   loader.<span style="color: #660066;">loadScript</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'files.zip://jquery.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #006600; font-style: italic;">// returns the file content</span>
   <span style="color: #003366; font-weight: bold;">var</span> someFileYouNeed <span style="color: #339933;">=</span> loader.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;files.zip://myFile.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #006600; font-style: italic;">// returns the base64 encoded image usable as img source</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#logo&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span> loader.<span style="color: #660066;">loadImage</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'files.zip://images/logo.png'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>The level of compression using zip surpasses the js and css minification in all the ways possible. For example, My current application has 79 files (js, and few css) and they all sum up to 924KB in size. Zipping all those 96 files using Ultra compression level gives me 1 file of 126 KB => 1 server request. That's something.</p><p>The best performance is made Opera (strangely), then Firefox, Crome, Safari and last IE (no surprise here, I was expecting it before I even started).</p><p><del
datetime="2010-10-04T10:42:19+00:00">It's a V 1.0 that still needs some work and it doesn't work in IE because that stupid browser overrides the mime type and at first null character in the reading of the zip, the content ends. I will fix this eventually <img
src='http://blog.another-d-mention.ro/wp-includes/images/smilies/icon_smile.gif' alt="icon smile Read/Load files from ZIP in JavaScript" class='wp-smiley' title="Read/Load files from ZIP in JavaScript" /> </del> I will also include this as a <a
href="http://code.google.com/p/adm-jclass/">jClass</a> library soon.</p><p><strong>Update:</strong> Fixed it so it works in IE as well. There is a performance issue still. Will fix that too.</p><p>Till then, <a
href="http://another-d-mention.ro/apps/download.php?app=archive">HERE</a> are the sources and a demo.</p><p>The zip in the demo is made using <a
href="http://www.7-zip.org/">7Zip</a> with Ultra Compression level.</p><p>Happy codding.</p><p><a
class="FlattrButton" style="display:none;" href="http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/"></a><br
/> <noscript><a
href="http://flattr.com/thing/183347/ReadLoad-files-from-ZIP-in-JavaScript" target="_blank"><br
/> <img
src="http://api.flattr.com/button/flattr-badge-large.png" alt="flattr badge large Read/Load files from ZIP in JavaScript" title="Flattr this" border="0" /></a></noscript></p><p><script type="text/javascript">google_ad_client = "ca-pub-3771432957882119";
/* InsidePost */
google_ad_slot = "9112434755";
google_ad_width = 468;
google_ad_height = 60;</script><br
/> <script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></p><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/' rel='bookmark' title='Permanent Link: Open and Save files to Desktop without going to Server'>Open and Save files to Desktop without going to Server</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/read-data-directly-from-base64-without-decoding/' rel='bookmark' title='Permanent Link: Read data directly from base64 without decoding'>Read data directly from base64 without decoding</a></li><li><a
href='http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/' rel='bookmark' title='Permanent Link: JavaScript Object-Oriented Programming (OOP) &#8211; jClass'>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/feed/</wfw:commentRss> <slash:comments>50</slash:comments> </item> <item><title>Parse XML in JavaScript with jQuery</title><link>http://blog.another-d-mention.ro/programming/java-script/parse-xml-in-javascript-with-jquery/</link> <comments>http://blog.another-d-mention.ro/programming/java-script/parse-xml-in-javascript-with-jquery/#comments</comments> <pubDate>Tue, 28 Sep 2010 10:40:42 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[parse]]></category> <category><![CDATA[xml]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=836</guid> <description><![CDATA[Yes, you can do it with XMLDOM and all the other ways out there, but why not use the power of jQuery ? Like so: 1 2 3 4 5 6 7 &#60;root&#62; &#60;items&#62; &#60;item name=&#34;first&#34; id=&#34;1&#34;&#62;Content 1&#60;/item&#62; &#60;item name=&#34;second&#34; id=&#34;2&#34;&#62;Content 2&#60;/item&#62; &#60;/items&#62; &#60;other atribute=&#34;true&#34; /&#62; &#60;/root&#62; 1 2 3 4 var xml = '&#60;root [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/' rel='bookmark' title='Permanent Link: jQuery.quickEach'>jQuery.quickEach</a></li><li><a
href='http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/' rel='bookmark' title='Permanent Link: Read/Load files from ZIP in JavaScript'>Read/Load files from ZIP in JavaScript</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li></ol>]]></description> <content:encoded><![CDATA[<p>Yes, you can do it with XMLDOM and all the other ways out there, but why not use the power of jQuery ?<br
/> Like so:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td
class="code"><pre class="xml" style="font-family:monospace;">   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;root<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;first&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Content 1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;second&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Content 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;other</span> <span style="color: #000066;">atribute</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/root<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">   <span style="color: #003366; font-weight: bold;">var</span> xml <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;root ......'</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>xml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #006600; font-style: italic;">// and now you can use jquery selectors to get what you want</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;item[name=second]&quot;</span><span style="color: #339933;">,</span> obj<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 2</span></pre></td></tr></table></div><p></root></pre><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/' rel='bookmark' title='Permanent Link: jQuery.quickEach'>jQuery.quickEach</a></li><li><a
href='http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/' rel='bookmark' title='Permanent Link: Read/Load files from ZIP in JavaScript'>Read/Load files from ZIP in JavaScript</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/java-script/parse-xml-in-javascript-with-jquery/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</title><link>http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/</link> <comments>http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/#comments</comments> <pubDate>Mon, 06 Sep 2010 11:29:28 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[class]]></category> <category><![CDATA[extend]]></category> <category><![CDATA[interface]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jclass]]></category> <category><![CDATA[oop]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=834</guid> <description><![CDATA[I just finished working on a JavaScript 'framework' that will allow you to write highly object-oriented code in your browser. Using jClass you can easily define namespaces, create and extend class, define and implement interfaces, define public/private/static methods, override and overload them, have getters and setters, and so on. The syntax for writing code using [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/' rel='bookmark' title='Permanent Link: Serialize JavaScript object to JSON'>Serialize JavaScript object to JSON</a></li><li><a
href='http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/' rel='bookmark' title='Permanent Link: Read/Load files from ZIP in JavaScript'>Read/Load files from ZIP in JavaScript</a></li><li><a
href='http://blog.another-d-mention.ro/programming/how-to-clone-duplicate-an-object-in-actionscript-3/' rel='bookmark' title='Permanent Link: How to clone (duplicate) an object in ActionScript 3'>How to clone (duplicate) an object in ActionScript 3</a></li></ol>]]></description> <content:encoded><![CDATA[<p>I just finished working on a JavaScript 'framework' that will allow you to write highly object-oriented code in your browser.<br
/> Using jClass you can easily define namespaces, create and extend class, define and implement interfaces, define public/private/static methods, override and overload them, have getters and setters, and so on.</p><p>The syntax for writing code using jClass looks something like this</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">include<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;some.other.files&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;my.namespace&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    MyClass <span style="color: #339933;">:</span> jClass.<span style="color: #003366; font-weight: bold;">extends</span><span style="color: #009900;">&#40;</span>BaseClass<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">implements</span><span style="color: #009900;">&#40;</span>SomeInterf<span style="color: #339933;">,</span> SomeOtherInterf<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        constructor <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><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: #003366; font-weight: bold;">private</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
          ....
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
          ....
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        static <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
          ....
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    OtherClass <span style="color: #339933;">:</span> jClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
       ......
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div><p>I'm also working on some useful libraries that you can use with jClass.<br
/> Usage examples, documentation and downloads are all available on Google Code right <a
href="http://code.google.com/p/adm-jclass/"><strong>HERE</strong></a></p><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/' rel='bookmark' title='Permanent Link: Serialize JavaScript object to JSON'>Serialize JavaScript object to JSON</a></li><li><a
href='http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/' rel='bookmark' title='Permanent Link: Read/Load files from ZIP in JavaScript'>Read/Load files from ZIP in JavaScript</a></li><li><a
href='http://blog.another-d-mention.ro/programming/how-to-clone-duplicate-an-object-in-actionscript-3/' rel='bookmark' title='Permanent Link: How to clone (duplicate) an object in ActionScript 3'>How to clone (duplicate) an object in ActionScript 3</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>On typing finished jQuery plugin</title><link>http://blog.another-d-mention.ro/programming/java-script/on-typing-complete-jquery-plugin/</link> <comments>http://blog.another-d-mention.ro/programming/java-script/on-typing-complete-jquery-plugin/#comments</comments> <pubDate>Wed, 11 Aug 2010 08:06:01 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[event]]></category> <category><![CDATA[form]]></category> <category><![CDATA[input]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[plugin]]></category> <category><![CDATA[type]]></category> <category><![CDATA[validation]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=832</guid> <description><![CDATA[If you are developing a form and you require certain validations; check if username is available or not for example - the way to do that is to listen for the change/focusout DOM events. You can also check it on every keypress but if the validation does some expensive checking in the background that is [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/' rel='bookmark' title='Permanent Link: jQuery.quickEach'>jQuery.quickEach</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/parse-xml-in-javascript-with-jquery/' rel='bookmark' title='Permanent Link: Parse XML in JavaScript with jQuery'>Parse XML in JavaScript with jQuery</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li></ol>]]></description> <content:encoded><![CDATA[<p>If you are developing a form and you require certain validations; check if username is available or not for example - the way to do that is to listen for the change/focusout DOM events. You can also check it on every keypress but if the validation does some expensive checking in the background that is out of the question. So here is a really small jQuery plugin that does tell you when a user finished typing inside a text box. The way it does it is to compute the speed the user is typing with and when a delay longer than twice the speed average occurs, the event is triggered and your validation function is called. Simple enough.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">onTypeFinished</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>func<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #003366; font-weight: bold;">var</span> T <span style="color: #339933;">=</span> undefined<span style="color: #339933;">,</span> S <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> D <span style="color: #339933;">=</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">;</span>
     $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;keypress&quot;</span><span style="color: #339933;">,</span> onKeyPress<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;focusout&quot;</span><span style="color: #339933;">,</span> onTimeOut<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">function</span> onKeyPress<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        clearTimeout<span style="color: #009900;">&#40;</span>T<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>S <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> S <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> D <span style="color: #339933;">=</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">;</span> T <span style="color: #339933;">=</span> setTimeout<span style="color: #009900;">&#40;</span>onTimeOut<span style="color: #339933;">,</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
        <span style="color: #003366; font-weight: bold;">var</span> t <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        D <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>D <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>t <span style="color: #339933;">-</span> S<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span> S <span style="color: #339933;">=</span> t<span style="color: #339933;">;</span> T <span style="color: #339933;">=</span> setTimeout<span style="color: #009900;">&#40;</span>onTimeOut<span style="color: #339933;">,</span> D <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</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> onTimeOut<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           func.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> S <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>The way to use it:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[name='username']&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">onTypeFinished</span><span style="color: #009900;">&#40;</span>myValidationFunction<span style="color: #009900;">&#41;</span></pre></td></tr></table></div><p>And here is a small demo:<br
/> <iframe
src="http://cache.another-d-mention.ro/stuff/jquery/jquerytest.html" border="0" width="100%" height="100"></iframe></p><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/' rel='bookmark' title='Permanent Link: jQuery.quickEach'>jQuery.quickEach</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/parse-xml-in-javascript-with-jquery/' rel='bookmark' title='Permanent Link: Parse XML in JavaScript with jQuery'>Parse XML in JavaScript with jQuery</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/java-script/on-typing-complete-jquery-plugin/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>How to run python code in Windows batch (bat) files</title><link>http://blog.another-d-mention.ro/programming/how-to-run-python-code-in-windows-batch-bat-files/</link> <comments>http://blog.another-d-mention.ro/programming/how-to-run-python-code-in-windows-batch-bat-files/#comments</comments> <pubDate>Wed, 23 Jun 2010 12:58:05 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Programming]]></category> <category><![CDATA[Python]]></category> <category><![CDATA[bat]]></category> <category><![CDATA[batch]]></category> <category><![CDATA[code]]></category> <category><![CDATA[py]]></category> <category><![CDATA[window]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=829</guid> <description><![CDATA[Here’s the bit of tricky batch file magic that does it: 1 2 3 @setlocal enabledelayedexpansion &#38;&#38; python -x &#34;%~f0&#34; %* &#38; exit /b !ERRORLEVEL! #start python code here print &#34;hello world&#34; The way it works is that the first line of the file does two different things. 1. starts python interpreter passing the name [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/sudoku-solver-in-python/' rel='bookmark' title='Permanent Link: Sudoku solver in python'>Sudoku solver in python</a></li><li><a
href='http://blog.another-d-mention.ro/programming/python/quick-python-script-explanation/' rel='bookmark' title='Permanent Link: Quick Python Script Explanation'>Quick Python Script Explanation</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/' rel='bookmark' title='Permanent Link: Open and Save files to Desktop without going to Server'>Open and Save files to Desktop without going to Server</a></li></ol>]]></description> <content:encoded><![CDATA[<p>Here’s the bit of tricky batch file magic that does it:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
</pre></td><td
class="code"><pre class="python" style="font-family:monospace;">@setlocal enabledelayedexpansion <span style="color: #66cc66;">&amp;&amp;</span> python -x <span style="color: #483d8b;">&quot;%~f0&quot;</span> <span style="color: #66cc66;">%*</span> <span style="color: #66cc66;">&amp;</span> exit /b <span style="color: #66cc66;">!</span>ERRORLEVEL<span style="color: #66cc66;">!</span>
<span style="color: #808080; font-style: italic;">#start python code here</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;hello world&quot;</span></pre></td></tr></table></div><p>The way it works is that the first line of the file does two different things.</p><p>1. starts python interpreter passing the name of the file in, and the -x option will tell it to skip the first line (containing .bat file code)<br
/> 2. When python finishes the script exits.</p><p>This nifty trick makes it much nicer for writing admin scripts with python on Windows.</p><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/sudoku-solver-in-python/' rel='bookmark' title='Permanent Link: Sudoku solver in python'>Sudoku solver in python</a></li><li><a
href='http://blog.another-d-mention.ro/programming/python/quick-python-script-explanation/' rel='bookmark' title='Permanent Link: Quick Python Script Explanation'>Quick Python Script Explanation</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/' rel='bookmark' title='Permanent Link: Open and Save files to Desktop without going to Server'>Open and Save files to Desktop without going to Server</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/how-to-run-python-code-in-windows-batch-bat-files/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>FlashBuilder network issue</title><link>http://blog.another-d-mention.ro/programming/flashbuilder-network-issue/</link> <comments>http://blog.another-d-mention.ro/programming/flashbuilder-network-issue/#comments</comments> <pubDate>Fri, 21 May 2010 20:54:21 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Flex / ActionScript]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[amfphp]]></category> <category><![CDATA[flash builder]]></category> <category><![CDATA[flex]]></category> <category><![CDATA[monitor]]></category> <category><![CDATA[network]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=822</guid> <description><![CDATA[Like most of my articles here, I try to post solutions for unusual problems I encounter now and then that may help someone someday. And this one almost made me scream. So here's the story. My DEV environment (http://dev/) is a Virtual Host mapped in the Windows host file to point to a sandboxed directory [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/create-flexas3-applications-for-mobile-devices/' rel='bookmark' title='Permanent Link: Create Flex/AS3 applications for Mobile Devices'>Create Flex/AS3 applications for Mobile Devices</a></li><li><a
href='http://blog.another-d-mention.ro/programming/neural-networks-in-actionscript-3/' rel='bookmark' title='Permanent Link: Neural networks in ActionScript 3'>Neural networks in ActionScript 3</a></li><li><a
href='http://blog.another-d-mention.ro/programming/how-to-identify-at-runtime-if-swf-is-in-debug-or-release-mode-build/' rel='bookmark' title='Permanent Link: How to identify at runtime if the swf is in debug or release mode/build'>How to identify at runtime if the swf is in debug or release mode/build</a></li></ol>]]></description> <content:encoded><![CDATA[<p><img
class="alignleft size-thumbnail wp-image-823" style="margin-right: 10px; margin-bottom: 10px;" title="ARGHHHHHHHHHHHH" src="http://cache.another-d-mention.ro/images/wp-content/uploads/2010/05/girl-scream-150x150.jpg" alt="girl scream 150x150 FlashBuilder network issue" width="150" height="150" />Like most of my articles here, I try to post solutions for unusual problems I encounter now and then that may help someone someday. And this one almost made me scream.</p><p>So here's the story. My DEV environment (http://dev/) is a Virtual Host mapped in the Windows host file to point to a sandboxed directory somewhere on my hard drive. The Flex project I'm building uses a RemoteObject and tries to communicate with a AMFPHP gateway to do it's stuff. All good till here.</p><p>The weird part is that when I try to run the app, even though my flash is coming from the DEV host and the path to the gateway points to the same DEV host, the AMF calls either failed with a security exception or if they worked, they were extremely slow. The delay between a service call and a response/error was somewhere between 6 and 10 seconds.</p><p>Why oh why !? The AMFPHP Browser app that comes with the package works just fine so my app was at fault somehow. Tried some investigations and thanks to Firebug I found the vital clue.</p><p>It seems that my app was trying to make the connection to the gateway through <strong>http://localhost:37813/</strong>. WTF ?? I didn't had any reference to 'localhost' in my code, yet the app was trying to connect using that address for some reason. And quite often, the crossdomain.xml failed to load resulting in a security error.</p><p>So what in the world is the problem then ? Well, Flash Builder seems to be the problem (and me for not RTFM).</p><p>It seems that if you compile your swf with<strong> Network Monitor</strong> active, which you may not realize, especially if the window is not even opened, you have just told your swf to redirect all traffic to localhost:37813. It will compile the redirect info into your flash. Traffic may work if you have Flash Builder debugger running but try to deploy that somewhere. Heh.</p><p>All you have to do is turn network monitor off. Recompile your swf. Redeploy.</p><p>Ta da !</p><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/create-flexas3-applications-for-mobile-devices/' rel='bookmark' title='Permanent Link: Create Flex/AS3 applications for Mobile Devices'>Create Flex/AS3 applications for Mobile Devices</a></li><li><a
href='http://blog.another-d-mention.ro/programming/neural-networks-in-actionscript-3/' rel='bookmark' title='Permanent Link: Neural networks in ActionScript 3'>Neural networks in ActionScript 3</a></li><li><a
href='http://blog.another-d-mention.ro/programming/how-to-identify-at-runtime-if-swf-is-in-debug-or-release-mode-build/' rel='bookmark' title='Permanent Link: How to identify at runtime if the swf is in debug or release mode/build'>How to identify at runtime if the swf is in debug or release mode/build</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/flashbuilder-network-issue/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> </channel> </rss>
