Browse Source

Merges resolved (but seriously, what kind of conflicts were those?)

Getty Ritter 8 years ago
parent
commit
e2794df602

+ 5 - 0
.gitignore

@@ -0,0 +1,5 @@
+*~
+.cabal-sandbox
+.stack-work
+cabal.sandbox.config
+dist

+ 30 - 0
json2bencode/LICENSE

@@ -0,0 +1,30 @@
+Copyright (c) 2016, Getty Ritter
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+
+    * Neither the name of Getty Ritter nor the names of other
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 2 - 0
json2bencode/Setup.hs

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

+ 27 - 0
json2bencode/json2bencode.cabal

@@ -0,0 +1,27 @@
+name:                json2bencode
+version:             0.1.0.0
+synopsis:            A utility for converting JSON to Bencode
+license:             BSD3
+license-file:        LICENSE
+author:              Getty Ritter
+maintainer:          gettyritter@gmail.com
+copyright:           2016
+category:            Data
+build-type:          Simple
+cabal-version:       >=1.10
+
+executable json2bencode
+  main-is:             Main.hs
+  -- other-modules:       
+  -- other-extensions:    
+  build-depends:       base >=4.8 && <4.9,
+                       aeson,
+                       bencode,
+                       bytestring,
+                       containers,
+                       scientific,
+                       text,
+                       unordered-containers,
+                       vector
+  hs-source-dirs:      src
+  default-language:    Haskell2010

+ 48 - 0
json2bencode/src/Main.hs

@@ -0,0 +1,48 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Main where
+
+import           Data.Aeson
+import           Data.BEncode
+import           Data.ByteString.Lazy (ByteString, fromStrict)
+import qualified Data.ByteString.Lazy.Char8 as BS
+import qualified Data.HashMap.Strict as HM
+import qualified Data.Map.Lazy as M
+import           Data.Scientific (isInteger)
+import           Data.Text (Text, unpack)
+import           Data.Text.Encoding (encodeUtf8)
+import qualified Data.Vector as V
+import           System.Environment (getArgs)
+import           System.Exit (die)
+
+byteify :: Text -> ByteString
+byteify = fromStrict . encodeUtf8
+
+convert :: Value -> Either String BEncode
+convert (Object os) =
+  (BDict . M.fromList) `fmap` mapM go (HM.toList os)
+  where go (k, v) = (,) (unpack k) `fmap` convert v
+convert (Array as) =
+  BList `fmap` mapM convert (V.toList as)
+convert (Number n)
+  | isInteger n = return $ BInt (floor n)
+  | otherwise   = Left ("Input contains a non-integer number: " ++ show n)
+convert (String ts) =
+  return $ BString (byteify ts)
+convert (Bool b) = Left ("Input contains a boolean: " ++ show b)
+convert (Null) = return $ BString ""
+
+main :: IO ()
+main = do
+  content <- do
+    args <- getArgs
+    case args of
+      []     -> BS.getContents
+      ["-"]  -> BS.getContents
+      [file] -> BS.readFile file
+      _      -> die "Usage: json2bencode [file]"
+  case decode content of
+    Just val -> case convert val of
+      Right bval -> BS.putStrLn (bPack bval)
+      Left err   -> putStrLn err
+    Nothing -> putStrLn "Unable to parse JSON"

+ 32 - 0
json2bencode/stack.yaml

@@ -0,0 +1,32 @@
+# 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]

+ 3 - 0
scripts/add-link

@@ -0,0 +1,3 @@
+#!/bin/sh
+
+LIB_REPO=/home/gdritter/projects/sites/lib-data /home/gdritter/projects/sites/lib-static/utils/add-link $@

+ 3 - 0
scripts/add-quip

@@ -0,0 +1,3 @@
+#!/bin/sh
+
+LIB_REPO=/home/gdritter/Projects/sites/lib-data /home/gdritter/Projects/sites/lib-static/utils/add-quip $@

+ 3 - 0
scripts/add-quote

@@ -0,0 +1,3 @@
+#!/bin/sh
+
+LIB_REPO=/home/gdritter/projects/sites/lib-data /home/gdritter/projects/sites/lib-static/utils/add-quote $@

+ 35 - 0
scripts/adjust-screens

