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

Pages: 1-4041-

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

Name: Anonymous 2011-07-05 15:58

>>40
okay now I'm mad. FUCK OFF AND DIE YOU SHIT EATING AUTISTIC LITHPER FAGSTORM. TAKE YOUR USELESS UNREADABLE PIECE OF SHIT LANGUAGE AND SHOVE IT UP YOUR GIGANTIC ASSHOLE

Name: Anonymous 2011-07-05 16:15

>>41
Less of this

Name: >>41 2011-07-05 16:15

>>42
.

Name: Anonymous 2011-07-05 16:32

>>42
nigger fagstorm

Name: Anonymous 2011-07-05 16:53

>>41
if u think lisp its shit y u mad tho lol u such a fagface gb2ur shitty language

Name: Anonymous 2011-07-05 17:26

>>1
this is why i'm an autist atheist

Name: Anonymous 2011-07-05 17:38

>>45
lisp is fucking shit and you are a cretin for thinking otherwise

Name: Anonymous 2011-07-05 18:14

>>47
u buttmad fiocfag

Name: Anonymous 2011-07-05 18:23

>>48
LITHPY NIGGERLOVRE

Name: Anonymous 2011-07-05 18:26

>>48
fiocfag here. I'm in good company.

http://en.wikipedia.org/wiki/Hal_Abelson

Name: Anonymous 2011-07-05 18:40

>>50
fuck you phython faggot

Name: Anonymous 2011-07-06 11:32

>>51
YOU ARE REALLY MAD NIGGER

Name: Anonymous 2011-07-06 13:29

six levels of indentation.

that is all.

Name: Anonymous 2011-07-06 13:35

>>53
jelly

Name: Anonymous 2011-07-06 14:33

>>53
So?

Name: Anonymous 2011-07-06 19:57

did somebody post a perl one-liner yet?

Name: Anonymous 2011-07-06 20:18

>>56

Someone posted a bash one-liner.

Name: Anonymous 2011-07-07 15:40

I hate to be the first to say it:
But isn't calculating a checksum of every file for this task... well inefficient?

A incremental check only loading the first blocks and comparing the first word of the files would be quite faster.

Name: Anonymous 2011-07-07 16:40

>>58
                               ­I shit in your face.                               ­
                         ­

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