Skip to content

Commit 064645b

Browse files
committed
Adds lsinteresting
1 parent 3435771 commit 064645b

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

lsinteresting/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lsinteresting

lsinteresting/main.go

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"io/ioutil"
7+
"log"
8+
"math"
9+
"path"
10+
"strconv"
11+
)
12+
13+
func main() {
14+
15+
flag.Parse()
16+
17+
dir := flag.Arg(0)
18+
if dir == "" {
19+
log.Fatal("No dir specified")
20+
}
21+
22+
threshold := 1.0
23+
if t, err := strconv.ParseFloat(flag.Arg(1), 64); err == nil {
24+
threshold = t
25+
}
26+
27+
contents, err := ioutil.ReadDir(dir)
28+
if err != nil {
29+
log.Fatalf("failed to read dir: %s", err)
30+
}
31+
32+
sizes := make([]int64, 0)
33+
34+
for _, f := range contents {
35+
// don't bother with directories
36+
if f.IsDir() {
37+
continue
38+
}
39+
40+
// see how different the file is to the sizes we've seen so far
41+
// start of assuming the file is different, but if it's within, say,
42+
// 1% of a filesize we've already seen then skip it
43+
isDifferent := true
44+
for _, s := range sizes {
45+
diff := math.Abs((float64(s-f.Size()) / float64(s)) * 100)
46+
if diff < threshold {
47+
isDifferent = false
48+
}
49+
}
50+
if isDifferent {
51+
sizes = append(sizes, f.Size())
52+
fmt.Println(path.Join(dir, f.Name()))
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)