Merge branch 'master' of git.dolda2000.com:/srv/git/r/utils
authorFredrik Tolf <fredrik@dolda2000.com>
Wed, 23 Jan 2019 15:43:34 +0000 (16:43 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Wed, 23 Jan 2019 15:43:34 +0000 (16:43 +0100)
gpgrep [new file with mode: 0755]
gpvi [new file with mode: 0755]
loadcpu.c
planime

diff --git a/gpgrep b/gpgrep
new file mode 100755 (executable)
index 0000000..7734a8d
--- /dev/null
+++ b/gpgrep
@@ -0,0 +1,44 @@
+#!/usr/bin/python3
+
+import sys, getopt, subprocess, re
+
+def usage(out):
+    out.write("usage: gpgrep PATTERN FILENAME\n")
+
+opts, args = getopt.getopt(sys.argv[1:], "h")
+for o, a in opts:
+    if o == "-h":
+        usage(sys.stdout)
+        sys.exit(0)
+if len(args) < 2:
+    usage(sys.stderr)
+    sys.exit(1)
+
+try:
+    pattern = re.compile(args[0], re.IGNORECASE)
+except Exception as exc:
+    sys.stderr.write("gpgrep: %s: %s\n" % (args[0], exc))
+    sys.exit(1)
+try:
+    efp = open(args[1], "r")
+except OSError as exc:
+    sys.stderr.write("gpgrep: %s: %s\n" % (args[1], exc.strerror))
+    sys.exit(1)
+with efp, subprocess.Popen(["gpg", "--quiet", "--decrypt", "--armor"], stdin=efp, stdout=subprocess.PIPE, universal_newlines=True) as gpg:
+    try:
+        for line in gpg.stdout:
+            line = line.rstrip()
+            if len(line) > 0 and not line[0].isspace() and pattern.search(line):
+                sys.stdout.write("%s\n" % (line))
+                for line in gpg.stdout:
+                    line = line.rstrip()
+                    if line == "" or not line[0].isspace():
+                        break
+                    sys.stdout.write("%s\n" % (line))
+                sys.exit(0)
+        sys.exit(1)
+    finally:
+        gpg.stdout.close()
+        if gpg.wait() != 0:
+            sys.stderr.write("gpgrep: gpg failed\n")
+            sys.exit(1)
diff --git a/gpvi b/gpvi
new file mode 100755 (executable)
index 0000000..481b1f2
--- /dev/null
+++ b/gpvi
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+set -e
+
+if [ $# -lt 1 ]; then
+    echo "usage: gpvi FILENAME" >&2
+    exit 1
+fi
+
+file="$1"; shift
+
+rcpt="$(gpg --batch --quiet --decrypt --list-only --status-fd 1 <"$file" | sed -n '/^\[GNUPG:\]/s/^.*ENC_TO \([^ ]*\) .*$/-r \1/p')"
+tf="$(mktemp /tmp/gpvi.XXXXXX)"
+
+gpg --quiet --decrypt --armor <"$file" >"$tf"
+omd5="$(md5sum "$tf")"
+vi -n "$tf"
+nmd5="$(md5sum "$tf")"
+if [ "$omd5" != "$nmd5" ]; then
+    gpg --quiet --encrypt --armor $rcpt <"$tf" >"${file}.new"
+    rm -f "$file~"
+    ln "$file" "$file~"
+    mv "${file}.new" "$file"
+else
+    echo "gpvi: file left unchanged, not overwriting old" >&2
+fi
+
+shred -u "$tf"
index ca39f7f..68e0429 100644 (file)
--- a/loadcpu.c
+++ b/loadcpu.c
@@ -4,6 +4,31 @@
 #include <errno.h>
 #include <pthread.h>
 
+static void *spin_snb(void *uu)
+{
+    char __attribute__((aligned(32))) m[2][32];
+    
+    asm("vpxor %%xmm1, %%xmm1, %%xmm1;\n"
+       "vpxor %%xmm2, %%xmm2, %%xmm2;\n"
+       "0:\n"
+       "vmovaps (%0), %%ymm0;\n"
+       "vmovaps %%ymm1, (%1);\n"
+       "vaddps %%ymm1, %%ymm1, %%ymm2\n"
+       "vmulps %%ymm3, %%ymm3, %%ymm4\n"
+       "vmovaps (%0), %%ymm0;\n"
+       "vmovaps %%xmm1, (%1);\n"
+       "vaddps %%ymm1, %%ymm1, %%ymm2\n"
+       "vmulps %%ymm3, %%ymm3, %%ymm4\n"
+       "vmovaps (%0), %%ymm0;\n"
+       "vaddps %%ymm1, %%ymm1, %%ymm2\n"
+       "vmulps %%ymm3, %%ymm3, %%ymm4\n"
+       "jmp 0b;\n"
+       :
+       : "r" (&m[0]), "r" (&m[1])
+       : "rax", "rcx");
+    abort();
+}
+
 static void *spin(void *uu)
 {
     while(1) {
diff --git a/planime b/planime
index 20b651e..854ef7f 100755 (executable)
--- a/planime
+++ b/planime
@@ -88,7 +88,7 @@ while [ "${1:0:1}" = - ]; do
            debug=y
            ;;
        -t)
-           cmdline=("${cmdline[@]}" -ao 'alsa:device=[hw:3,7]')
+           cmdline=("${cmdline[@]}" -audio-device 'alsa/hdmi:CARD=PCH,DEV=0')
            DISPLAY=:1
            chwp=y
            ;;