]> code.delx.au - dotfiles/commitdiff
bin: Moved things to/from jamesstuff/scripts
authorJames Bunton <jamesbunton@delx.net.au>
Tue, 11 Nov 2014 04:57:16 +0000 (15:57 +1100)
committerJames Bunton <jamesbunton@delx.net.au>
Tue, 11 Nov 2014 04:58:22 +0000 (15:58 +1100)
bin/find-in-file [new file with mode: 0755]
bin/java-decompile-recursive [deleted file]
bin/passwdgen [new file with mode: 0755]
bin/rsync-ssh-restrict [deleted file]

diff --git a/bin/find-in-file b/bin/find-in-file
new file mode 100755 (executable)
index 0000000..df771fe
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/python2
+
+import sys
+
+try:
+    needle = sys.argv[1]
+    haystack = sys.argv[2]
+except IndexError:
+    print >>sys.stderr, "Usage: %s needle haystack" % sys.argv[0]
+    sys.exit(1)
+
+
+f = open(needle)
+magic = f.read(1024)
+f.close()
+
+chunk_size = 32768
+f = open(haystack)
+count = 0
+buf = ""
+while True:
+    newbuf = f.read(chunk_size)
+    if not newbuf:
+        break
+    buf += newbuf
+    pos = buf.find(magic)
+    if pos >= 0:
+        print "found", count + pos
+    count += len(buf) - len(magic)
+    buf = buf[-len(magic):]
+f.close()
+
diff --git a/bin/java-decompile-recursive b/bin/java-decompile-recursive
deleted file mode 100755 (executable)
index afc6220..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/bash
-
-if [ -z "$1" -o -z "$2" ]; then
-    echo "Usage: $0 src dest"
-    exit 1
-fi
-
-src="$1"
-dest="$2"
-mkdir -p "$dest"
-dest="$(cd "$dest" && pwd)"
-
-cd "$src"
-find . -name '*.class' | while read line; do
-    class="$(echo "$line"| sed -e 's|^\./||' -e 's|\.class$||' -e 's|/|.|g')"
-    javap -private -c "$class" > "${dest}/${class}.txt"
-done
-
diff --git a/bin/passwdgen b/bin/passwdgen
new file mode 100755 (executable)
index 0000000..f774381
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/python3
+
+import random, sys
+
+alnum_chars = list(filter(lambda c: c.isalnum(), map(chr, range(128))))
+full_chars = alnum_chars * 2 + list("!@#%^&*(){}[]/=?+_-;:,.<>")
+
+def generate(chars, length):
+    return "".join([random.choice(chars) for i in range(length)])
+
+def print_usage():
+    print("Usage: %s [length] [alnum|full]" % sys.argv[0])
+    sys.exit(1)
+
+if __name__ == "__main__":
+    if len(sys.argv) <= 1:
+        n = 20
+    elif sys.argv[1].isdigit():
+        n = int(sys.argv[1])
+    else:
+        print_usage()
+
+    if len(sys.argv) <= 2:
+        chars = alnum_chars
+    elif sys.argv[2] == "alnum":
+        chars = alnum_chars
+    elif sys.argv[2] == "full":
+        chars = full_chars
+    else:
+        print_usage()
+
+    print(generate(chars, n))
+
diff --git a/bin/rsync-ssh-restrict b/bin/rsync-ssh-restrict
deleted file mode 100755 (executable)
index fc5e7b1..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh
-
-case "$SSH_ORIGINAL_COMMAND" in
-*\&*)
-echo "Rejected" >&2
-;;
-*\(*)
-echo "Rejected" >&2
-;;
-*\{*)
-echo "Rejected" >&2
-;;
-*\;*)
-echo "Rejected" >&2
-;;
-*\<*)
-echo "Rejected" >&2
-;;
-*\`*)
-echo "Rejected" >&2
-;;
-*\|*)
-echo "Rejected" >&2
-;;
-rsync\ --server*)
-ionice -c3 nice -n5 $SSH_ORIGINAL_COMMAND
-;;
-*)
-echo "Rejected" >&2
-;;
-esac
-