Skip to content

Commit

Permalink
New bin goodies taken from @pengwynn & @adamyonk.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggamel committed Jan 15, 2013
1 parent 14ec6c6 commit 7bfcd3c
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bin/+x
@@ -0,0 +1,2 @@
#!/bin/sh
exec chmod +x "$@"
19 changes: 19 additions & 0 deletions bin/colordump
@@ -0,0 +1,19 @@
#!/bin/sh
# Usage: colordump
# Dump 256 ansi colors to the terminal.

printf "How each ANSI color is displayed on your terminal:\n\n"

i=0
row=0
while [ $i -lt 255 ];
do
newrow=$(expr $i / 10)
test $newrow -ne $row && printf "\n"
row=$newrow
printf "\e[%dm %03d \e[0m" $i $i
i=$(expr $i + 1)
done

printf '\n\n e.g., "\\e[41mTEXT\\e[0m" '
printf "\e[41m(for TEXT like this)\e[0m\n"
14 changes: 14 additions & 0 deletions bin/domain
@@ -0,0 +1,14 @@
# encoding: utf-8
%w(json open-uri).each { |lib| require lib }
abort "Usage: #{File.basename __FILE__} [query]" unless ARGV.first

response = open("http://domai.nr/api/json/search?q=#{ARGV.first}").read

JSON.parse(response)["results"].each do |domain|
symbol = if domain["availability"] == "available"
"\e[32m✓\e[0m" # 32 = green
else
"\e[31m✗\e[0m" # 31 = red
end
puts "#{symbol} #{domain['domain']}"
end
14 changes: 14 additions & 0 deletions bin/faces
@@ -0,0 +1,14 @@
#!/bin/zsh
faces=('ಠ_ಠ' 'ಠ_ರೃ' '﴾͡๏̯͡๏﴿' '๏_๏' 'ಠ▃ಠ' '(•‿•)' 'Ծ_Ծ' '¯\(°_o)/¯' '(✌゚∀゚)☞' '╚(•⌂•)╝' 't(-_-t)t' '(ツ)_/¯' '◔_◔' '◎⃝ _◎⃝' ';ლ(ಠ_ಠლ)' '(╯°□°)╯︵ ┻━┻' 'ᶘ ᵒᴥᵒᶅ')

if [[ -z $1 ]]; then
echo 'Choose a face and | it to pbcopy'
i=1
for f in ${faces[@]}
do
echo $i $f
i=`expr $i + 1`
done
else
echo ${faces[$1]}
fi
47 changes: 47 additions & 0 deletions bin/gxpr
@@ -0,0 +1,47 @@
#!/bin/sh
# Usage: gxpr <expression>
# Like expr(1), but uses Google's calculator to evaluate <expression>.
# When google fails, light the WolframAlpha signal
#
# Math examples:
# $ gxpr '1 + 1'
# 2
#
# $ gxpr 2 ^ 16
# 65536
#
# $ gxpr '(2 ^ 1) + (2 ^ 2) + (2 ^ 3) + (2 ^ 5)'
# 46
#
# $ gxpr '5*9+(sqrt 10)^3='
# 76.6227766
#
# Conversion examples:
# $ gxpr 1GB in KB
# 1048576 kilobytes
#
# $ gxpr 10 megabits in megabytes
# 1.25 megabytes
#
# $ gxpr 2 miles in inches
# 126720 inches

CURL='curl -s --header User-Agent:gxpr/1.0'
GOOGLE="http://www.google.com/ig/calculator"
WOLFRAM="http://www.wolframalpha.com/input/"
EXPR=$(echo "$@" | perl -MURI::Escape -ne 'chomp;print uri_escape($_)')

res=$(
$CURL "$GOOGLE?q=$EXPR" |
perl -ne '/rhs: "?([^\[\],":]+)/ and print $1' |
perl -pe 's/[^\x00-\x7F]//g'
)

# if we don't have a result, try wolfram alpha
test -z "$res" && {
echo "google doesn't know" "$@" 1>&2
echo "⌘ click: \033[4m$WOLFRAM?i=$EXPR\033[0m"
exit 1
}

echo "$res"
23 changes: 23 additions & 0 deletions bin/gzball
@@ -0,0 +1,23 @@
#!/bin/sh
# create tar.gz archives and remove original dirs
# usage: gzball [-q] DIR [DIR] ...

