Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

post bits of code you like

Name: Anonymous 2005-08-02 1:52

i shall start:

open(F,"find -type f|");
while (<F>) {
 $_ = substr($_,2,-1);
 print "$_\n" if $v;
 push @{$dups{substr(`md5sum -b "$_"`,0,31)}}, $_;
}
close(F);

for every file in a directory it checksums the file, then adds the checksum as a key to a hash, the value being an array reference. the filename is then added to the array.

so basically the arrays have a list of files with the same checksum. i use this to find duplicates files.

Name: Anonymous 2005-12-15 19:36

Reposting code from above post with proper tags.  Apparently, I fail at XHTML in Shiichan.

<code>for aChild in thisRoot ... end
</code>

<code>
class Node
  attr_accessor :left, :right, :data
  def traverse
    @left.traverse {|node| yield node } unless @left.nil?
    yield self
    @right.traverse {|node| yield node } unless @right.nil?
  end
end
</code>


<code>
def fibone(n)
  a, b = 0, 1
  (n-1).times do
    yield a if block_given?
    a, b = b, a+b
  end
  return b
end
</code>

<code>fib(100) {|n| puts n}
</code>

<code>
$fibcache = Hash.new
def fib(n)
  $fibcache[0], $fibcache[1] = 0, 1
  return fib_re(n)
end

def fib_re(n)
  if !($fibcache[n].nil?)
    return $fibcache[n]
  elsif (n.modulo(2) == 0)
    fnn = fib_re((n/2.0).to_i)
    fnm = fib_re(((n/2.0)-1).to_i)
    ans = (((2 * fnm) + fnn)*fnn).to_i
  else
    fnn = fib_re((n/2.0).ceil)
    fnm = fib_re((n/2.0).floor)
    ans =  ((fnn**2)+ (fnm**2)).to_i
  end
  $fibcache[n]=ans
  return ans
end
</code>

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List