Browse Source

Merge branch 'master' of rosencrantz:/srv/git/GRUtils

Getty Ritter 6 years ago
parent
commit
f56a8e9cf5

+ 12 - 7
README

@@ -5,13 +5,7 @@ Miscellaneous command-line utilities to do various small tasks. They're split
 up into different libraries so they can be installed individually, but also
 up into different libraries so they can be installed individually, but also
 kept in a single repo because they're all tiny.
 kept in a single repo because they're all tiny.
 
 
-All these are licensed under the WTFPL.
-
-RSAPair/
---------
-
-A single RSAPair executable that produces a hex-encoded public/private key
-pair on stdout. In Haskell; cabalized.
+All these are licensed under the WTFPL unless noted otherwise.
 
 
 escaped-string/
 escaped-string/
 -----------
 -----------
@@ -25,3 +19,14 @@ expseq/
 
 
 A rough analogue of seq for generating exponentially increasing numbers rather
 A rough analogue of seq for generating exponentially increasing numbers rather
 than sequentially. In C; has Makefile.
 than sequentially. In C; has Makefile.
+
+json2bencode/
+-------------
+
+What it says on the tin. In Haskell.
+
+scripts/
+--------
+
+Random scripts, several of them not useful to anyone else, some of them probably
+quite useful. A mixed bag.

+ 0 - 14
RSAPair/LICENSE

@@ -1,14 +0,0 @@
-            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
-                    Version 2, December 2004
-
- Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
-
- Everyone is permitted to copy and distribute verbatim or modified
- copies of this license document, and changing it is allowed as long
- as the name is changed.
-
-            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. You just DO WHAT THE FUCK YOU WANT TO.
-

+ 0 - 16
RSAPair/RSAPair.cabal

@@ -1,16 +0,0 @@
-name:                RSAPair
-version:             0.1.0.1
-license:             OtherLicense
-license-file:        LICENSE
-author:              Getty Ritter
-maintainer:          gdritter@galois.com
-category:            Codec
-build-type:          Simple
-cabal-version:       >=1.10
-
-executable rsa-pair
-  main-is:             RSAPair.hs
-  build-depends:       base >=4.6 && <4.8,
-                       bytestring, binary, DRBG, crypto-api, RSA
-  hs-source-dirs:      src
-  default-language:    Haskell2010

+ 0 - 2
RSAPair/Setup.hs

@@ -1,2 +0,0 @@
-import Distribution.Simple
-main = defaultMain

+ 0 - 27
RSAPair/src/RSAPair.hs

@@ -1,27 +0,0 @@
-module Main where
-
-import           Codec.Crypto.RSA
-import           Crypto.Random
-import           Crypto.Random.DRBG
-import           Data.Binary
-import qualified Data.ByteString.Lazy as BS
-import           Numeric (showHex)
-import           System.Environment (getArgs)
-import           System.IO (hPutStrLn, stderr)
-
-toHex :: (Binary a) => a -> String
-toHex = concat . map (flip showHex "") . BS.unpack . encode
-
-main :: IO ()
-main = do
-  args <- getArgs
-  let size = case args of (s:_) -> read s
-                          _     -> 1024
-  hPutStrLn stderr ("Generating key pair of size " ++ show size)
-  (pub, priv) <- genPair size
-  putStrLn ("pub: " ++ toHex pub)
-  putStrLn ("priv: " ++ toHex priv)
-
-genPair :: Int -> IO (PublicKey, PrivateKey)
-genPair size = go `fmap` (newGenIO :: IO HashDRBG)
-  where go g = let (pub, priv, _) = generateKeyPair g size in (pub, priv)

+ 1 - 3
json2bencode/json2bencode.cabal

@@ -12,9 +12,7 @@ cabal-version:       >=1.10
 
 
 executable json2bencode
 executable json2bencode
   main-is:             Main.hs
   main-is:             Main.hs
-  -- other-modules:       
-  -- other-extensions:    
-  build-depends:       base >=4.8 && <4.9,
+  build-depends:       base,
                        aeson,
                        aeson,
                        bencode,
                        bencode,
                        bytestring,
                        bytestring,

+ 0 - 32
json2bencode/stack.yaml