@@ -0,0 +1,35 @@
+#!/usr/bin/python2
+
+import subprocess
+import sys
+
+def invoke(args):
+    sys.stderr.write('invoke("{0}")\n'.format(' '.join(args)))
+    p = subprocess.Popen(args, stdout=subprocess.PIPE)
+    return p.stdout.readlines()
+
+disps = set()
+for x in invoke(['xrandr']):
+    if x and not x[0].isspace():
+        cdisp = x.split()[0]
+    else:
+        disps.add(cdisp)
+
+if disps:
+    sys.stderr.write("connected displays: {0}\n".format(', '.join(disps)))
+
+if len(disps) <= 0:
+    sys.stderr.write("no displays connected.\n")
+    sys.exit(1)
+elif len(disps) == 1:
+    args = ['xrandr', '--auto']
+    invoke(args)
+elif len(disps) == 2:
+    other = (disps ^ set(['eDP1'])).pop()
+    invoke(['xrandr', '--output', 'eDP1', '--primary', '--left-of',
+            other, '--output', other, '--auto'])
+else:
+    sys.stderr.write("more than two connected displays;\n")
+    sys.stderr.write("unsure how to continue\n")
+    sys.exit(1)
+# invoke(['/home/gdritter/Pictures/ghibli/rand.sh'])

+ 1 - 1
scripts/as-tmp

@@ -2,4 +2,4 @@
 
 FILENAME=$(mktemp)
 cat >$FILENAME
-echo $FILENAME
+echo $FILENAME

+ 6 - 0
scripts/avg

@@ -0,0 +1,6 @@
+#!/bin/python2
+
+import sys
+
+nums = [float(l) for l in sys.stdin.read().split()]
+print sum(nums) / float(len(nums))

+ 9 - 0
scripts/docker-delete-images

@@ -0,0 +1,9 @@
+#!/bin/bash
+
+if [ "x$1" = "x--YES" ]; then
+  sudo docker rm $(sudo docker ps -a -q)
+  sudo docker rmi $(sudo docker images -a -q)
+else
+  echo "ARE YOU SURE YOU WANT TO DO THIS?"
+  echo "If so, re-run with --YES"
+fi

+ 1 - 1
scripts/ff-here

