<?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>Vidul Nikolaev Petrov &#187; Ruby</title>
	<atom:link href="http://www.vidul.com/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vidul.com</link>
	<description>my web space</description>
	<lastBuildDate>Wed, 11 Aug 2010 06:22:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Alphabet</title>
		<link>http://www.vidul.com/2009/10/20/the-alphabet/</link>
		<comments>http://www.vidul.com/2009/10/20/the-alphabet/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 17:35:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[chars]]></category>

		<guid isPermaLink="false">urn:uuid:{a.guid}</guid>
		<description><![CDATA[Python


import re
&#160;
_char = re.compile&#40;r'\w'&#41;
&#160;
''.join&#40;&#91;chr&#40;i&#41; for i in xrange&#40;65,122&#41; if _char.match&#40;chr&#40;i&#41;&#41;&#93;&#41;
&#160;
# or just:
import string
&#160;
string.ascii_letters
string.ascii_lowercase
string.ascii_uppercase


Ruby


&#40;65..122&#41;.to_a.map&#123; &#124;e&#124; e.chr =~ /\w/ &#38;&#38; e.chr &#125;.compact.to_s


Perl


$chars .= chr&#40;&#41; =~ /\w/ ? chr&#40;&#41; : q&#123;&#125; for 65..122;


I don&#8217;t like the mess of Ruby, and Perl.





		
			Share this on Blinklist
		
		
			Share this on del.icio.us
		
		
			Digg this!
		
		
			Share this on Reddit
		
		
			Stumble upon something good? Share it on StumbleUpon
		
		
			Share [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Python</strong></p>
<div class="typocode">

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:arial,verdana,monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
&nbsp;
_char = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\w</span>'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #483d8b;">''</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #008000;">chr</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">65</span>,<span style="color: #ff4500;">122</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">if</span> _char.<span style="color: black;">match</span><span style="color: black;">&#40;</span><span style="color: #008000;">chr</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># or just:</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">string</span>
&nbsp;
<span style="color: #dc143c;">string</span>.<span style="color: black;">ascii_letters</span>
<span style="color: #dc143c;">string</span>.<span style="color: black;">ascii_lowercase</span>
<span style="color: #dc143c;">string</span>.<span style="color: black;">ascii_uppercase</span></pre></div></div>

</div>
<p><strong>Ruby</strong></p>
<div class="typocode">

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;"><span style="color:#006600; font-weight:bold;">&#40;</span>65..122<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_a</span>.<span style="color:#9900CC;">map</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>e<span style="color:#006600; font-weight:bold;">|</span> e.<span style="color:#9900CC;">chr</span> =~ <span style="color:#006600; font-weight:bold;">/</span>\w<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> e.<span style="color:#9900CC;">chr</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">compact</span>.<span style="color:#9900CC;">to_s</span></pre></div></div>

</div>
<p><strong>Perl</strong></p>
<div class="typocode">

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:arial,verdana,monospace;"><span style="color: #0000ff;">$chars</span> <span style="color: #339933;">.=</span> <span style="color: #000066;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/\w/</span> <span style="color: #339933;">?</span> <span style="color: #000066;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000066;">q</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">for</span> 65<span style="color: #339933;">..</span>122<span style="color: #339933;">;</span></pre></div></div>

</div>
<p>I don&#8217;t like the mess of Ruby, and Perl.</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.vidul.com/2009/10/20/the-alphabet/&amp;Title=The+Alphabet" rel="nofollow" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vidul.com/2009/10/20/the-alphabet/&amp;title=The+Alphabet" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.vidul.com/2009/10/20/the-alphabet/&amp;title=The+Alphabet" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.vidul.com/2009/10/20/the-alphabet/&amp;title=The+Alphabet" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.vidul.com/2009/10/20/the-alphabet/&amp;title=The+Alphabet" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.vidul.com/2009/10/20/the-alphabet/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=The+Alphabet+-+http://b2l.me/bj3dt+" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-newsvine">
			<a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.vidul.com/2009/10/20/the-alphabet/&amp;h=The+Alphabet" rel="nofollow" title="Seed this on Newsvine">Seed this on Newsvine</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.vidul.com/2009/10/20/the-alphabet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to sort a file by its columns</title>
		<link>http://www.vidul.com/2009/06/04/how-to-sort-a-file-by-its-columns/</link>
		<comments>http://www.vidul.com/2009/06/04/how-to-sort-a-file-by-its-columns/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 02:29:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[sorting]]></category>

		<guid isPermaLink="false">urn:uuid:{a.guid}</guid>
		<description><![CDATA[
# sort by user id
ruby -a -F: -ne 'puts $F.values_at(2, 0).join(&#34;\t&#34;)' '/etc/passwd' &#124; sort -g
&#160;
# sort by user home directory
ruby -a -F: -ne 'puts $F.values_at(5, 0).join(&#34;\t&#34;)' '/etc/passwd' &#124; sort -g
&#160;
# sort by username
ruby -a -F: -ne 'puts $F.values_at(0).join(&#34;\t&#34;)' '/etc/passwd' &#124; sort -g






		
			Share this on Blinklist
		
		
			Share this on del.icio.us
		
		
			Digg this!
		
		
			Share this on Reddit
		
		
			Stumble upon something good? [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:arial,verdana,monospace;"><span style="color: #666666; font-style: italic;"># sort by user id</span>
ruby <span style="color: #660033;">-a</span> -F: <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">'puts $F.values_at(2, 0).join(&quot;\t&quot;)'</span> <span style="color: #ff0000;">'/etc/passwd'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-g</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># sort by user home directory</span>
ruby <span style="color: #660033;">-a</span> -F: <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">'puts $F.values_at(5, 0).join(&quot;\t&quot;)'</span> <span style="color: #ff0000;">'/etc/passwd'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-g</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># sort by username</span>
ruby <span style="color: #660033;">-a</span> -F: <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">'puts $F.values_at(0).join(&quot;\t&quot;)'</span> <span style="color: #ff0000;">'/etc/passwd'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-g</span></pre></div></div>



<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.vidul.com/2009/06/04/how-to-sort-a-file-by-its-columns/&amp;Title=How+to+sort+a+file+by+its+columns" rel="nofollow" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vidul.com/2009/06/04/how-to-sort-a-file-by-its-columns/&amp;title=How+to+sort+a+file+by+its+columns" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.vidul.com/2009/06/04/how-to-sort-a-file-by-its-columns/&amp;title=How+to+sort+a+file+by+its+columns" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.vidul.com/2009/06/04/how-to-sort-a-file-by-its-columns/&amp;title=How+to+sort+a+file+by+its+columns" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.vidul.com/2009/06/04/how-to-sort-a-file-by-its-columns/&amp;title=How+to+sort+a+file+by+its+columns" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.vidul.com/2009/06/04/how-to-sort-a-file-by-its-columns/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=How+to+sort+a+file+by+its+columns+-+http://b2l.me/bj3dx+" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-newsvine">
			<a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.vidul.com/2009/06/04/how-to-sort-a-file-by-its-columns/&amp;h=How+to+sort+a+file+by+its+columns" rel="nofollow" title="Seed this on Newsvine">Seed this on Newsvine</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.vidul.com/2009/06/04/how-to-sort-a-file-by-its-columns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Ruby Text Parser</title>
		<link>http://www.vidul.com/2009/03/20/simple-ruby-text-parser/</link>
		<comments>http://www.vidul.com/2009/03/20/simple-ruby-text-parser/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 16:42:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[parser]]></category>

		<guid isPermaLink="false">urn:uuid:{a.guid}</guid>
		<description><![CDATA[
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
filename = &#34;sample records.txt&#34;
file = File.open&#40;filename&#41;
data = &#91;&#93;
record = &#123;&#125;
&#160;
class MyParse
  Tokens = &#91;
    ### change the regular expressions accordingly ###
    ### sale date, sale time, sale address,
    &#91;/^Sale:\s*&#40;\d+\/\d+\/\d+&#41;\s+&#40;\S+\s+\w\w&#41;\s+&#40;.+?&#41;\s*$/,
        lambda &#123; &#124;m&#124; m.to_a &#38;&#38;
     [...]]]></description>
			<content:encoded><![CDATA[
<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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;">filename = <span style="color:#996600;">&quot;sample records.txt&quot;</span>
file = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>filename<span style="color:#006600; font-weight:bold;">&#41;</span>
data = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
record = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> MyParse
  Tokens = <span style="color:#006600; font-weight:bold;">&#91;</span>
    <span style="color:#008000; font-style:italic;">### change the regular expressions accordingly ###</span>
    <span style="color:#008000; font-style:italic;">### sale date, sale time, sale address,</span>
    <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">/</span>^Sale:\s<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span>\d<span style="color:#006600; font-weight:bold;">+</span>\<span style="color:#006600; font-weight:bold;">/</span>\d<span style="color:#006600; font-weight:bold;">+</span>\<span style="color:#006600; font-weight:bold;">/</span>\d<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span>\s<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#40;</span>\S<span style="color:#006600; font-weight:bold;">+</span>\s<span style="color:#006600; font-weight:bold;">+</span>\w\w<span style="color:#006600; font-weight:bold;">&#41;</span>\s<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#40;</span>.<span style="color:#006600; font-weight:bold;">+</span>?<span style="color:#006600; font-weight:bold;">&#41;</span>\s<span style="color:#006600; font-weight:bold;">*</span>$<span style="color:#006600; font-weight:bold;">/</span>,
        <span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>m<span style="color:#006600; font-weight:bold;">|</span> m.<span style="color:#9900CC;">to_a</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span>
            <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;sale date&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>m<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#996600;">&quot;sale time&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>m<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#996600;">&quot;sale address&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>m<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
    <span style="color:#008000; font-style:italic;">### seller name, seller time, seller address</span>
    <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">/</span>^Seller:\s<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span>\d<span style="color:#006600; font-weight:bold;">+</span>\<span style="color:#006600; font-weight:bold;">/</span>\d<span style="color:#006600; font-weight:bold;">+</span>\<span style="color:#006600; font-weight:bold;">/</span>\d<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span>\s<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#40;</span>\S<span style="color:#006600; font-weight:bold;">+</span>\s<span style="color:#006600; font-weight:bold;">+</span>\w\w<span style="color:#006600; font-weight:bold;">&#41;</span>\s<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#40;</span>.<span style="color:#006600; font-weight:bold;">+</span>?<span style="color:#006600; font-weight:bold;">&#41;</span>\s<span style="color:#006600; font-weight:bold;">*</span>$<span style="color:#006600; font-weight:bold;">/</span>,
        <span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>m<span style="color:#006600; font-weight:bold;">|</span> m.<span style="color:#9900CC;">to_a</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span>
            <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;seller date&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>m<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#996600;">&quot;seller time&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>m<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#996600;">&quot;seller address&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>m<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
    <span style="color:#008000; font-style:italic;">### Trustor: trustor</span>
    <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">/</span>^Trustor:\s<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#40;</span>.<span style="color:#006600; font-weight:bold;">+</span>?<span style="color:#006600; font-weight:bold;">&#41;</span>\s<span style="color:#006600; font-weight:bold;">*</span>$<span style="color:#006600; font-weight:bold;">/</span>,
        <span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>m<span style="color:#006600; font-weight:bold;">|</span> m.<span style="color:#9900CC;">to_a</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;trustor&quot;</span><span style="color:#006600; font-weight:bold;">=&gt;</span>m<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
  <span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span>text<span style="color:#006600; font-weight:bold;">&#41;</span>
    parse<span style="color:#006600; font-weight:bold;">&#40;</span>text<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  protected
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>text<span style="color:#006600; font-weight:bold;">&#41;</span>
    text.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>line<span style="color:#006600; font-weight:bold;">|</span>
      Tokens.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>token<span style="color:#006600; font-weight:bold;">|</span>
        <span style="color:#9966CC; font-weight:bold;">if</span> m = token.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span>line<span style="color:#006600; font-weight:bold;">&#41;</span>
          <span style="color:#0000FF; font-weight:bold;">return</span> token.<span style="color:#9900CC;">last</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span>m<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#0000FF; font-weight:bold;">nil</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">begin</span>
  <span style="color:#9966CC; font-weight:bold;">while</span> line = file.<span style="color:#CC0066; font-weight:bold;">readline</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> line.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>^\s<span style="color:#006600; font-weight:bold;">*</span>$<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      record = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#9966CC; font-weight:bold;">next</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    line.<span style="color:#CC0066; font-weight:bold;">sub!</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;<span style="color:#000099;">\r</span>&quot;</span>, <span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> record = MyParse.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span>line<span style="color:#006600; font-weight:bold;">&#41;</span>
      data.<span style="color:#9900CC;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span>record<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">EOFError</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;'#{filename}': #{e}&quot;</span>
<span style="color:#9966CC; font-weight:bold;">ensure</span>
  file.<span style="color:#9900CC;">close</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> data.<span style="color:#9900CC;">inspect</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">exit</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>



<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.vidul.com/2009/03/20/simple-ruby-text-parser/&amp;Title=Simple+Ruby+Text+Parser" rel="nofollow" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vidul.com/2009/03/20/simple-ruby-text-parser/&amp;title=Simple+Ruby+Text+Parser" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.vidul.com/2009/03/20/simple-ruby-text-parser/&amp;title=Simple+Ruby+Text+Parser" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.vidul.com/2009/03/20/simple-ruby-text-parser/&amp;title=Simple+Ruby+Text+Parser" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.vidul.com/2009/03/20/simple-ruby-text-parser/&amp;title=Simple+Ruby+Text+Parser" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.vidul.com/2009/03/20/simple-ruby-text-parser/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Simple+Ruby+Text+Parser+-+http://b2l.me/bj3dz+" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-newsvine">
			<a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.vidul.com/2009/03/20/simple-ruby-text-parser/&amp;h=Simple+Ruby+Text+Parser" rel="nofollow" title="Seed this on Newsvine">Seed this on Newsvine</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.vidul.com/2009/03/20/simple-ruby-text-parser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to download an image from flickr</title>
		<link>http://www.vidul.com/2009/03/11/howto-download-an-image-from-flickr/</link>
		<comments>http://www.vidul.com/2009/03/11/howto-download-an-image-from-flickr/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 21:10:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">urn:uuid:{a.guid}</guid>
		<description><![CDATA[I wasn’t able to download a photo from flickr. It happened to be 1px transparent image over the other. Here is a simple scaper in cases of such “protection”:

1
2
3
4
5
6
7
8
9
10
11
12
require 'rubygems'
require 'www/mechanize'
&#160;
url = 'http://www.flickr.com/photos/46457493@N00/3162339409/in/set-72157612102050814/'
&#160;
my_id = url.split&#40;&#34;/&#34;&#41;&#91;-3&#93;
agent  = WWW::Mechanize.new
page   = agent.get&#40;url&#41;
&#160;
url   = page.search&#40;&#34;//div[@id='photoImgDiv#{my_id}']/img&#34;&#41;.attr&#40;'src'&#41;
&#160;
agent.get&#40;url&#41;.save_as&#40;&#40;File.basename&#40;url&#41;&#41;.split&#40;&#34;?&#34;&#41;&#91;0&#93;&#41;






		
			Share this on Blinklist
		
		
			Share this on del.icio.us
		
		
			Digg this!
		
		
			Share this on [...]]]></description>
			<content:encoded><![CDATA[<p>I wasn’t able to download a photo from flickr. It happened to be 1px transparent image over the other. Here is a simple scaper in cases of such <a href="http://en.wikipedia.org/wiki/Security_through_obscurity">“protection”</a>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'www/mechanize'</span>
&nbsp;
url = <span style="color:#996600;">'http://www.flickr.com/photos/46457493@N00/3162339409/in/set-72157612102050814/'</span>
&nbsp;
my_id = url.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;/&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>
agent  = <span style="color:#6666ff; font-weight:bold;">WWW::Mechanize</span>.<span style="color:#9900CC;">new</span>
page   = agent.<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span>url<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
url   = page.<span style="color:#9900CC;">search</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;//div[@id='photoImgDiv#{my_id}']/img&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">attr</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'src'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
agent.<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span>url<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">save_as</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">basename</span><span style="color:#006600; font-weight:bold;">&#40;</span>url<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;?&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>



<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.vidul.com/2009/03/11/howto-download-an-image-from-flickr/&amp;Title=How+to+download+an+image+from+flickr" rel="nofollow" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vidul.com/2009/03/11/howto-download-an-image-from-flickr/&amp;title=How+to+download+an+image+from+flickr" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.vidul.com/2009/03/11/howto-download-an-image-from-flickr/&amp;title=How+to+download+an+image+from+flickr" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.vidul.com/2009/03/11/howto-download-an-image-from-flickr/&amp;title=How+to+download+an+image+from+flickr" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.vidul.com/2009/03/11/howto-download-an-image-from-flickr/&amp;title=How+to+download+an+image+from+flickr" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.vidul.com/2009/03/11/howto-download-an-image-from-flickr/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=How+to+download+an+image+from+flickr+-+http://b2l.me/bwbpe+" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-newsvine">
			<a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.vidul.com/2009/03/11/howto-download-an-image-from-flickr/&amp;h=How+to+download+an+image+from+flickr" rel="nofollow" title="Seed this on Newsvine">Seed this on Newsvine</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.vidul.com/2009/03/11/howto-download-an-image-from-flickr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Filtering Lists</title>
		<link>http://www.vidul.com/2008/12/01/filtering-lists/</link>
		<comments>http://www.vidul.com/2008/12/01/filtering-lists/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 08:33:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[list]]></category>

		<guid isPermaLink="false">urn:uuid:{a.guid}</guid>
		<description><![CDATA[Ruby

arr = &#40;1..10&#41;.to_a
arr.select&#123; &#124;e&#124; e % 2 != 0 &#125;

Python

arr = range&#40;1,11&#41;
&#91;e for e in arr if e % 2&#93;

Perl

@arr = &#40;1..10&#41;;
grep&#40;$_ % 2, @arr&#41;;






		
			Share this on Blinklist
		
		
			Share this on del.icio.us
		
		
			Digg this!
		
		
			Share this on Reddit
		
		
			Stumble upon something good? Share it on StumbleUpon
		
		
			Share this on Technorati
		
		
			Tweet This!
		
		
			Seed this on Newsvine
		





]]></description>
			<content:encoded><![CDATA[<p><strong>Ruby</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;">arr = <span style="color:#006600; font-weight:bold;">&#40;</span>1..10<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_a</span>
arr.<span style="color:#CC0066; font-weight:bold;">select</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>e<span style="color:#006600; font-weight:bold;">|</span> e <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">2</span> != <span style="color:#006666;">0</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p><strong>Python</strong></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:arial,verdana,monospace;">arr = <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">11</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#91;</span>e <span style="color: #ff7700;font-weight:bold;">for</span> e <span style="color: #ff7700;font-weight:bold;">in</span> arr <span style="color: #ff7700;font-weight:bold;">if</span> e <span style="color: #66cc66;">%</span> <span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span></pre></div></div>

<p><strong>Perl</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;"><span style="color:#0066ff; font-weight:bold;">@arr</span> = <span style="color:#006600; font-weight:bold;">&#40;</span>1..10<span style="color:#006600; font-weight:bold;">&#41;</span>;
grep<span style="color:#006600; font-weight:bold;">&#40;</span>$_ <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">2</span>, <span style="color:#0066ff; font-weight:bold;">@arr</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</pre></div></div>



<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.vidul.com/2008/12/01/filtering-lists/&amp;Title=Filtering+Lists" rel="nofollow" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vidul.com/2008/12/01/filtering-lists/&amp;title=Filtering+Lists" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.vidul.com/2008/12/01/filtering-lists/&amp;title=Filtering+Lists" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.vidul.com/2008/12/01/filtering-lists/&amp;title=Filtering+Lists" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.vidul.com/2008/12/01/filtering-lists/&amp;title=Filtering+Lists" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.vidul.com/2008/12/01/filtering-lists/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Filtering+Lists+-+http://b2l.me/bmbmg+" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-newsvine">
			<a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.vidul.com/2008/12/01/filtering-lists/&amp;h=Filtering+Lists" rel="nofollow" title="Seed this on Newsvine">Seed this on Newsvine</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.vidul.com/2008/12/01/filtering-lists/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sequence Types and Slice</title>
		<link>http://www.vidul.com/2008/10/21/sequence-types-and-slice/</link>
		<comments>http://www.vidul.com/2008/10/21/sequence-types-and-slice/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 12:08:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">urn:uuid:{a.guid}</guid>
		<description><![CDATA[Ruby slice:

a = &#91;1, 2, 3, 4, 5, 6&#93;
a&#91;0..-1&#93; # [1, 2, 3, 4, 5, 6]
a&#91;&#40;0..-1&#41;&#93; # tha same

Python slice:

a = &#91;1, 2, 3, 4, 5, 6&#93;
a&#91;:-1&#93; # [1, 2, 3, 4, 5]
a&#91;:&#93; # [1, 2, 3, 4, 5, 6]
a&#91;0:len&#40;a&#41;:2&#93; # [2, 4, 6]  Nice, isn't it?






		
			Share this on Blinklist
		
		
			Share this on del.icio.us
		
		
			Digg this!
		
		
			Share [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Ruby</strong> slice:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;">a = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span>, <span style="color:#006666;">3</span>, <span style="color:#006666;">4</span>, <span style="color:#006666;">5</span>, <span style="color:#006666;">6</span><span style="color:#006600; font-weight:bold;">&#93;</span>
a<span style="color:#006600; font-weight:bold;">&#91;</span>0..<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#008000; font-style:italic;"># [1, 2, 3, 4, 5, 6]</span>
a<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#40;</span>0..<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#008000; font-style:italic;"># tha same</span></pre></div></div>

<p><strong>Python</strong> slice:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;">a = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span>, <span style="color:#006666;">3</span>, <span style="color:#006666;">4</span>, <span style="color:#006666;">5</span>, <span style="color:#006666;">6</span><span style="color:#006600; font-weight:bold;">&#93;</span>
a<span style="color:#006600; font-weight:bold;">&#91;</span>:<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#008000; font-style:italic;"># [1, 2, 3, 4, 5]</span>
a<span style="color:#006600; font-weight:bold;">&#91;</span>:<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#008000; font-style:italic;"># [1, 2, 3, 4, 5, 6]</span>
a<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span>:len<span style="color:#006600; font-weight:bold;">&#40;</span>a<span style="color:#006600; font-weight:bold;">&#41;</span>:<span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#008000; font-style:italic;"># [2, 4, 6]  Nice, isn't it?</span></pre></div></div>



<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.vidul.com/2008/10/21/sequence-types-and-slice/&amp;Title=Sequence+Types+and+Slice" rel="nofollow" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vidul.com/2008/10/21/sequence-types-and-slice/&amp;title=Sequence+Types+and+Slice" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.vidul.com/2008/10/21/sequence-types-and-slice/&amp;title=Sequence+Types+and+Slice" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.vidul.com/2008/10/21/sequence-types-and-slice/&amp;title=Sequence+Types+and+Slice" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.vidul.com/2008/10/21/sequence-types-and-slice/&amp;title=Sequence+Types+and+Slice" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.vidul.com/2008/10/21/sequence-types-and-slice/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Sequence+Types+and+Slice+-+http://b2l.me/bmwcw+" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-newsvine">
			<a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.vidul.com/2008/10/21/sequence-types-and-slice/&amp;h=Sequence+Types+and+Slice" rel="nofollow" title="Seed this on Newsvine">Seed this on Newsvine</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.vidul.com/2008/10/21/sequence-types-and-slice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Scanner (Host/Port)</title>
		<link>http://www.vidul.com/2008/09/28/quick-scanner-host-port/</link>
		<comments>http://www.vidul.com/2008/09/28/quick-scanner-host-port/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 20:09:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[scanner]]></category>

		<guid isPermaLink="false">urn:uuid:{a.guid}</guid>
		<description><![CDATA[
#!/usr/bin/ruby
&#160;
host_port = ARGV&#91;0&#93;
host = host_port.split&#40;':'&#41;.first
port = host_port.split&#40;':'&#41;.last
&#160;
puts %x&#91;nmap -p #{port} #{host}]

Or just:

#!/usr/bin/ruby
&#160;
puts %x&#91;nmap -p #{ARGV[0].split(':').reverse.join(' ')}]

Usage (cli and given that the script is named scan_proxy):

./scan_proxy 202.105.182.87:808






		
			Share this on Blinklist
		
		
			Share this on del.icio.us
		
		
			Digg this!
		
		
			Share this on Reddit
		
		
			Stumble upon something good? Share it on StumbleUpon
		
		
			Share this on Technorati
		
		
			Tweet This!
		
		
			Seed this on Newsvine
		





]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/ruby</span>
&nbsp;
host_port = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
host = host_port.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">':'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">first</span>
port = host_port.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">':'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">last</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#006600; font-weight:bold;">%</span>x<span style="color:#006600; font-weight:bold;">&#91;</span>nmap <span style="color:#006600; font-weight:bold;">-</span><span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#008000; font-style:italic;">#{port} #{host}]</span></pre></div></div>

<p>Or just:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#006600; font-weight:bold;">%</span>x<span style="color:#006600; font-weight:bold;">&#91;</span>nmap <span style="color:#006600; font-weight:bold;">-</span><span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#008000; font-style:italic;">#{ARGV[0].split(':').reverse.join(' ')}]</span></pre></div></div>

<p>Usage (cli and given that the script is named scan_proxy):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;">.<span style="color:#006600; font-weight:bold;">/</span>scan_proxy 202.105.182.87:<span style="color:#006666;">808</span></pre></div></div>



<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.vidul.com/2008/09/28/quick-scanner-host-port/&amp;Title=Quick+Scanner+%28Host%2FPort%29" rel="nofollow" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vidul.com/2008/09/28/quick-scanner-host-port/&amp;title=Quick+Scanner+%28Host%2FPort%29" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.vidul.com/2008/09/28/quick-scanner-host-port/&amp;title=Quick+Scanner+%28Host%2FPort%29" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.vidul.com/2008/09/28/quick-scanner-host-port/&amp;title=Quick+Scanner+%28Host%2FPort%29" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.vidul.com/2008/09/28/quick-scanner-host-port/&amp;title=Quick+Scanner+%28Host%2FPort%29" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.vidul.com/2008/09/28/quick-scanner-host-port/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Quick+Scanner+%28Host%2FPort%29+-+http://b2l.me/bmr93+" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-newsvine">
			<a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.vidul.com/2008/09/28/quick-scanner-host-port/&amp;h=Quick+Scanner+%28Host%2FPort%29" rel="nofollow" title="Seed this on Newsvine">Seed this on Newsvine</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.vidul.com/2008/09/28/quick-scanner-host-port/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Phonebook Script</title>
		<link>http://www.vidul.com/2008/09/20/simple-phonebook-script/</link>
		<comments>http://www.vidul.com/2008/09/20/simple-phonebook-script/#comments</comments>
		<pubDate>Sat, 20 Sep 2008 15:39:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">urn:uuid:{a.guid}</guid>
		<description><![CDATA[
#!/usr/bin/env ruby
&#160;
class Hash
  def search&#40;arg&#41;
    self.select &#123; &#124;k,v&#124; k =~ /#{arg}/ or v =~ /#{arg}/ }
  end
end
&#160;
search = ARGV&#91;0&#93;
search =~ /^&#91;0-9&#93;+/ and search = search.to_i
&#160;
phones = &#123;
  &#34;me&#34;        =&#62; &#34;359880101020406&#34;,
  &#34;Hitler&#34;     =&#62; &#34;+49 666&#34;,
  &#34;Van Gog&#34; [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC00FF; font-weight:bold;">Hash</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> search<span style="color:#006600; font-weight:bold;">&#40;</span>arg<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#CC0066; font-weight:bold;">select</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>k,v<span style="color:#006600; font-weight:bold;">|</span> k =~ <span style="color:#006600; font-weight:bold;">/</span><span style="color:#008000; font-style:italic;">#{arg}/ or v =~ /#{arg}/ }</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
search = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
search =~ <span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+/</span> <span style="color:#9966CC; font-weight:bold;">and</span> search = search.<span style="color:#9900CC;">to_i</span>
&nbsp;
phones = <span style="color:#006600; font-weight:bold;">&#123;</span>
  <span style="color:#996600;">&quot;me&quot;</span>        <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;359880101020406&quot;</span>,
  <span style="color:#996600;">&quot;Hitler&quot;</span>     <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;+49 666&quot;</span>,
  <span style="color:#996600;">&quot;Van Gog&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;+31&quot;</span>,
  <span style="color:#996600;">&quot;devil&quot;</span>      <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;666&quot;</span>,
  <span style="color:#996600;">&quot;God&quot;</span>       <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;1&quot;</span>,
<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
phones.<span style="color:#9900CC;">search</span><span style="color:#006600; font-weight:bold;">&#40;</span>search<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>person<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;person:#{person.first}<span style="color:#000099;">\t</span>number:#{person.last}<span style="color:#000099;">\n</span>&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>



<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.vidul.com/2008/09/20/simple-phonebook-script/&amp;Title=Simple+Phonebook+Script" rel="nofollow" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vidul.com/2008/09/20/simple-phonebook-script/&amp;title=Simple+Phonebook+Script" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.vidul.com/2008/09/20/simple-phonebook-script/&amp;title=Simple+Phonebook+Script" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.vidul.com/2008/09/20/simple-phonebook-script/&amp;title=Simple+Phonebook+Script" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.vidul.com/2008/09/20/simple-phonebook-script/&amp;title=Simple+Phonebook+Script" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.vidul.com/2008/09/20/simple-phonebook-script/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Simple+Phonebook+Script+-+http://b2l.me/bmsgn+" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-newsvine">
			<a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.vidul.com/2008/09/20/simple-phonebook-script/&amp;h=Simple+Phonebook+Script" rel="nofollow" title="Seed this on Newsvine">Seed this on Newsvine</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.vidul.com/2008/09/20/simple-phonebook-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby __DATA__ (embedded data)</title>
		<link>http://www.vidul.com/2008/08/22/ruby-__data__-embedded-data/</link>
		<comments>http://www.vidul.com/2008/08/22/ruby-__data__-embedded-data/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 17:04:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[data]]></category>

		<guid isPermaLink="false">urn:uuid:{a.guid}</guid>
		<description><![CDATA[
module Kernel
  RE_THIS_DATA = lambda&#123; &#124;number&#124; /^__DATA#{number}__\n/ }
  RE_THE_DATA  = /^__DATA\d+__/
&#160;
  def __data__&#40;num=&#34;&#34;&#41;
    data = File.read&#40;$0&#41;.split&#40;RE_THIS_DATA.call&#40;num&#41;&#41;
    data&#91;1&#93;.split&#40;RE_THE_DATA&#41;&#91;0&#93; if data&#91;1&#93;
  end
end
&#160;
puts &#34;DATA&#34;
print __data__&#40;&#41;
&#160;
puts &#34;DATA1&#34;
print __data__&#40;1&#41;
&#160;
puts &#34;DATA2&#34;
print __data__&#40;2&#41;
&#160;
__END__
&#160;
__DATA__
data_1
data_2
data_3
&#160;
__DATA1__
data1_1
data1_2
data1_3
&#160;
data1_11
&#160;
__DATA2__
data2_1
data2_2
data2_3
&#160;
data2_31






		
			Share this on Blinklist
		
		
			Share this on del.icio.us
		
		
			Digg this!
		
		
			Share this on Reddit
		
		
			Stumble upon something good? Share it on StumbleUpon
		
		
			Share this [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> <span style="color:#CC00FF; font-weight:bold;">Kernel</span>
  RE_THIS_DATA = <span style="color:#CC0066; font-weight:bold;">lambda</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>number<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">/</span>^__DATA<span style="color:#008000; font-style:italic;">#{number}__\n/ }</span>
  RE_THE_DATA  = <span style="color:#006600; font-weight:bold;">/</span>^__DATA\d<span style="color:#006600; font-weight:bold;">+</span>__<span style="color:#006600; font-weight:bold;">/</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> __data__<span style="color:#006600; font-weight:bold;">&#40;</span>num=<span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    data = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span>$<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span>RE_THIS_DATA.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span>num<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    data<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span>RE_THE_DATA<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">if</span> data<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;DATA&quot;</span>
<span style="color:#CC0066; font-weight:bold;">print</span> __data__<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;DATA1&quot;</span>
<span style="color:#CC0066; font-weight:bold;">print</span> __data__<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;DATA2&quot;</span>
<span style="color:#CC0066; font-weight:bold;">print</span> __data__<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
__END__
&nbsp;
__DATA__
data_1
data_2
data_3
&nbsp;
__DATA1__
data1_1
data1_2
data1_3
&nbsp;
data1_11
&nbsp;
__DATA2__
data2_1
data2_2
data2_3
&nbsp;
data2_31</pre></div></div>



<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.vidul.com/2008/08/22/ruby-__data__-embedded-data/&amp;Title=Ruby+__DATA__+%28embedded+data%29" rel="nofollow" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vidul.com/2008/08/22/ruby-__data__-embedded-data/&amp;title=Ruby+__DATA__+%28embedded+data%29" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.vidul.com/2008/08/22/ruby-__data__-embedded-data/&amp;title=Ruby+__DATA__+%28embedded+data%29" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.vidul.com/2008/08/22/ruby-__data__-embedded-data/&amp;title=Ruby+__DATA__+%28embedded+data%29" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.vidul.com/2008/08/22/ruby-__data__-embedded-data/&amp;title=Ruby+__DATA__+%28embedded+data%29" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.vidul.com/2008/08/22/ruby-__data__-embedded-data/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Ruby+__DATA__+%28embedded+data%29+-+http://b2l.me/bmu5a+" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-newsvine">
			<a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.vidul.com/2008/08/22/ruby-__data__-embedded-data/&amp;h=Ruby+__DATA__+%28embedded+data%29" rel="nofollow" title="Seed this on Newsvine">Seed this on Newsvine</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.vidul.com/2008/08/22/ruby-__data__-embedded-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chdir Method with Block</title>
		<link>http://www.vidul.com/2008/08/22/chdir-method-with-block/</link>
		<comments>http://www.vidul.com/2008/08/22/chdir-method-with-block/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 16:13:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[dir]]></category>

		<guid isPermaLink="false">urn:uuid:{a.guid}</guid>
		<description><![CDATA[
# temporary changes the cwd to '/tmp',
# adds content to a file and finally restores cwd
&#160;
p Dir.getwd
&#160;
Dir.chdir&#40;&#34;/tmp&#34;&#41; do
  p Dir.getwd
  File.open&#40;&#34;test.txt&#34;, &#34;a&#34;&#41; do &#124;f&#124;
    f &#60;&#60; Time.now &#60;&#60; &#34;\n&#34;
  end
end
&#160;
p Dir.getwd






		
			Share this on Blinklist
		
		
			Share this on del.icio.us
		
		
			Digg this!
		
		
			Share this on Reddit
		
		
			Stumble upon something good? Share it on StumbleUpon
		
		
			Share this [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;"><span style="color:#008000; font-style:italic;"># temporary changes the cwd to '/tmp',</span>
<span style="color:#008000; font-style:italic;"># adds content to a file and finally restores cwd</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">getwd</span>
&nbsp;
<span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">chdir</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;/tmp&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">getwd</span>
  <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;test.txt&quot;</span>, <span style="color:#996600;">&quot;a&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
    f <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">getwd</span></pre></div></div>



<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-blinklist">
			<a href="http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url=http://www.vidul.com/2008/08/22/chdir-method-with-block/&amp;Title=Chdir+Method+with+Block" rel="nofollow" title="Share this on Blinklist">Share this on Blinklist</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vidul.com/2008/08/22/chdir-method-with-block/&amp;title=Chdir+Method+with+Block" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.vidul.com/2008/08/22/chdir-method-with-block/&amp;title=Chdir+Method+with+Block" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.vidul.com/2008/08/22/chdir-method-with-block/&amp;title=Chdir+Method+with+Block" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.vidul.com/2008/08/22/chdir-method-with-block/&amp;title=Chdir+Method+with+Block" rel="nofollow" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.vidul.com/2008/08/22/chdir-method-with-block/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Chdir+Method+with+Block+-+http://b2l.me/bmte7+" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-newsvine">
			<a href="http://www.newsvine.com/_tools/seed&amp;save?u=http://www.vidul.com/2008/08/22/chdir-method-with-block/&amp;h=Chdir+Method+with+Block" rel="nofollow" title="Seed this on Newsvine">Seed this on Newsvine</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.vidul.com/2008/08/22/chdir-method-with-block/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
