summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gold/bitcoinwisdom/index.js84
-rw-r--r--ship/lib/punani114
2 files changed, 59 insertions, 139 deletions
diff --git a/gold/bitcoinwisdom/index.js b/gold/bitcoinwisdom/index.js
deleted file mode 100644
index 95861229..00000000
--- a/gold/bitcoinwisdom/index.js
+++ /dev/null
@@ -1,84 +0,0 @@
-var http = require('http');
-var beeper = require('./beep.js').create_beeper();
-
-setInterval(get_ticker, 1000);
-
-function get_ticker () {
- http.get('http://s1.bitcoinwisdom.com:8080/ticker', ticker_response_handler);
-}
-
-function ticker_response_handler (res) {
- var data = '';
- res.on('data', function (chunk) {
- data += chunk;
- });
- res.on('end', function () {
- try {
- data = JSON.parse(data);
- } catch (err) {
- return console.log('Error:', err);
- }
- ticker_data_handler(data);
- });
-}
-
-var last_data = {
- btceltcbtc: {
- last: 0, // price
- date: 0,
- tid: 0,
- },
-}
-
-function ticker_data_handler (data) {
- //console.log(data)
-
- var ticker = data.btceltcbtc
- var last_ticker = last_data.btceltcbtc
-
- if (ticker.date !== last_ticker.date) {
-
- var diff = ticker.last - last_ticker.last;
-
- var lag = data.now - ticker.date;
-
- freq = (2000 + 1000000 * diff) | 0;
-
- var out = [
- format_date(data.now) + '+' + pad_left(lag, 2, '0'),
- 'btceltcbtc',
- '[' + diff_color(diff) + 'm' + ticker.last + '',
- lag,
- freq,
- ];
-
- console.log(out.join(' '));
-
- beeper.beep(freq, 10);
- }
-
- last_data.btceltcbtc = data.btceltcbtc;
-}
-
-function diff_color (diff) {
- if (diff < 0) {
- return '31;1';
- } else if (diff > 0) {
- return '32;1';
- } else {
- return '33;1';
- }
-}
-
-function format_date (unix) {
- return (new Date(unix * 1000)).toISOString()
- .replace(/\.000Z$/, 'Z')
-}
-
-function pad_left (obj, num, char) {
- var str = obj.toString();
- while (str.length < num) {
- str += char;
- }
- return str;
-}
diff --git a/ship/lib/punani b/ship/lib/punani
index 8efa9e8d..dc55c256 100644
--- a/ship/lib/punani
+++ b/ship/lib/punani
@@ -1,45 +1,9 @@
#@include core
#@include _punani_db
-## usage: _punani_resolve_package PKGNAME
-_punani_resolve_package(){
- eval "set -u; echo \"\${_punanidb_${PACKER}_$1}\"" 2>/dev/null
-}
-
-KNOWN_PACKERS='pacman apt-get yum brew'
-_punani_pacman_install(){ pacman --noconfirm -S --needed "$@" ;}
-_punani_pacman_remove(){ pacman -Rcs "$@" ;}
-_punani_pacman_has(){ pacman -Q "$1" >/dev/null;}
-_punani_aptget_install(){ apt-get -y install "$@" ;}
-_punani_aptget_remove(){ apt-get -y remove "$@" ;}
-_punani_aptget_has() { dpkg -s "$1" | grep -q "Status: install";}
-_punani_yum_install(){ yum -y install "$@" ;}
-_punani_yum_remove(){ yum -y remove "$@" ;}
-_punani_yum_has() { rpm -qa --qf "%{NAME}\n"| egrep "^${1}\$" >/dev/null ;}
-_punani_brew_install(){ brew install "$@"; }
-_punani_brew_remove(){ brew remove "$@";}
-_punani_brew_has(){ error "not implemented"; return 1 ;}
-
-## usage: _punani_has PACKAGE
-_punani_has() {
- eval "_punani_${PACKER}_has \"\$1\""
-}
-
-## usage: _punani_install PACKAGE
-_punani_install() {
- eval "_punani_${PACKER}_install \"\$1\""
-}
-
-## usage: _punani_remove PACKAGE
-_punani_remove() {
- eval "_punani_${PACKER}_remove \"\$1\""
-}
-
_punani_usage='punani {install,remove,has} PACKAGE...'
punani(){
- for p in ${KNOWN_PACKERS:-null}; do
- exists $p && info "using $p" && PACKER=`echo $p | tr -d -` && break
- done || die 'Error 2: no package manager found; no punani for you!'
+ __punani_select_packer || die 'no package manager found; no punani for you!'
ACTION="$1"; shift
@@ -54,29 +18,69 @@ punani(){
case "$ACTION" in
install)
- if _punani_has $RES; then
- info "$RES already installed, skipping"
- else
- _punani_install $RES || error "cannot install $RES with $PACKER"
- fi
- ;;
+ if _punani_has $RES; then
+ info "$RES already installed, skipping"
+ else
+ _punani_install $RES || error "cannot install $RES with $PACKER"
+ fi
+ ;;
remove)
- if ! _punani_has $RES; then
- info "$RES not installed, skipping"
- else
- _punani_remove $RES || error "cannot install $RES with $PACKER"
- fi
- ;;
+ if ! _punani_has $RES; then
+ info "$RES not installed, skipping"
+ else
+ _punani_remove $RES || error "cannot install $RES with $PACKER"
+ fi
+ ;;
has)
- if _punani_has $RES; then
- info "$RES is installed"
- else
- info "$RES is not installed"
- fi
- ;;
+ if _punani_has $RES; then
+ info "$RES is installed"
+ else
+ info "$RES is not installed"
+ fi
+ ;;
*)
error "bad action: $ACTION"
die "usage: $_punani_usage"
esac
done
}
+
+## usage: _punani_has PACKAGE
+_punani_has() {
+ eval "_punani_${PACKER}_has \"\$1\""
+}
+
+## usage: _punani_install PACKAGE
+_punani_install() {
+ eval "_punani_${PACKER}_install \"\$1\""
+}
+
+## usage: _punani_remove PACKAGE
+_punani_remove() {
+ eval "_punani_${PACKER}_remove \"\$1\""
+}
+
+## usage: _punani_resolve_package PKGNAME
+_punani_resolve_package(){
+ eval "set -u; echo \"\${_punanidb_${PACKER}_$1}\"" 2>/dev/null
+}
+
+## usage: __punani_select_packer
+__punani_select_packer() {
+ for p in ${__punani_known_packers:-null}; do
+ exists $p && info "using $p" && PACKER=`echo $p | tr -d -` && break
+ done
+}
+__punani_known_packers='pacman apt-get yum brew'
+_punani_pacman_install(){ pacman --noconfirm -S --needed "$@" ;}
+_punani_pacman_remove(){ pacman -Rcs "$@" ;}
+_punani_pacman_has(){ pacman -Q "$1" >/dev/null;}
+_punani_aptget_install(){ apt-get -y install "$@" ;}
+_punani_aptget_remove(){ apt-get -y remove "$@" ;}
+_punani_aptget_has() { dpkg -s "$1" | grep -q "Status: install";}
+_punani_yum_install(){ yum -y install "$@" ;}
+_punani_yum_remove(){ yum -y remove "$@" ;}
+_punani_yum_has() { rpm -qa --qf "%{NAME}\n"| egrep "^${1}\$" >/dev/null ;}
+_punani_brew_install(){ brew install "$@"; }
+_punani_brew_remove(){ brew remove "$@";}
+_punani_brew_has(){ error "not implemented"; return 1 ;}