@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 if [[ "$1" = /* ]]; then
 	firefox file://$1

+ 3 - 0
scripts/gdr-img

@@ -0,0 +1,3 @@
+#!/bin/sh
+
+scp $1 rosencrantz:/srv/http/gdr/www/imgs/.

+ 24 - 0
scripts/ghc-clean-pkgs

@@ -0,0 +1,24 @@
+# unregister broken GHC packages. Run this a few times to resolve dependency rot in installed packages.                                                                                                                                     
+# ghc-pkg-clean -f cabal/dev/packages*.conf also works.                                                                                                                                                                                     
+function ghc-pkg-clean() {
+    for p in `ghc-pkg check $* 2>&1  | grep problems | awk '{print $6}' | sed -e 's/:$//'`
+    do
+        echo unregistering $p; ghc-pkg $* unregister $p
+    done
+}
+
+# remove all installed GHC/cabal packages, leaving ~/.cabal binaries and docs in place.                                                                                                                                                     
+# When all else fails, use this to get out of dependency hell and start over.                                                                                                                                                               
+function ghc-pkg-reset() {
+    read -p 'erasing all your user ghc and cabal packages - are you sure (y/n) ? ' ans
+    test x$ans == xy && ( \
+        echo 'erasing directories under ~/.ghc'; rm -rf `find ~/.ghc -maxdepth 1 -type d`; \
+        echo 'erasing ~/.cabal/lib'; rm -rf ~/.cabal/lib; \
+        # echo 'erasing ~/.cabal/packages'; rm -rf ~/.cabal/packages; \                                                                                                                                                                     
+        # echo 'erasing ~/.cabal/share'; rm -rf ~/.cabal/share; \                                                                                                                                                                           
+        )
+}
+
+alias cabalupgrades="cabal list --installed  | egrep -iv '(synopsis|homepage|license)'"
+
+ghc-pkg-clean

+ 85 - 0
scripts/ghc-wrapper

@@ -0,0 +1,85 @@
+#!/bin/bash -e
+
+# ghc wrapper script (for managing installed GHC versions)
+# this is a small script I use that allows multiple simultaneous ghc
+# installations. This makes the following assumptions about how
+# you want to set up your system:
+# - GHC version {X} is installed with prefix ~/install/ghc-${X}
+# - A file naming the current selected GHC version is placed
+#   at ~/.current-ghc
+# - cabal is configured to point to this script instead of ghc
+# - If using fetch, then mktemp must result in a directory to which
+#   this script can write, as well
+# This script is being run as a user that can read and modify things
+# in your $HOME directory.
+
+if [[ "$1" = "list" ]]; then
+    for f in $(ls ~/install/ | grep ghc); do
+        # It's possible (for various reasons) for /none/ of the
+        # current versions to be selected, in which case all of
+        # them will be prefixed by a -; otherwise, the one that
+        # is selected will be prefixed by a +.
+        if [[ "$f" = "$(cat ~/.current-ghc)" ]]; then
+            echo "+" $f
+        else
+            echo "-" $f
+        fi
+    done
+elif [[ "$1" = "set" ]]; then
+    MATCHES=($(ls ~/install | grep ghc | grep -e "$2"))
+    if [[ -z $MATCHES ]]; then
+        # There is nothing in ~/install that matches that version
+        echo "Unknown GHC version: $2"
+    elif [ "${#MATCHES[@]}" -eq "1" ]; then
+        # There is exactly one relevant match---we can use that one!
+        echo "Setting GHC version to $MATCHES"
+        echo $MATCHES >~/.current-ghc
+    else
+        # The regex given matches too many versions.
+        echo "Ambiguous GHC version: argument matches"
+        for f in "${MATCHES[@]}"; do
+            echo "  " $f
+        done
+    fi
+elif [[ "$1" = "fetch" ]]; then
+    VERSION="$2"
+    URL="https://www.haskell.org/ghc/dist/$VERSION/ghc-$VERSION-src.tar.xz"
+    LOC=$(mktemp -d)
+    (
+        echo "Attempting to fetch $URL..." &&
+        curl -L "$URL" >"$LOC/ghc.tar.xz" &&
+        cd "$LOC" &&
+        echo "...tarball fetched; unpacking..." &&
+        tar -xf "ghc.tar.xz" &&
+        cd "$LOC/ghc-$VERSION" &&
+        echo "Creating $HOME/install/ghc-$VERSION" &&
+        mkdir -p "$HOME/install/ghc-$VERSION" &&
+        ./configure --prefix="$HOME/install/ghc-$VERSION" &&
+        echo "... starting build process..." &&
+        make &&
+        make install &&
+        echo "...finished!"
+    )
+elif [[ "$1" = "--wrapper-help" ]]; then
+    cat <<EOF
+$0 [wrapper script]
+Usage:
+  $0 list              List installed versions of ghc
+  $0 set [regex]       Set current GHC to the version that uniquely
+                          matches the supplied regex
+  $0 fetch [version]   Fetch, build, and install the specified version
+                          of GHC. (Does not change the current version.)
+  $0 --wrapper-help    See this help menu
+  $0 [anything else]   Use GHC normally
+
+This wrapper script assumes that you'll always install your GHC versions
+to ~/install/ghc-{VERSION}, and will store the currently selected GHC version
+in ~/.current-ghc.
+
+WARNING: This script is quite brittle and makes a lot of assumptions about
+how you lay things out! While I suspect it shouldn't actively break anything,
+be careful about using it!
+EOF
+else
+   exec /home/gdritter/install/$(cat ~/.current-ghc)/bin/$(basename $0) "$@"
+fi

+ 45 - 0
scripts/ghci-with

@@ -0,0 +1,45 @@
+#!/bin/sh -e
+
+if [ $# -lt 1 ]; then
+    echo "Usage: $0 package [package ...]" >&2
+    exit 1
+fi
+
+DIR=$(mktemp -d)
+PKG=Temporary
+
+touch $DIR/LICENSE
+
+cat >$DIR/$PKG.hs <<EOF
+module $PKG where
+EOF
+
+cat >$DIR/$PKG.cabal <<EOF
+name:           $PKG
+version:        0.0.0
+license:        OtherLicense
+license-file:   LICENSE
+cabal-version:  >= 1.10
+build-type:     Simple
+
+library
+  default-language: Haskell2010
+  exposed-modules: $PKG
+  build-depends: $1,
+EOF
+
+shift
+for DEP in $@; do
+    cat >>$DIR/$PKG.cabal <<EOF
+                 $DEP,
+EOF
+done
+cat >>$DIR/$PKG.cabal <<EOF
+                 base
+EOF
+
+cd $DIR
+cabal sandbox init
+cabal install
+cabal configure
+exec cabal repl

+ 5 - 0
scripts/git-add-untracked-sources

@@ -0,0 +1,5 @@
+#!/bin/bash -e
+
+if [[ $# -eq 1 ]]; then cd $1; fi
+
+git add $(git ls-untracked-sources)

+ 7 - 0
scripts/git-ls-untracked-sources

@@ -0,0 +1,7 @@
+#!/bin/bash -e
+
+if [[ $# -eq 1 ]]; then cd $1; fi
+
+for f in $(git ls-files --others --exclude-standard); do
+    if [[ ! -x "$f" ]]; then echo $f; fi
+done

+ 8 - 0
scripts/git-update-all

@@ -0,0 +1,8 @@
+#!/bin/bash -e
+
+if [[ $# -eq 1 ]]; then cd $1; fi
+
+REPO=$(basename $(pwd))
+TIME=$(date -Iseconds)
+git add-untracked-sources
+git commit -a -m "Updates for $REPO at $TIME"

+ 19 - 0
scripts/minimize-pdf-file-size

@@ -0,0 +1,19 @@
+#!/bin/sh
+
+if [ "$#" -lt "2" ]; then
+	APPNAME=$(basename $0)
+	echo "USAGE: $APPNAME [input pdf] [output pdf]"
+	exit 1
+fi
+
+IN=$1
+OUT=$2
+
+echo "Optimizing $IN for screen resolution, and saving to $OUT."
+
+gs -o $OUT                      \
+   -dNOPAUSE                    \
+   -sDEVICE=pdfwrite            \
+   -dCompatibilityLevel=1.4     \
+   -dPDFSETTINGS=/screen        \
+   $IN

+ 58 - 0
scripts/mk-cabal-executable-file

@@ -0,0 +1,58 @@
+#!/bin/bash -e
+
+if [ $# -eq 0 ]; then
+	EXENAME="$(basename $(pwd))"
+	TGT="-"
+elif [ $# -eq 1 ]; then
+	EXENAME="$1"
+	TGT='-'
+elif [ $# -eq 2 ]; then
+	EXENAME="$1"
+	TGT="$2"
+else
+	echo "USAGE: $0 [library name]" >&2
+	exit 99
+fi
+
+NAME=$(git config user.name)
+EMAIL=$(git config user.email)
+USER="${NAME} <${EMAIL}>"
+YEAR=$(date '+%Y')
+
+if [ "${CATEGORY}x" = "x" ]; then
+	CAT_LINE="-- category:"
+else
+	CAT_LINE="category:         ${CATEGORY}"
+fi
+
+function cabal_file {
+	cat <<EOF
+name:             ${EXENAME}
+version:          0.1.0.0
+-- synopsis:
+-- description:
+license:          BSD3
+license-file:     LICENSE
+author:           ${USER}
+maintainer:       ${USER}
+copyright:        ©${YEAR} ${NAME}
+${CAT_LINE}
+build-type:       Simple
+cabal-version:    >= 1.12
+
+executable ${EXENAME}
+  hs-source-dirs:      src
+  main-is:             Main.hs
+  default-extensions:  OverloadedStrings,
+                       ScopedTypeVariables
+  ghc-options:         -Wall
+  build-depends:       base >=4.7 && <4.9
+  default-language:    Haskell2010
+EOF
+}
+
+if [ "x${TGT}" = "x-" ]; then
+	cabal_file
+else
+	cabal_file >${TGT}
+fi

+ 48 - 0
scripts/mk-cabal-file

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

+ 27 - 0
scripts/pr-pamphlet

@@ -0,0 +1,27 @@
+#!/bin/sh
+
+if [ "$#" -lt "2"]; then
+	APPNAME=$(basename $0)
+	echo "USAGE: $APPNAME [input-file]"
+	exit 1
+fi
+
+if [[ "$1" = http* ]]; then
+	FILE=$(mktemp)
+	curl $1 >$FILE
+else
+	FILE="$1"
+fi
+
+if [[ $FILE = *pdf ]]; then
+	TMPF=$(mktemp)
+	pdf2ps $FILE $TMPF
+	
+elif [[ $FILE = *ps ]]; then
+	TMPF=$FILE
+else
+	echo "Unknown file type: $FILE"
+	exit 2
+fi
+
+cat $TMPF | psbook | psnup -pletter -2 | lpr -o sides=two-sided-short-edge -P hp4200n

+ 18 - 0
scripts/pr-paper

@@ -0,0 +1,18 @@
+#!/bin/bash -e
+
+if [ "$#" -lt "1" ]; then
+	APPNAME=$(basename $0)
+	echo "not enough arguments to $APPNAME"
+	exit 1
+fi
+
+OPTS="-P hp4200n -o number-up=2 -o sides=two-sided-long-edge"
+
+if [[ "$1" = http* ]]; then
+	FILE=$(mktemp)
+	curl "$1" >$FILE
+	lpr $OPTS $FILE
+    rm $FILE
+else
+	lpr $OPTS "$1"
+fi

+ 4 - 0
scripts/twit

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

+ 4 - 0
scripts/windows

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

+ 20 - 0
scripts/yaml2csv

@@ -0,0 +1,20 @@
+#!/usr/bin/python
+
+import sys
+import yaml
+
+def comma(x, y):
+  if x:
+    return '{0},{1}'.format(x, y)
+  else:
+    return str(y)
+
+def print_obj(obj, lead=''):
+  if type(obj) == dict:
+    for k in obj:
+      print_obj(obj[k], comma(lead, k))
+  else:
+    print(comma(lead, obj))
+
+with open(sys.argv[1]) as f:
+  print_obj(yaml.load(f))