summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2011-06-21 21:44:46 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2011-06-21 21:44:46 -0400
commit896161c483ceef3ed16e2f19a5c05106bed04512 (patch)
tree8e79f92d7b3dfe09fa97f4ae5feb8331ad6fbb52
I can't believe I didn't have this in git before.
-rw-r--r--Makefile38
-rw-r--r--arg.c10
-rw-r--r--chardiff.sh15
-rw-r--r--chardiff_post.c25
-rw-r--r--chardiff_pre.c14
-rw-r--r--daemon.sh12
-rw-r--r--emacsmail.sh10
-rwxr-xr-xhangman.sh15
-rwxr-xr-xnewegg.sh18
-rw-r--r--ord.c15
-rw-r--r--sysfiles.sh11
-rw-r--r--urldecode.sh5
-rw-r--r--v-editor.sh7
-rw-r--r--v-www-browser.sh7
-rw-r--r--whatismyip.sh2
15 files changed, 204 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..37508a6
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,38 @@
+prefix ?= /usr/local
+bindir ?= $(prefix)/bin
+
+INSTALL = install
+RM = rm -f
+
+BINFILES = \
+ arg \
+ ord \
+ urldecode \
+ v-www-browser \
+ v-editor \
+ whatismyip \
+ chardiff \
+ chardiff_pre \
+ chardiff_post \
+ newegg \
+ hangman \
+ sysfiles \
+ daemon \
+ emacsmail
+
+all: build
+
+build: $(BINFILES)
+
+install: $(addprefix $(DESTDIR)$(bindir)/,$(BINFILES))
+
+$(DESTDIR)$(bindir)/%: % | $(DESTDIR)$(bindir)
+ $(INSTALL) '$<' '$(@D)'
+
+$(DESTDIR)$(bindir):
+ mkdir -p '$@'
+
+clean:
+ $(RM) $(BINFILES)
+ $(RM) *~
+
diff --git a/arg.c b/arg.c
new file mode 100644
index 0000000..0a57cec
--- /dev/null
+++ b/arg.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+int
+main(int argc, char* argv[]) {
+ int i;
+ for (i=1; i<argc; i++) {
+ puts(argv[i]);
+ }
+ return 0;
+}
diff --git a/chardiff.sh b/chardiff.sh
new file mode 100644
index 0000000..b6d7403
--- /dev/null
+++ b/chardiff.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+file1=${1?usage: chardiff FILE1 FILE2 [FLAGS]}
+file2=${2?usage: chardiff FILE1 FILE2 [FLAGS]}
+shift 2
+
+tmp1=`mktemp`
+chardiff_pre < "$file1" > "$tmp1"
+
+tmp2=`mktemp`
+chardiff_pre < "$file2" > "$tmp2"
+
+wdiff $@ "$tmp1" "$tmp2" | chardiff_post
+rm "$tmp1" "$tmp2"
+
diff --git a/chardiff_post.c b/chardiff_post.c
new file mode 100644
index 0000000..2145759
--- /dev/null
+++ b/chardiff_post.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+
+extern char* program_name;
+
+int
+main (int argc, char* argv[]) {
+ char c;
+ while ((c = getchar()) != EOF) {
+ if (c=='\\') {
+ char c2 = getchar();
+ switch (c2) {
+ case 'n': putchar('\n'); break;
+ case '\\': putchar('\\'); break;
+ default: putchar(c2); break;
+ }
+ }
+ char n = getchar();
+ if (n != '\n') {
+ printf(
+ "%s: found other character when expecting newline: %c",
+ argv[0], n);
+ }
+ }
+}
+
diff --git a/chardiff_pre.c b/chardiff_pre.c
new file mode 100644
index 0000000..8a68d54
--- /dev/null
+++ b/chardiff_pre.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+int
+main (int argc, char* argv[]) {
+ char c;
+ while ((c = getchar()) != EOF) {
+ switch (c) {
+ case '\n': puts("\\n"); break;
+ case '\\': puts("\\\\"); break;
+ default: printf("%c\n",c); break;
+ }
+ }
+}
+
diff --git a/daemon.sh b/daemon.sh
new file mode 100644
index 0000000..1d4965a
--- /dev/null
+++ b/daemon.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+TMP=${TMPDIR-/tmp}/daemon
+
+running=$(ps -u `whoami` -U `whoami` -o comm|grep -- "$1")
+if [ -z "$running" ]; then
+ mkdir -p "$TMP"
+ echo "daemon: starting $1"
+ nohup $@ > "$TMP/$1.out" 2> "$TMP/$1.err" &
+else
+ echo "daemon: $1 is already running"
+fi \ No newline at end of file
diff --git a/emacsmail.sh b/emacsmail.sh
new file mode 100644
index 0000000..a815997
--- /dev/null
+++ b/emacsmail.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+# emacs-mailto-handler
+
+mailto=$1
+mailto="mailto:${mailto#mailto:}"
+mailto=$(printf '%s\n' "$mailto" | sed -e 's/[\"]/\\&/g')
+elisp_expr="(mailto-compose-mail \"$mailto\")"
+
+emacsclient -a "" -c -n --eval "$elisp_expr" \
+ '(set-window-dedicated-p (selected-window) t)'
diff --git a/hangman.sh b/hangman.sh
new file mode 100755
index 0000000..5e0e138
--- /dev/null
+++ b/hangman.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+word=$1
+not=$2
+flag=$3
+
+temp=`mktemp`
+
+grep -i '^'"$word"'$' /usr/share/dict/words | grep -iv "['$not]" > "$temp"
+
+if [ "$flag" = '-l' ]; then
+ cat "$temp" | tr 'A-Z' 'a-z' | sed 's/\(.\)/\1\n/'g | sort | uniq -c | sort -n
+else
+ cat "$temp"
+fi
+rm "$temp"
diff --git a/newegg.sh b/newegg.sh
new file mode 100755
index 0000000..235000f
--- /dev/null
+++ b/newegg.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+sed -n \
+ -e 's/.*<a href="\(.*\)" title="View Details">/URL\t\1/p' \
+ -e 's/.*<span class="itemDescription">\(.*\)<\/span>/Desc\t\1/p' \
+ -e 's/.*<li class="priceFinal">\(.*\)<\/li>/Price\t\1/p' \
+ -e 's/.*<li class="priceShip">\(.*\)Shipping<\/li>/Ship\t\1/p' | \
+sed \
+ -e 's/<\/*[a-z]*>//g' \
+ -e 's/&#40;/(/g' \
+ -e 's/&#41;/)/g' \
+ -e 's/&#47;/\//g' \
+ -e 's/Ship\tFree/Ship\t$0.00/' > newegg.$$.out
+grep '^URL' newegg.$$.out | cut -f2 >newegg.$$.url
+grep '^Desc' newegg.$$.out | cut -f2 >newegg.$$.desc
+grep '^Price' newegg.$$.out | cut -f2 >newegg.$$.pri
+grep '^Ship' newegg.$$.out | cut -f2 >newegg.$$.ship
+paste newegg.$$.{url,desc,pri,ship}
+
diff --git a/ord.c b/ord.c
new file mode 100644
index 0000000..fd2eadf
--- /dev/null
+++ b/ord.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+int
+main (int argc, char* argv[]) {
+ if (argc<2) { return 1; }
+
+ int i = 0;
+ char* delim = "";
+ while (argv[1][i] != '\0') {
+ printf("%s%i",delim,(int)argv[1][i]);
+ delim=" ";
+ i++;
+ }
+}
+
diff --git a/sysfiles.sh b/sysfiles.sh
new file mode 100644
index 0000000..54229d8
--- /dev/null
+++ b/sysfiles.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+cputime_file=${TMPDIR-/tmp}/cputime
+
+mpstat -P ALL 1 > "$cputime_file" &
+
+while true; do
+ cputime="`tail -n4 "$cputime_file"`"
+ echo "$cputime">"$cputime_file"
+ sleep 1
+done
diff --git a/urldecode.sh b/urldecode.sh
new file mode 100644
index 0000000..1666621
--- /dev/null
+++ b/urldecode.sh
@@ -0,0 +1,5 @@
+#!/usr/bin/env php
+<?php
+
+$contents = file_get_contents('php://stdin');
+echo urldecode($contents);
diff --git a/v-editor.sh b/v-editor.sh
new file mode 100644
index 0000000..ef6f0a1
--- /dev/null
+++ b/v-editor.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+(if [ -n "$DISPLAY" ]; then eval ${VISUAL:-$SELECTED_EDITOR} "$@"
+ else eval ${EDITOR:-$SELECTED_EDITOR} "$@"
+fi) || eval ${ALTERNATE_EDITOR:-false} "$@"
+
+
diff --git a/v-www-browser.sh b/v-www-browser.sh
new file mode 100644
index 0000000..005b7a1
--- /dev/null
+++ b/v-www-browser.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if [ -n "$DISPLAY" ]; then
+ x-www-browser $@
+else
+ www-browser $@
+fi
diff --git a/whatismyip.sh b/whatismyip.sh
new file mode 100644
index 0000000..0d1d57f
--- /dev/null
+++ b/whatismyip.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+wget -qO- whatismyip.org | xargs echo