<?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>Zenovation's Blog &#187; code clips</title>
	<atom:link href="http://zenovations.com/blog/tag/code-clips/feed/" rel="self" type="application/rss+xml" />
	<link>http://zenovations.com/blog</link>
	<description>A blog about web design, programming, hosting, and virtualmin hacks</description>
	<lastBuildDate>Mon, 16 Jan 2012 15:01:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Get elements by CSS class name in javascript</title>
		<link>http://zenovations.com/blog/2010/06/get-elements-by-css-class-name-in-javascript/</link>
		<comments>http://zenovations.com/blog/2010/06/get-elements-by-css-class-name-in-javascript/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 19:59:59 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[code clips]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://zenovations.com/blog/?p=195</guid>
		<description><![CDATA[Dustin Diaz wrote a nice, efficient version of getElementByClassName(), which searches HTML elements and retrieves all the items with a given CSS class specified. Of course, if you use a lib like extjs, jQuery, et al, then you have no need of this. But if you&#8217;re trying to hack out a greasemonkey script or insert [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.dustindiaz.com">Dustin Diaz</a> wrote a nice, efficient version of getElementByClassName(), which searches HTML elements and retrieves all the items with a given CSS class specified.</p>
<p>Of course, if you use a lib like extjs, jQuery, et al, then you have no need of this. But if you&#8217;re trying to hack out a greasemonkey script or insert some minimalist code, <a href="http://www.dustindiaz.com/getelementsbyclass/">here it is</a>.</p>
<p>And here it is, for my own archives:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p195code3'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1953"><td class="code" id="p195code3"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> getElementsByClass<span style="color: #009900;">&#40;</span>searchClass<span style="color: #339933;">,</span>node<span style="color: #339933;">,</span>tag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> classElements <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><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> node <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
		node <span style="color: #339933;">=</span> document<span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> tag <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
		tag <span style="color: #339933;">=</span> <span style="color: #3366CC;">'*'</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> els <span style="color: #339933;">=</span> node.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span>tag<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> elsLen <span style="color: #339933;">=</span> els.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> pattern <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;(^|<span style="color: #000099; font-weight: bold;">\\</span>s)&quot;</span><span style="color: #339933;">+</span>searchClass<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;(<span style="color: #000099; font-weight: bold;">\\</span>s|$)&quot;</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>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> j <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> elsLen<span style="color: #339933;">;</span> i<span style="color: #339933;">++</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> pattern.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>els<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">className</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			classElements<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> els<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			j<span style="color: #339933;">++;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> classElements<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Here&#8217;s another alternative I found on <a href="http://daniel.glazman.free.fr/weblog/">Glazblog</a>, using xpath to search the document:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p195code4'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1954"><td class="code" id="p195code4"><pre class="javascript" style="font-family:monospace;">document.<span style="color: #660066;">getElementByClassName</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>needle<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> xpathResult <span style="color: #339933;">=</span> document.<span style="color: #660066;">evaluate</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'//*[@class = needle]'</span><span style="color: #339933;">,</span> document<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> outArray <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>outArray<span style="color: #009900;">&#91;</span>outArray.<span style="color: #660066;">length</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> xpathResult.<span style="color: #660066;">iterateNext</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: #009900;">&#123;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">return</span> outArray<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>I don&#8217;t really know which is more efficient, though I suspect the xpath search could be taxing in very large documents. I&#8217;m positive, based on IE&#8217;s fake implementation of key/value pairs in the DOM, that they both suck in IE, even if you specify a specific tag type to search. Obviously, providing a node makes the regular expression search faster, by virtue of having less content to parse.</p>
]]></content:encoded>
			<wfw:commentRss>http://zenovations.com/blog/2010/06/get-elements-by-css-class-name-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding group/world writable files and directories in Linux</title>
		<link>http://zenovations.com/blog/2007/11/finding-groupworld-writable-files-and-directories-in-linux/</link>
		<comments>http://zenovations.com/blog/2007/11/finding-groupworld-writable-files-and-directories-in-linux/#comments</comments>
		<pubDate>Mon, 26 Nov 2007 17:30:51 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[code clips]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://zenovations.com/blog/2007/11/finding-groupworld-writable-files-and-directories-in-linux/</guid>
		<description><![CDATA[?View Code BASHfind / -type f \&#40; -perm -2 -o -perm -20 \&#41; -exec ls -lg &#123;&#125; \;]]></description>
			<content:encoded><![CDATA[
<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p105code6'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1056"><td class="code" id="p105code6"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-type</span> f \<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #660033;">-perm</span> <span style="color: #660033;">-2</span> <span style="color: #660033;">-o</span> <span style="color: #660033;">-perm</span> <span style="color: #660033;">-20</span> \<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-lg</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://zenovations.com/blog/2007/11/finding-groupworld-writable-files-and-directories-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CVS tunnel via CLI SSH</title>
		<link>http://zenovations.com/blog/2007/05/cvs-tunnel-via-cli-ssh/</link>
		<comments>http://zenovations.com/blog/2007/05/cvs-tunnel-via-cli-ssh/#comments</comments>
		<pubDate>Sat, 05 May 2007 08:55:25 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[code clips]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://zenovations.com/blog/2007/05/cvs-tunnel-via-cli-ssh/</guid>
		<description><![CDATA[?View Code BASH/usr/bin/ssh -v -a -L 2401:localhost:2401 cvsnobody@ns2.cyterm.com]]></description>
			<content:encoded><![CDATA[
<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p99code8'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p998"><td class="code" id="p99code8"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-L</span> <span style="color: #000000;">2401</span>:localhost:<span style="color: #000000;">2401</span>  cvsnobody<span style="color: #000000; font-weight: bold;">@</span>ns2.cyterm.com</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://zenovations.com/blog/2007/05/cvs-tunnel-via-cli-ssh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

