diff options
author | makefu <github@syntax-fehler.de> | 2013-03-07 11:40:38 +0100 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2013-03-07 11:40:38 +0100 |
commit | 7fa8fb85b072f612adb322f8a02617e1bd737020 (patch) | |
tree | 683df8268baae71451633518aa7ff7ea258a4aa8 /util | |
parent | dbe2d838ba6834788265029162b2dd7d82473335 (diff) | |
parent | ef4eb3189363f5cd9a33b43693322a68d3142979 (diff) |
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'util')
-rw-r--r-- | util/README.markdown | 27 | ||||
-rwxr-xr-x | util/bin/dict.leo.org | 87 | ||||
-rwxr-xr-x | util/bin/with | 6 | ||||
-rw-r--r-- | util/lib/geo/Makefile | 15 | ||||
-rw-r--r-- | util/lib/geo/index.js | 48 | ||||
-rw-r--r-- | util/lib/geo/package.json | 7 |
6 files changed, 103 insertions, 87 deletions
diff --git a/util/README.markdown b/util/README.markdown new file mode 100644 index 00000000..78b9b81a --- /dev/null +++ b/util/README.markdown @@ -0,0 +1,27 @@ +# various utils + +## //util/bin/with + + execute a command with an extended/modified environment + +### usage + + with ENV COMMAND + + where `ENV` is the name of the environment and + `COMMAND` your to-be-executed command (-line). + +### environment + + `env_dir` defines the directory where environment files are searched + (default: `$HOME/.env.d`). + +### example + + cat > ~/.env.d/frh-ire <<EOF + export api_url=... + export api_key=... + export api_hash=... + EOF + + with frh-ire //ext/solus/bin/client info diff --git a/util/bin/dict.leo.org b/util/bin/dict.leo.org deleted file mode 100755 index 03f16b96..00000000 --- a/util/bin/dict.leo.org +++ /dev/null @@ -1,87 +0,0 @@ -#! /bin/sh -#### dict.leo.org version 2.0 beta 1 -set -euf - -cache_dir=/tmp/dict.leo.org/ -file="$cache_dir$*" - -url="http://dict.leo.org/?$*" - -# TODO check sanity of filename - -if test -d "$cache_dir" ; then - test -e "$file" || { curl --silent "$url" | tee "$file" ; } -else - curl --silent "$url" -fi | -sed 's/>\( *.\)/>\n\1/g' | sed -n ' - s/[[:space:]]/ /g - /<!-- # Werbung # -->/,/<\/td>/b - /<!-- ============================================== -->/,/^<\/td>/b - /<!-- # Trailer # -->/,/^ <\/table>/b - /<table id="subnavigation" class="border">/,/<\/table>/b - /<div id="divMoreInfo" class="popup">/,/^ <\/table>/b - - ## show link in rendered version - s/^<a href="\(.*searchLocRelinked.*\)">$/&mehr: \1/ - s/^mehr >>// - - s/<[Bb][Rr] *\/>/,/g - - p - b - :c;# comment - s/-->/\\-\\-\\>/g - s/<!--/\\<\\!\\-\\-/g - s/.*/<!--(&)-->/ - p -' \ -| w3m -cols 1024 -T text/html -dump | sed ' - s/[[:space:]]\+/ /g - s/ ,/,/g - s/^ //;s/ $// - s/[┌┬┐└┴┘├┼┤─]//g - s/ *│ */|/g - s/\[ \]// - s/\[Speichern\] der ausgewa:hlten Wo:rter im Trainer// - s/^||//;s/|| \?$// -' | sed -n ' - /^\[EN-> DE\]/,$b - s/^mehr: /+ / - s/^ENGLISCH||DEUTSCH \?/= Englisch -> Deutsch/ - s/^|\([0-9]\+\) \(Treffer\)|$/= \1 \2/ - s/^\([^|]\+\)||\([^|]\+\)$/- \1|\2/ - - s/^[^=+#-][^|]\+$/## &/ - - p -' | sed -n ' - /^$/b - s/ \([?!]\)/\1/g - s/\([[(]\) /\1/g;s/ \([]\)]\)/\1/g - - s/ ([0-9]\+ of [0-9]\+) \?//;# TODO - - #s/^##.*Grundform.*/\n#&/ - /^## .*Grundform.*/,/^##\( .*\)\?/{ - /##/{/Grundform/!p} - b - } - - /^## Informationen /,$b;# TODO - #/^## Beispiele/,$b;# TODO - #/^## Wendungen/,$b;# TODO - /^+/b;# TODO - #/^=/b;# TODO - - p -' | sed ' - ## - s/|\(.*\)/\n [32m\1[m/g - s/^#.*/\n[33m&[m/ - - s/##.*Treffer $/\n[1;33m#&[m/ -' | less -R -echo - -#### end of file. diff --git a/util/bin/with b/util/bin/with new file mode 100755 index 00000000..97893faf --- /dev/null +++ b/util/bin/with @@ -0,0 +1,6 @@ +#! /bin/sh +set -euf +ENV="${env_dir-$HOME/.env.d}/$1" +shift +. "$ENV" +exec "$@" diff --git a/util/lib/geo/Makefile b/util/lib/geo/Makefile new file mode 100644 index 00000000..d13cd471 --- /dev/null +++ b/util/lib/geo/Makefile @@ -0,0 +1,15 @@ +all: node_modules GeoLiteCity.dat + +node_modules: package.json + npm install + @touch -r $< $@ + +GeoLiteCity.dat: + @test -e GeoLiteCity.dat && ln -s GeoLiteCity.dat $@ || { \ + echo 'No GeoIP City database found.'; \ + echo 'You can get one from http://dev.maxmind.com/geoip/geolite:'; \ + echo ' wget -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz'; \ + echo ' gunzip GeoLiteCity.dat.gz'; \ + exit 23; \ + } + diff --git a/util/lib/geo/index.js b/util/lib/geo/index.js new file mode 100644 index 00000000..0763b1a4 --- /dev/null +++ b/util/lib/geo/index.js @@ -0,0 +1,48 @@ +function slurp (stream, callback) { + var data = [] + stream.on('data', function (chunk) { + data.push(chunk) + }) + stream.on('end', function () { + callback(null, Buffer.concat(data)) + }) + stream.resume() +} + + +var path = require('path') +var city_dat = path.join(__dirname, 'GeoLiteCity.dat') + +var geoip = require('geoip') +var city = new geoip.City(city_dat) + +slurp(process.stdin, function (err, data) { + var lines = data.toString().split('\n') + // remove last, empty element (caused by the [mandatory] final \n) + if (lines.length > 1 && lines[lines.length - 1] === '') { + lines.pop() + } + var name = 0, addr = 1 + lines + .map(function (line) { return line.split(' ') }) + .forEach(function (host) { + //city.lookup(host[addr], function (err, loc) { + // if (err) { + // console.error('#', host[name], err.message) + // } else { + // console.log(host[name] + ': ' + loc.longitude + ',' + loc.latitude) + // } + //}) + var loc = city.lookupSync(host[addr]) + //if (!loc) { console.error('#', host[name]) } + if (loc) { + var a = loc.latitude + var b = loc.longitude + //var c = loc.altitude + //var geo = 'geo:' + [a,b,c].join(',') + var geo = 'geo:' + [a,b].join(',') + + console.log(host[name], geo) + } + }) +}) diff --git a/util/lib/geo/package.json b/util/lib/geo/package.json new file mode 100644 index 00000000..ad449a62 --- /dev/null +++ b/util/lib/geo/package.json @@ -0,0 +1,7 @@ +{ + "name": "geo", + "version": "0.0.0", + "dependencies": { + "geoip": "*" + } +} |