<?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; oneliners</title>
	<atom:link href="http://www.vidul.com/category/oneliners/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vidul.com</link>
	<description>my web space</description>
	<lastBuildDate>Fri, 09 Apr 2010 21:01:09 +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>Fast ICMP scanner (Perl oneliner)</title>
		<link>http://www.vidul.com/2008/01/08/fast-icmp-scanner-perl-one-liner/</link>
		<comments>http://www.vidul.com/2008/01/08/fast-icmp-scanner-perl-one-liner/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 08:05:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[SA]]></category>
		<category><![CDATA[oneliners]]></category>

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

time perl -MNet::Ping -e '$p = Net::Ping-&#62;new();
@hosts = qw(
127.0.0.1
172.16.0.1
172.16.0.2
172.16.0.5
172.16.0.254);
#the significant detail
$p-&#62;{&#34;timeout&#34;} = 0.005;
for (@hosts) { print &#34;$_ is &#34;.($p-&#62;ping($_) ? &#34;up&#34; : &#34;down&#34;).$/ }'

127.0.0.1 is up
172.16.0.1 is up
172.16.0.2 is down
172.16.0.5 is up
172.16.0.254 is down
real    0m0.062s
user    0m0.040s
sys     0m0.000s





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

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:arial,verdana,monospace;"><span style="color: #000066;">time</span> perl <span style="color: #339933;">-</span>MNet<span style="color: #339933;">::</span><span style="color: #006600;">Ping</span> <span style="color: #339933;">-</span>e <span style="color: #ff0000;">'$p = Net::Ping-&gt;new();
@hosts = qw(
127.0.0.1
172.16.0.1
172.16.0.2
172.16.0.5
172.16.0.254);
#the significant detail
$p-&gt;{&quot;timeout&quot;} = 0.005;
for (@hosts) { print &quot;$_ is &quot;.($p-&gt;ping($_) ? &quot;up&quot; : &quot;down&quot;).$/ }'</span></pre></div></div>

<p>127.0.0.1 is up<br />
172.16.0.1 is up<br />
172.16.0.2 is down<br />
172.16.0.5 is up<br />
172.16.0.254 is down</p>
<p>real    0m0.062s<br />
user    0m0.040s<br />
sys     0m0.000s</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/2008/01/08/fast-icmp-scanner-perl-one-liner/&amp;Title=Fast+ICMP+scanner+%28Perl+oneliner%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/01/08/fast-icmp-scanner-perl-one-liner/&amp;title=Fast+ICMP+scanner+%28Perl+oneliner%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/01/08/fast-icmp-scanner-perl-one-liner/&amp;title=Fast+ICMP+scanner+%28Perl+oneliner%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/01/08/fast-icmp-scanner-perl-one-liner/&amp;title=Fast+ICMP+scanner+%28Perl+oneliner%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/01/08/fast-icmp-scanner-perl-one-liner/&amp;title=Fast+ICMP+scanner+%28Perl+oneliner%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/01/08/fast-icmp-scanner-perl-one-liner/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Fast+ICMP+scanner+%28Perl+oneliner%29+-+http://b2l.me/bj3th+" 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/01/08/fast-icmp-scanner-perl-one-liner/&amp;h=Fast+ICMP+scanner+%28Perl+oneliner%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/01/08/fast-icmp-scanner-perl-one-liner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby one-liners (file manipulation)</title>
		<link>http://www.vidul.com/2007/07/20/ruby-one-liners-file-manipulation/</link>
		<comments>http://www.vidul.com/2007/07/20/ruby-one-liners-file-manipulation/#comments</comments>
		<pubDate>Fri, 20 Jul 2007 18:11:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[oneliners]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">urn:uuid:{a.guid}</guid>
		<description><![CDATA[
# number each line of a file
ruby -ne 'puts &#34;#{$.}\t#{$_}&#34;' file.txt
&#160;
# print all non-blank lines
ruby -pe '$_.chomp.empty? and next' file.txt
&#160;
# number and print all non-blank lines
ruby -ne '$_.chomp.empty? or print $.,&#34;\t&#34;, $_' file.txt
&#160;
# number and print each blank line
ruby -ne 'puts $. if $_.chomp.empty?' file.txt
&#160;
# reverse order of lines (`tac` style)
ruby -e 'puts File.open($&#60; .filename).readlines.reverse' [...]]]></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;"># number each line of a file</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>ne <span style="color:#996600;">'puts &quot;#{$.}<span style="color:#000099;">\t</span>#{$_}&quot;'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># print all non-blank lines</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>pe <span style="color:#996600;">'$_.chomp.empty? and next'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># number and print all non-blank lines</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>ne <span style="color:#996600;">'$_.chomp.empty? or print $.,&quot;<span style="color:#000099;">\t</span>&quot;, $_'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># number and print each blank line</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>ne <span style="color:#996600;">'puts $. if $_.chomp.empty?'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># reverse order of lines (`tac` style)</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>e <span style="color:#996600;">'puts File.open($&lt; .filename).readlines.reverse'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># print matched string from lines, matching the pattern</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>ne <span style="color:#996600;">'puts $_.scan(/^<span style="color:#000099;">\w</span>+/)'</span> <span style="color:#006600; font-weight:bold;">/</span>etc<span style="color:#006600; font-weight:bold;">/</span>passwd
&nbsp;
<span style="color:#008000; font-style:italic;"># triple space a file and reverse order of lines</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>e <span style="color:#996600;">'$,=&quot;<span style="color:#000099;">\n</span><span style="color:#000099;">\n</span><span style="color:#000099;">\n</span>&quot;; puts File.readlines($&lt;.filename).reverse.join'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># print first line of a file (emulate 'head -1')</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>ne <span style="color:#996600;">'puts $_; break'</span> file.<span style="color:#9900CC;">txt</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>pe <span style="color:#996600;">'$. == 1 or break'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># print last line of a file (emulates 'tail -1')</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>ne <span style="color:#996600;">'END{puts $_}'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># print last line number (emulates 'wc -l')</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>e <span style="color:#996600;">'loop{gets or break}; puts $.'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># print only lines that match a regular expression (emulates 'grep')</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>pe <span style="color:#996600;">'next if not /regex/'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># print only lines that do not match a regular expression (emulates 'grep -v')</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>pe <span style="color:#996600;">'next if /regex/'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># print section of file between two regular expressions, /^root/ and /^nobody/</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>ne <span style="color:#996600;">'puts $_ if /^root/../^nobody/'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># print file and remove duplicate, consecutive lines from a file (emulates 'uniq')</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>ne <span style="color:#996600;">'$_.eql? $; or puts $_;$; = $_;'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># print file except for blank lines</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>pe <span style="color:#996600;">'next if $_.chomp.empty?'</span> file.<span style="color:#9900CC;">txt</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>pe <span style="color:#996600;">'next if /^<span style="color:#000099;">\s</span>*$/'</span> file.<span style="color:#9900CC;">txt</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>pe <span style="color:#996600;">'next if $_.split(/<span style="color:#000099;">\S</span>+/).size &lt; 2'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># print file except for lines, starting with digit (unclear and inefficient)</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>pe <span style="color:#996600;">'next if (48..57).to_a.include?($_.split(//)[0][0])'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># delete all leading blank lines at top of file</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>pe <span style="color:#996600;">'$,=&quot;$.&quot; if not $_.chomp.empty?; $, or next'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># print section of file from regex to end of file</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>pe <span style="color:#996600;">'$,=&quot;$.&quot; if /regex/; $, or next'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># delete leading and trailing whitespace from each line</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>pe <span style="color:#996600;">'$_.strip!.sub!(/$/, &quot;<span style="color:#000099;">\n</span>&quot;)'</span> file.<span style="color:#9900CC;">txt</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>ne <span style="color:#996600;">'puts $_.strip! + $/'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># delete leading whitespace from the beginning of each line</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>ne <span style="color:#996600;">'puts $_.lstrip! || $_'</span> file.<span style="color:#9900CC;">txt</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># convert DOS newlines (CR/LF) to Unix format (LF)</span>
ruby <span style="color:#006600; font-weight:bold;">-</span>i <span style="color:#006600; font-weight:bold;">-</span>pe <span style="color:#996600;">'sub(/<span style="color:#000099;">\r</span><span style="color:#000099;">\n</span>/, &quot;<span style="color:#000099;">\n</span>&quot;)'</span> file.<span style="color:#9900CC;">txt</span></pre></div></div>

</pre>


<!-- 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/2007/07/20/ruby-one-liners-file-manipulation/&amp;Title=Ruby+one-liners+%28file+manipulation%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/2007/07/20/ruby-one-liners-file-manipulation/&amp;title=Ruby+one-liners+%28file+manipulation%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/2007/07/20/ruby-one-liners-file-manipulation/&amp;title=Ruby+one-liners+%28file+manipulation%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/2007/07/20/ruby-one-liners-file-manipulation/&amp;title=Ruby+one-liners+%28file+manipulation%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/2007/07/20/ruby-one-liners-file-manipulation/&amp;title=Ruby+one-liners+%28file+manipulation%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/2007/07/20/ruby-one-liners-file-manipulation/" 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+one-liners+%28file+manipulation%29+-+http://b2l.me/bkb27+" 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/2007/07/20/ruby-one-liners-file-manipulation/&amp;h=Ruby+one-liners+%28file+manipulation%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/2007/07/20/ruby-one-liners-file-manipulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>1..666</title>
		<link>http://www.vidul.com/2007/07/19/nonsense/</link>
		<comments>http://www.vidul.com/2007/07/19/nonsense/#comments</comments>
		<pubDate>Fri, 20 Jul 2007 03:59:00 +0000</pubDate>
		<dc:creator>Vidul</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[oneliners]]></category>
		<category><![CDATA[scripts]]></category>

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

