<?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>BitBonsai Labs &#187; snippet</title>
	<atom:link href="http://www.bitbonsai.com/category/snippet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bitbonsai.com</link>
	<description>Mauricio Wolff&#039;s geekness</description>
	<lastBuildDate>Fri, 27 Aug 2010 20:30:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Testing pastie.org embed</title>
		<link>http://www.bitbonsai.com/testing-pastie-org-embed/</link>
		<comments>http://www.bitbonsai.com/testing-pastie-org-embed/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 12:25:05 +0000</pubDate>
		<dc:creator>mw</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.bitbonsai.com/?p=229</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><script src='http://pastie.org/1023253.js'></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bitbonsai.com/testing-pastie-org-embed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JS Tip: Revealing Module Pattern</title>
		<link>http://www.bitbonsai.com/revealing-module-pattern/</link>
		<comments>http://www.bitbonsai.com/revealing-module-pattern/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 17:59:00 +0000</pubDate>
		<dc:creator>mw</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.bitbonsai.com/?p=217</guid>
		<description><![CDATA[From Christian Heilmann. Nothing too fancy for those who are used to write jQ plugins, but nice to save it for reference... var myApp = function&#40;&#41;&#123; var nome = 'Mauricio Wolff'; var idade = 35; &#160; function insertPessoa&#40;&#41;&#123; // [...] &#125; &#160; function updatePessoa&#40;&#41;&#123; // [...] &#125; &#160; function setPessoa &#40;&#41; &#123; // [ usa [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>From Christian Heilmann. Nothing too fancy for those who are used to write jQ plugins, but nice to save it for reference...</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myApp <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: #003366; font-weight: bold;">var</span> nome <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Mauricio Wolff'</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> idade <span style="color: #339933;">=</span> <span style="color: #CC0000;">35</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> insertPessoa<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// [...]</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> updatePessoa<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// [...]</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> setPessoa <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// [ usa insert ou update ]</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> getPessoa <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// [...]</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#123;</span>
		set<span style="color: #339933;">:</span> setPessoa<span style="color: #339933;">,</span>
		get<span style="color: #339933;">:</span> getPessoa
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Example usage:</span>
myApp.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</div>
]]></content:encoded>
			<wfw:commentRss>http://www.bitbonsai.com/revealing-module-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python x PHP: Finding IPs with regex</title>
		<link>http://www.bitbonsai.com/python-php-vs-find-ip-with-regex/</link>
		<comments>http://www.bitbonsai.com/python-php-vs-find-ip-with-regex/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 12:09:47 +0000</pubDate>
		<dc:creator>mw</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.bitbonsai.com/?p=147</guid>
		<description><![CDATA[Sometimes I just like to write code in Python and PHP to compare them, and admire both... Here's a little code to find IP adressess inside strings (returned from a nslookup). The code is not optimal, but illustrate how both languages works. Just for some friday fun... Python &#160; Python 2.6.1 &#40;r261:67515, Jul  7 2009, [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes I just like to write code in Python and PHP to compare them, and admire both...</p>
<p>Here's a little code to find IP adressess inside strings (returned from a nslookup). The code is not optimal, but illustrate how both languages works. Just for some friday fun...</p>
<h3>Python</h3>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
Python 2.6.1 <span style="color: black;">&#40;</span>r261:<span style="color: #ff4500;">67515</span>, Jul  <span style="color: #ff4500;">7</span> <span style="color: #ff4500;">2009</span>,  <span style="color: #ff4500;">23</span>:<span style="color: #ff4500;">51</span>:<span style="color: #ff4500;">51</span><span style="color: black;">&#41;</span>
 <span style="color: black;">&#91;</span>GCC 4.2.1 <span style="color: black;">&#40;</span>Apple Inc. <span style="color: black;">build</span> <span style="color: #ff4500;">5646</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> on darwin
 Type <span style="color: #483d8b;">&quot;help&quot;</span>, <span style="color: #483d8b;">&quot;copyright&quot;</span>, <span style="color: #483d8b;">&quot;credits&quot;</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #483d8b;">&quot;license&quot;</span>  <span style="color: #ff7700;font-weight:bold;">for</span>  more information.
&nbsp;
<span style="color: #66cc66;">&gt;&gt;&gt;</span> a  = <span style="color: #483d8b;">'yahoo.com IN A 69.147.114.224 18774s  (05:12:54)'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> a += <span style="color: #483d8b;">'yahoo.com IN A 209.131.36.159 18774s  (05:12:54)'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> a += <span style="color: #483d8b;">'yahoo.com IN A 209.191.93.53  18774s  (05:12:54)'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> a
 <span style="color: #483d8b;">'yahoo.com IN A 69.147.114.224  18774s (05:12:54)yahoo.com IN A 209.131.36.159 18774s  (05:12:54)yahoo.com IN A 209.191.93.53  18774s (05:12:54)'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;;</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> p = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'(?:<span style="color: #000099; font-weight: bold;">\d</span>{1,3}<span style="color: #000099; font-weight: bold;">\.</span>){3}<span style="color: #000099; font-weight: bold;">\d</span>{1,3}'</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;;</span> p.<span style="color: black;">findall</span><span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>
 <span style="color: black;">&#91;</span><span style="color: #483d8b;">'69.147.114.224'</span>, <span style="color: #483d8b;">'209.131.36.159'</span>,  <span style="color: #483d8b;">'209.191.93.53'</span><span style="color: black;">&#93;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span></pre></div></div>

<h3>PHP</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$a</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'yahoo.com IN A 69.147.114.224 18774s (05:12:54)'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'yahoo.com  IN A 209.131.36.159 18774s (05:12:54)'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'yahoo.com  IN A 209.191.93.53  18774s (05:12:54)'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">print</span> <span style="color: #000088;">$a</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
saida: yahoo.com IN A 69.147.114.224 18774s (05:12:54)yahoo.com IN A  209.131.36.159 18774s (05:12:54)yahoo.com IN A 209.191.93.53 18774s  (05:12:54)
*/</span>
&nbsp;
<span style="color: #000088;">$re</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/(\d+).(\d+).(\d+).(\d+)/'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$re</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// saida 1</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// saida 2</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
saida 1:
&nbsp;
array(3) {
  [0]=&gt;
  string(14) &quot;69.147.114.224&quot;
  [1]=&gt;
  string(14) &quot;209.131.36.159&quot;
  [2]=&gt;
  string(13) &quot;209.191.93.53&quot;
}
&nbsp;
saida 2:
&nbsp;
array(5) {
  [0]=&gt;
  array(3) {
    [0]=&gt;
    string(14) &quot;69.147.114.224&quot;
    [1]=&gt;
    string(14) &quot;209.131.36.159&quot;
    [2]=&gt;
    string(13) &quot;209.191.93.53&quot;
  }
  [1]=&gt;
  array(3) {
    [0]=&gt;
    string(2) &quot;69&quot;
    [1]=&gt;
    string(3) &quot;209&quot;
    [2]=&gt;
    string(3) &quot;209&quot;
  }
  [2]=&gt;
  array(3) {
    [0]=&gt;
    string(3) &quot;147&quot;
    [1]=&gt;
    string(3) &quot;131&quot;
    [2]=&gt;
    string(3) &quot;191&quot;
  }
  [3]=&gt;
  array(3) {
    [0]=&gt;
    string(3) &quot;114&quot;
    [1]=&gt;
    string(2) &quot;36&quot;
    [2]=&gt;
    string(2) &quot;93&quot;
  }
  [4]=&gt;
  array(3) {
    [0]=&gt;
    string(3) &quot;224&quot;
    [1]=&gt;
    string(3) &quot;159&quot;
    [2]=&gt;
    string(2) &quot;53&quot;
  }
}
*/</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bitbonsai.com/python-php-vs-find-ip-with-regex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Porque adoro jQuery</title>
		<link>http://www.bitbonsai.com/porque-adoro-jquery/</link>
		<comments>http://www.bitbonsai.com/porque-adoro-jquery/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 08:10:54 +0000</pubDate>
		<dc:creator>mw</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.bitbonsai.com/?p=140</guid>
		<description><![CDATA[Pedido: Fazer com que todos os links de uma determinada página sejam externos. Abordagem 1: Alterar a classe em php, genérica, para ver se o link é externo e acrescentar o target; por regex. Abordagem 2: Colocar no init.js $&#40;&#34;a[href^='http://']&#34;&#41;.attr&#40;&#34;target&#34;,&#34;_blank&#34;&#41;; E todo site fica assim; links externos, para fora! Aff... que doce.]]></description>
			<content:encoded><![CDATA[<p>Pedido: Fazer com que todos os links de uma determinada página sejam externos.</p>
<ul>
<li>Abordagem 1: Alterar a classe em php, genérica, para ver se o link é externo e acrescentar o target; por regex.</li>
<li>Abordagem 2: Colocar no init.js</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a[href^='http://']&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;target&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;_blank&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>E todo site fica assim; links externos, para fora!<br />
Aff... que doce.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bitbonsai.com/porque-adoro-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>recursively chmod only subdirectories</title>
		<link>http://www.bitbonsai.com/chmod-dirs-fix/</link>
		<comments>http://www.bitbonsai.com/chmod-dirs-fix/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 14:10:00 +0000</pubDate>
		<dc:creator>mw</dc:creator>
				<category><![CDATA[snippet]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.bitbonsai.com/?p=130</guid>
		<description><![CDATA[When I use Betterzip to uncompress a directory tree, it chmods the dirs with 700. Here's the command to solve this: find . -type d &#124; xargs chmod 755 It finds all subdirectories and chmod'em to 755. Clever, isn't it?]]></description>
			<content:encoded><![CDATA[<p>When I use Betterzip to uncompress a directory tree, it chmods the dirs with 700. Here's the command to solve this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> d <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">755</span></pre></div></div>

<p>It finds all subdirectories and chmod'em to 755. Clever, isn't it?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bitbonsai.com/chmod-dirs-fix/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Deletar .svn recursivamente</title>
		<link>http://www.bitbonsai.com/deletar-svn-recursivamente/</link>
		<comments>http://www.bitbonsai.com/deletar-svn-recursivamente/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 03:39:32 +0000</pubDate>
		<dc:creator>mw</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://www.bitbonsai.com/?p=128</guid>
		<description><![CDATA[Desde que comecei a usar GIT acho svn clumsy... prefiro jogar os arquivos no dropbox, que ele guarda versões pra mim. Agora resolvi detonar todos os .svn de um trabalho que estou fazendo. Chega de xalassa... criar um bash script básico para remover os .svn recursivos salvar no meu ~/bin e dar chmod +x rodar [...]]]></description>
			<content:encoded><![CDATA[<p>Desde que comecei a usar <a href="http://git-scm.com/" target="_blank">GIT</a> acho svn clumsy... prefiro jogar os arquivos no <a href="http://dropbox.com" target="_blank">dropbox</a>, que ele guarda versões pra mim.</p>
<p>Agora resolvi detonar todos os .svn de um trabalho que estou fazendo. Chega de xalassa...</p>
<ol>
<li>criar um bash script básico para remover os .svn recursivos</li>
<li>salvar no meu ~/bin e dar chmod +x</li>
<li>rodar e ser feliz.</li>
</ol>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 48px; width: 1px; height: 1px;">#!/bin/sh</div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 48px; width: 1px; height: 1px;">echo "recursively removing .svn folders from"</div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 48px; width: 1px; height: 1px;">pwd</div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 48px; width: 1px; height: 1px;">rm -rf `find . -type d -name .svn`</div>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;recursively removing .svn folders from&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">pwd</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> d <span style="color: #660033;">-name</span> .svn<span style="color: #000000; font-weight: bold;">`</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bitbonsai.com/deletar-svn-recursivamente/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lifesaver snippets</title>
		<link>http://www.bitbonsai.com/lifesaver-snippets/</link>
		<comments>http://www.bitbonsai.com/lifesaver-snippets/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 18:56:15 +0000</pubDate>
		<dc:creator>mw</dc:creator>
				<category><![CDATA[snippet]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[geek]]></category>

		<guid isPermaLink="false">http://www.bitbonsai.com/lifesaver-snippets/</guid>
		<description><![CDATA[Alguns códigos são simplesmente salvadores da pátria... Por exemplo: Tens de subir um site por 3g, e mesmo targzipando o site ele fica com 12Mb por causa dos .svn escondidos... tar --exclude='.svn' -czvf file.tar.gz ./* 6MB. Simples e eficaz...]]></description>
			<content:encoded><![CDATA[<p>Alguns códigos são simplesmente salvadores da pátria...</p>
<p>Por exemplo: Tens de subir um site por 3g, e mesmo targzipando o site ele fica com 12Mb por causa dos .svn escondidos...</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">--exclude</span>=<span style="color: #ff0000;">'.svn'</span> <span style="color: #660033;">-czvf</span> file.tar.gz .<span style="color: #000000; font-weight: bold;">/*</span></pre></div></div>

<p>6MB. Simples e eficaz...</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bitbonsai.com/lifesaver-snippets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