ECHO="echo"

# be totally quite with -q argument
if [ "$1" == "-q" ] ; then
TAR="tar czf"
shift
else
TAR="tar cvzf"
fi

# bail on first error
set -e

for p in "$@" ; do
$ECHO "$p.tar.gz" # what we're building
$TAR "$p.tar.gz" "$p" # create tar.gz archive
touch -r "$p" "$p.tar.gz" # update modified time to match original DIR
rm -rf "$p" # remove original dir
done
84 changes: 84 additions & 0 deletions bin/hman
@@ -0,0 +1,84 @@
#!/bin/bash
# Formats a man page for reading in a browser, and opens it. Example:
#
# hman xsltproc
#

stylesheet=$(cat <<eocss
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" encoding="UTF-8" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="style" />
<xsl:template match="@style|@valign|@width|@align|@border|@cellspacing|@cellpadding|@frame|@rules" />
<xsl:template match="head">
<head>
<xsl:apply-templates select="@* | *"/>
<style type="text/css">
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px;
}
a { color: #4183C4; }
h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
cursor: text;
position: relative;
}
h1 {
font-size: 28px;
color: black;
}
h2 {
font-size: 24px;
border-bottom: 1px solid #cccccc;
color: black;
}
h3 { font-size: 18px; }
h4 { font-size: 16px; }
h5 { font-size: 14px; }
h6 {
color: #777777;
font-size: 14px;
}
p, table, pre {
margin: 15px 0;
}
</style>
</head>
</xsl:template>
</xsl:stylesheet>
eocss)
if ! manpath=`man -w $@`
then
exit 1
else
if [ ${manpath##*.} = "gz" ]; then catter="gzcat"; else catter="cat"; fi
outpath="$TMPDIR$$.$RANDOM.html"
$catter $manpath | groff -mandoc -Thtml -P -r | tidy -q -asxhtml --input-encoding ascii --output-encoding utf8 2>/dev/null | xsltproc --html <(echo "$stylesheet") - > $outpath
open $outpath
fi
17 changes: 17 additions & 0 deletions bin/lsrb
@@ -0,0 +1,17 @@
#!/bin/sh
#/ Usage: lsrb <file>...
#/ List class, module, and method definitions in Ruby <file>.
set -e

# show usage
[ -z "$1" -o "$1" = "--help" ] && {
grep ^#/ <"$0" |cut -c4-
exit 2
}

# run over files and grep out interesting bits
for f in "$@"
do echo "$f:"
grep -e '^[ ]*\(class\|module\|def\|alias\|alias_method\) ' "$f" |
sed 's/^/ /'
done
12 changes: 12 additions & 0 deletions bin/ports
@@ -0,0 +1,12 @@
#!/bin/sh
#/ Usage: ports [<options>]
#/ Show processes listening on ports.
#/ Any <options> are passed to lsof
set -e

test "$1" = "--help" && {
grep ^#/ <"$0"| cut -c4-
exit 2
}

exec lsof -iTCP -sTCP:LISTEN -P "$@"
35 changes: 35 additions & 0 deletions bin/served
@@ -0,0 +1,35 @@
#!/bin/sh
# served -- no fuss working directory HTTP server
# usage: served [-p PORT] [-a ADDR]
#
# With no PORT or ADDR, bind to "localhost:3000".
#
# Supports directory index.html files and automatic
# adding of ".html" extensions.
#
# Prerequisites: ruby, thin (HTTP server)
set -e

config="/tmp/$(basename $0)-$$.ru"
trap "rm -f $config" 0

cat <<-RUBY > $config
class Rewriter < Struct.new(:app)
def call(env)
if env['PATH_INFO'] =~ /\/$/
env['PATH_INFO'] += 'index.html'
elsif env['PATH_INFO'] !~ /\.\w+$/
env['PATH_INFO'] += '.html'
end
app.call(env)
end
end
use Rack::CommonLogger
use Rewriter
use Rack::Static, :root => '$(pwd)', :urls => ["/"]
run lambda { |env| [404,{},'<h1>Not Found</h1>'] }
RUBY

thin --rackup "$config" "$@" start

0 comments on commit 7bfcd3c

Please sign in to comment.