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

This is why Python is God

Name: Anonymous 2011-07-03 23:41

#!/usr/bin/env python

import hashlib
import os
import sys


def visit(files_by_size, dirname, names):
  for name in names:
    path = os.path.join(dirname, name)
    if os.path.isfile(path):
      size = os.path.getsize(path)
      if size in files_by_size:
        files_by_size[size].append(path)
      else:
        files_by_size[size] = [path]


if __name__ == '__main__':
  for dirname in sys.argv[1:]:
    files_by_size = {}
    files_by_hash = {}
    os.path.walk(dirname, visit, files_by_size)
    for size, paths in files_by_size.items():
      if len(paths) > 1:
        for path in paths:
          with open(path) as f:
            hash = hashlib.md5(f.read()).hexdigest()
            f.close()
          if hash in files_by_hash:
            files_by_hash[hash].append(path)
          else:
            files_by_hash[hash] = [path]
    for hash, paths in files_by_hash.items():
      if len(paths) > 1:
        for path in paths:
          print '%s  %s' % (hash, path)

Name: Anonymous 2011-07-04 0:00

PIG DISGUSTING!

Don't worry, swarms of shitty programmers will come to talk shit on your language, no doubt. Might as well give up now.

Name: Anonymous 2011-07-04 0:15

>>2
It's a work of art, bro. You can't appreciate beauty. Also, you can't program.

Name: Anonymous 2011-07-04 2:08

find /usr/anus -type f -exec md5sum {} \;

Get out.

Name: Anonymous 2011-07-04 3:02

where are the newlines

Name: Anonymous 2011-07-04 3:37

>>3
Complete and utter shite, both the language and your code.

Name: Anonymous 2011-07-04 3:41

>>6
come on me bro

Name: Anonymous 2011-07-04 4:34

bump

Name: Anonymous 2011-07-04 5:02

>>4
That prints out the checksum for every file. The Python code only displays duplicates.

Name: Anonymous 2011-07-04 5:04

>>5
Newlines are implied by 'print'.

>>6
Feel free to write it in Lisp. See you next week.

>>8
Why are you bumping my thread?

Name: dubzbot-ng 2011-07-04 5:04

:GJS1M 67dcbdbce4a0b67c4b48e86a6ae29205a95e4b83024a9d947213d1231800e8d9
:66 15c4c7cb5635c7de4029324b98c6d628
:1309750908 1309770288


>>8
<-- that's cool and all, but check 'em

Name: Anonymous 2011-07-04 9:15

find -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate

Name: Anonymous 2011-07-04 9:40

>>12
prepare your anus, faggot

Name: Anonymous 2011-07-04 11:45

>>1
you can read this like a poem

>>12
not

Name: Anonymous 2011-07-04 14:08

>>12
./dupes.py /

I win.

find, sort, uniq, xargs; that's four tools each written in 9001 lines of C to do something that can be done in 37 lines of Python WITHOUT taking the checksum of every file TWICE and sorting it TWICE. No way in hell I'm running that on 800 GB of backup data.

Name: Anonymous 2011-07-04 14:22

>>15
Anime is not ``backup data''.

Name: Anonymous 2011-07-04 14:26

>>15
No way people can really think that way

Name: Anonymous 2011-07-04 14:29

Here's the Lisp version: ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((

Name: Anonymous 2011-07-04 14:30

>>17
It's called logic. It's not something they teach you in SICP, faggot.

Name: Anonymous 2011-07-04 14:38

>>19
Section 4.4, Logic Programming.

Name: Anonymous 2011-07-04 14:39

>>19
Aww you're cute when you're angry.

Name: Anonymous 2011-07-04 15:02

>>17
Don't feed the troll.

>>15
The python interpreter itself is a bloated piece of shit (3 megabytes? LOL!), and guess what? It's written in over 9000 lines of C.

0/10

Name: Anonymous 2011-07-04 17:05

>>16
Absolute the best post on /prog/ for at least months.

Name: Anonymous 2011-07-04 18:25

>>22
And it has some sorry ass lambda function.

Name: Anonymous 2011-07-04 18:38

>>24
f = lambda:f

Name: Anonymous 2011-07-04 18:54

>>12
That's a terrible idea. Use this instead:
find -not -empty -type f -printf '%s           ,"%p"\n' | sort -n | uniq -Dw12 | cut -f 2- -d "," | xargs md5sum | sort | uniq -w32 --all-repeated=separate

Name: Anonymous 2011-07-05 12:03

#lang racket
(require file/md5)

(define (group-by-size dir)
  (fold-files (lambda (path type result)
                (if (eq? type 'file)
                    (hash-update result (file-size path) (curry cons path) '())
                    result))
              (hash) dir))

(define (group-by-md5 files)
  (foldl (lambda (paths result)
           (if (> (length paths) 1)
               (foldl (lambda (path result)
                        (hash-update result (md5 (file->bytes path)) (curry cons path) '()))
                      result paths)
               result))
         (hash) (hash-values files)))

(define (print-duplicates files)
  (hash-for-each files (lambda (md5 paths)
                         (when (> (length paths) 1)
                           (for-each (lambda (path) (printf "~a: ~a\n" md5 path)) paths)))))

(print-duplicates (group-by-md5 (group-by-size (command-line #:args (dir) dir))))

Name: Anonymous 2011-07-05 12:25

>>1,27
I can't settle on which is uglier.

Name: Anonymous 2011-07-05 12:27

>>28
You're mom is.

Name: Anonymous 2011-07-05 13:15

>>29
butthurt lisper

Name: Anonymous 2011-07-05 13:52

check

Name: Anonymous 2011-07-05 13:52

my

Name: Anonymous 2011-07-05 13:52

dubz

Name: Anonymous 2011-07-05 14:42

>>27

good man.

loops are for faggots

Name: Anonymous 2011-07-05 15:12

>>27
           
(                )

(       (                 )
  (           (       (                )
                (   (              )
                    (                   (              ) (               )  ())
                          ))
              (    )    ))

(       (                  )
  (      (       (            )
           (   (  (            )  )
               (      (       (           )
                        (                   (    (                )) (               )  ()))
                                  )
                     ))
         (    ) (                 )))

(       (                      )
  (                    (       (         )
                         (     (  (            )  )
                           (         (       (    ) (                          ))      )))))

(                 (             (              (                    (   )    ))))

Name: Anonymous 2011-07-05 15:45

>>35
eat a dick thupid fiocfag

Name: Anonymous 2011-07-05 15:49

>>36
U MAD LITHP FARTITHT

Name: Anonymous 2011-07-05 15:52

>>37
i aint even mad ur just butthurt cuz ur fioc is shit dealw/it

Name: Anonymous 2011-07-05 15:53

>>38
im not the pythonista you stupid fagstorm

Name: Anonymous 2011-07-05 15:54

>>39
if it aint lisp its shit dealw/it faggot

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