@@ -1,32 +0,0 @@
-# For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md
-
-# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
-resolver: lts-3.19
-
-# Local packages, usually specified by relative directory name
-packages:
-- '.'
-
-# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3)
-extra-deps: []
-
-# Override default flag values for local packages and extra-deps
-flags: {}
-
-# Extra package databases containing global packages
-extra-package-dbs: []
-
-# Control whether we use the GHC we find on the path
-# system-ghc: true
-
-# Require a specific version of stack, using version ranges
-# require-stack-version: -any # Default
-# require-stack-version: >= 0.1.4.0
-
-# Override the architecture used by stack, especially useful on Windows
-# arch: i386
-# arch: x86_64
-
-# Extra directories used by stack for building
-# extra-include-dirs: [/path/to/dir]
-# extra-lib-dirs: [/path/to/dir]

+ 38 - 0
scripts/dir2yaml

@@ -0,0 +1,38 @@
+#!/usr/bin/python
+
+import os
+import sys
+import json
+import yaml
+
+
+def die(msg, *args):
+    sys.stderr.write(msg + '\n', *args)
+    sys.exit(99)
+
+
+def load_dir(dir_name):
+    if not os.path.isdir(dir_name):
+        die("{0} is not a directory", dir_name)
+    else:
+        return dict((path, load_elem(os.path.join(dir_name, path)))
+                    for path in os.listdir(dir_name) if path[0] != '.')
+
+
+def load_elem(path):
+    if os.path.isdir(path):
+        return load_dir(path)
+    else:
+        with open(path) as f:
+            content = f.read()
+        try:
+            return json.loads(content)
+        except ValueError:
+            return content.strip()
+
+if __name__ == '__main__':
+    if sys.argv[1:]:
+        dir_name = sys.argv[1]
+    else:
+        dir_name = os.getcwd()
+    yaml.dump(load_dir(dir_name), sys.stdout)

+ 2 - 4
scripts/ghci-with

@@ -39,7 +39,5 @@ cat >>$DIR/$PKG.cabal <<EOF
 EOF
 EOF
 
 
 cd $DIR
 cd $DIR
-cabal sandbox init
-cabal install
-cabal configure
-exec cabal repl
+cabal new-build
+exec cabal new-repl

+ 21 - 7
scripts/mk-cabal-executable-file