$.=0; &#40;1..666&#41;.to_a.inject&#40;1&#41;&#123;&#124;res, i&#124; res += i&#125;.to_s.split&#40;//&#41;.collect&#123;&#124;i&#124; $. += i.to_i&#125;; STDOUT.puts$






		
			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>irb console</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:arial,verdana,monospace;">$.=<span style="color:#006666;">0</span>; <span style="color:#006600; font-weight:bold;">&#40;</span>1..666<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_a</span>.<span style="color:#9900CC;">inject</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>res, i<span style="color:#006600; font-weight:bold;">|</span> res <span style="color:#006600; font-weight:bold;">+</span>= i<span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">to_s</span>.<span style="color:#CC0066; font-weight:bold;">split</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>.<span style="color:#9900CC;">collect</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span> $. <span style="color:#006600; font-weight:bold;">+</span>= i.<span style="color:#9900CC;">to_i</span><span style="color:#006600; font-weight:bold;">&#125;</span>; STDOUT.<span style="color:#CC0066; font-weight:bold;">puts</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/2007/07/19/nonsense/&amp;Title=1..666" 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/2007/07/19/nonsense/&amp;title=1..666" 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/2007/07/19/nonsense/&amp;title=1..666" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.vidul.com/2007/07/19/nonsense/&amp;title=1..666" 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/2007/07/19/nonsense/&amp;title=1..666" 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/2007/07/19/nonsense/" rel="nofollow" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=1..666+-+http://b2l.me/bkmgq+" 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/2007/07/19/nonsense/&amp;h=1..666" 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/2007/07/19/nonsense/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