@@ -10,7 +10,7 @@ elif [ $# -eq 2 ]; then
 	EXENAME="$1"
 	EXENAME="$1"
 	TGT="$2"
 	TGT="$2"
 else
 else
-	echo "USAGE: $0 [library name]" >&2
+	echo "USAGE: $0 [executable name]" >&2
 	exit 99
 	exit 99
 fi
 fi
 
 
@@ -19,26 +19,38 @@ EMAIL=$(git config user.email)
 USER="${NAME} <${EMAIL}>"
 USER="${NAME} <${EMAIL}>"
 YEAR=$(date '+%Y')
 YEAR=$(date '+%Y')
 
 
-if [ "${CATEGORY}x" = "x" ]; then
-	CAT_LINE="-- category:"
+if [ -z "${CATEGORY}" ]; then
+    CAT_FIELD="-- category:"
 else
 else
-	CAT_LINE="category:         ${CATEGORY}"
+    CAT_FIELD="category:         ${CATEGORY}"
+fi
+
+if [ -z "${SYNOPSIS}" ]; then
+    SYN_FIELD="-- synopsis:"
+else
+    SYN_FIELD="synopsis:         ${SYNOPSIS}"
+fi
+
+if [ -z "${DESCRIPTION}" ]; then
+    DESCR_FIELD="-- description:"
+else
+    DESCR_FIELD="description:      ${DESCRIPTION}"
 fi
 fi
 
 
 function cabal_file {
 function cabal_file {
 	cat <<EOF
 	cat <<EOF
 name:             ${EXENAME}
 name:             ${EXENAME}
 version:          0.1.0.0
 version:          0.1.0.0
+${SYN_FIELD}
+${DESCR_FIELD}
 license:          BSD3
 license:          BSD3
 license-file:     LICENSE
 license-file:     LICENSE
 author:           ${USER}
 author:           ${USER}
 maintainer:       ${USER}
 maintainer:       ${USER}
 copyright:        ©${YEAR} ${NAME}
 copyright:        ©${YEAR} ${NAME}
-${CAT_LINE}
+${CAT_FIELD}
 build-type:       Simple
 build-type:       Simple
-cabal-version:    >= 1.12
+cabal-version:    >= 1.14
 
 
 executable ${EXENAME}
 executable ${EXENAME}
   hs-source-dirs:      src
   hs-source-dirs:      src
@@ -46,7 +58,7 @@ executable ${EXENAME}
   default-extensions:  OverloadedStrings,
   default-extensions:  OverloadedStrings,
                        ScopedTypeVariables
                        ScopedTypeVariables
   ghc-options:         -Wall
   ghc-options:         -Wall
-  build-depends:       base >=4.7 && <4.9
+  build-depends:       base >=4.7 && <4.10
   default-language:    Haskell2010
   default-language:    Haskell2010
 EOF
 EOF
 }
 }

+ 29 - 6
scripts/mk-cabal-file

@@ -1,14 +1,16 @@
 #!/bin/bash -e
 #!/bin/bash -e
-
-if [ $# -lt 1 ]; then
-	echo "USAGE: $0 [library name]" >&2
-	exit 99
+if [ $# -eq 0 ]; then
+	LIBNAME="$(basename $(pwd))"
+	TGT="-"
 elif [ $# -eq 1 ]; then
 elif [ $# -eq 1 ]; then
 	LIBNAME="$1"
 	LIBNAME="$1"
 	TGT='-'
 	TGT='-'
 elif [ $# -eq 2 ]; then
 elif [ $# -eq 2 ]; then
 	LIBNAME="$1"
 	LIBNAME="$1"
 	TGT="$2"
 	TGT="$2"
+else
+	echo "USAGE: $0 [library name]" >&2
+	exit 99
 fi
 fi
 
 
 NAME=$(git config user.name)
 NAME=$(git config user.name)
@@ -16,25 +18,43 @@ EMAIL=$(git config user.email)
 USER="${NAME} <${EMAIL}>"
 USER="${NAME} <${EMAIL}>"
 YEAR=$(date '+%Y')
 YEAR=$(date '+%Y')
 
 
+if [ -z "${CATEGORY}" ]; then
+    CAT_FIELD="-- category:"
+else
+    CAT_FIELD="category:         ${CATEGORY}"
+fi
+
+if [ -z "${SYNOPSIS}" ]; then
+    SYN_FIELD="-- synopsis:"
+else
+    SYN_FIELD="synopsis:         ${SYNOPSIS}"
+fi
+
+if [ -z "${DESCRIPTION}" ]; then
+    DESCR_FIELD="-- description:"
+else
+    DESCR_FIELD="description:      ${DESCRIPTION}"
+fi
+
 function cabal_file {
 function cabal_file {
 	cat <<EOF
 	cat <<EOF
 name:             ${LIBNAME}
 name:             ${LIBNAME}
 version:          0.1.0.0
 version:          0.1.0.0
+${SYN_FIELD}
+${DESCR_FIELD}
 license:          BSD3
 license:          BSD3
 license-file:     LICENSE
 license-file:     LICENSE
 author:           ${USER}
 author:           ${USER}
 maintainer:       ${USER}
 maintainer:       ${USER}
 copyright:        ©${YEAR} ${NAME}
 copyright:        ©${YEAR} ${NAME}
+${CAT_FIELD}
 build-type:       Simple
 build-type:       Simple
-cabal-version:    >= 1.12
+cabal-version:    >= 1.14
 
 
 library
 library
 --  exposed-modules:
 --  exposed-modules:
   ghc-options:         -Wall
   ghc-options:         -Wall
-  build-depends:       base >=4.7 && <4.9
+  build-depends:       base >=4.7 && <4.10
   default-language:    Haskell2010
   default-language:    Haskell2010
   default-extensions:  OverloadedStrings,
   default-extensions:  OverloadedStrings,
                        ScopedTypeVariables
                        ScopedTypeVariables

+ 45 - 0
scripts/mp3rename

@@ -0,0 +1,45 @@
+#!/usr/bin/python2
+
+import eyed3
+
+import sys
+
+def err(*args):
+    sys.stderr.write(" ".join(args) + "\n")
+
+def die(*args):
+    err(*args)
+    sys.exit(1)
+
+USAGE='Usage: {0} [file]'.format(sys.argv[0])
+
+def to_file_case(name):
+    for ch in name:
+        if ord(ch) > 127:
+            err("ERROR: {0} outside ASCII range".format(ord(ch)))
+            raise Exception("NonAsciiName")
+    return '_'.join(name.lower().split())
+
+filenames = sys.argv[1:]
+
+if not filenames:
+    die(USAGE)
+
+def do_rename(filename):
+    audiofile = eyed3.load(filename)
+
+    (tn,_) = audiofile.tag.track_num
+    if tn is None:
+        err("ERROR: Unknown track number for file `{0}'".format(filename))
+
+    title = audiofile.tag.title
+    newname = '{0:02}_-_{1}'.format(tn, to_file_case(title))
+
+    print "renaming: `{0}' -> `{1}'".format(filename, newname)
+    audiofile.rename(newname)
+
+for f in filenames:
+    try:
+        do_rename(f)
+    except:
+        err("ERROR: Unable to rename `{0}'".format(f))

+ 3 - 3
scripts/new-cabal-exec

@@ -4,15 +4,15 @@ if [ $# -gt 0 ]; then
     NAME="$1"
     NAME="$1"
 	shift
 	shift
 else
 else
-    NAME="$(basename $(pwd))"
+    NAME="$(basename "$(pwd)")"
 fi
 fi
 
 
-VERSION="$(cat *.cabal | grep -e '^version' | grep -o -e '[0-9.]*')"
+VERSION="$(cat ./*.cabal | grep -e '^version' | grep -o -e '[0-9.]*')"
 PROGRAM="$(find dist-newstyle -type f -executable -name "$NAME" | grep -e "${VERSION}" | head -n 1)"
 PROGRAM="$(find dist-newstyle -type f -executable -name "$NAME" | grep -e "${VERSION}" | head -n 1)"
 
 
 
 
 if [ ! "${PROGRAM}" = "" ]; then
 if [ ! "${PROGRAM}" = "" ]; then
-	exec "${PROGRAM}" $@
+	exec "${PROGRAM}" "$@"
 else
 else
 	echo "cannot find executable: ${NAME}-${VERSION}" >&2
 	echo "cannot find executable: ${NAME}-${VERSION}" >&2
 	exit 99
 	exit 99

+ 22 - 0
scripts/panview

@@ -0,0 +1,22 @@
+#!/bin/bash -e
+
+FILE=$(mktemp)
+if [ $# -lt 1 ]; then
+    INP="-"
+else
+    INP="$1"
+    shift
+fi
+
+if [ x"$1" = x--github ]; then
+    FMT="markdown_github"
+elif [ x"$1" = x--rst ]; then
+    FMT="rst"
+else
+    FMT="markdown"
+fi
+
+echo "format: $FMT; source: $INP; tmp location: $FILE"
+pandoc --standalone -f $FMT -i $INP -t html -o $FILE
+surf $FILE
+rm $FILE

+ 0 - 4
scripts/twit

@@ -1,4 +0,0 @@
-#!/bin/sh
-
-THEME=solarized-dark TWIT=true BARE=true emacs
-

+ 0 - 4
scripts/windows

@@ -1,4 +0,0 @@
-#!/bin/sh
-
-RES="xrandr | grep '\*' | grep -o '[0-9]*x[0-9]'*"
-rdesktop -g $RES porthole.galois.com

+ 40 - 0
scripts/yaml2dir

@@ -0,0 +1,40 @@
+#!/usr/bin/python
+
+import os
+import sys
+import json
+import yaml
+
+
+def die(msg, *args):
+    sys.stderr.write(msg + '\n', *args)
+    sys.exit(99)
+
+
+def emit(datum, root='./'):
+    if type(datum) is not dict:
+        die("Unexpected type: {0} of type {1}", datum, type(datum))
+    else:
+        for key, val in datum.items():
+            if type(val) is dict:
+                new_root = os.path.join(root, key)
+                os.makedir(new_root)
+                emit(val, root=new_root)
+            elif type(val) is list:
+                die("Cannot serialize lists: {0}", datum)
+            elif type(val) is str or type(val) is unicode:
+                with open(os.path.join(root, key), 'w') as f:
+                    f.write(val)
+                    f.write('\n')
+            else:
+                with open(os.path.join(root, key), 'w') as f:
+                    json.dump(val, f)
+                    f.write('\n')
+
+if __name__ == '__main__':
+    if sys.argv[:1] and sys.argv[1] != '-':
+        with open(sys.argv[1]) as f:
+            datum = yaml.load(f)
+    else:
+        datum = yaml.load(sys.stdin)
+    emit(datum)