From 3e1087fd70910351e625c94570ef6fb42b9e1e45 Mon Sep 17 00:00:00 2001 From: martind2000 Date: Tue, 8 Mar 2016 21:52:21 +0000 Subject: [PATCH] init --- .gitignore | 7 + app.js | 38 + app/Robots.txt | 2 + app/app.js | 390 ++++ app/app.min.js | 10 + app/app.min.js.map | 1 + app/coins.js | 7 + app/css/clock.css | 170 ++ app/css/mui.css | 3053 +++++++++++++++++++++++++++++ app/css/mui.min.css | 1 + app/gfx/information-icon-24.png | Bin 0 -> 1259 bytes app/gfx/information-icon-32.png | Bin 0 -> 1586 bytes app/gfx/popout.png | Bin 0 -> 111 bytes app/index.html | 12 + app/jessica.html | 89 + app/js/clock.js | 114 ++ app/js/jessica.js | 424 ++++ app/js/temp.js | 54 + app/js/tempSocket.js | 47 + app/js/weight.js | 68 + app/libs/ejs.js | 505 +++++ app/libs/ejs_production.js | 1 + app/libs/microevent.js | 55 + app/libs/password.js | 109 + app/libs/skycons.js | 730 +++++++ app/libs/view.js | 200 ++ app/lot.csv | 184 ++ app/newermobile.htm | 1 + app/newmobile.htm | 64 + app/oldslack.htm | 663 +++++++ app/password.html | 0 app/password.new.html | 14 + app/slack.htm | 414 ++++ app/slack.new.html | 12 + app/template/password.ejs | 2 + app/template/trains.ejs | 17 + app/template/watchlist.ejs | 33 + app/watch.html | 222 +++ app/watchlist.json.js | 36 + data.json | 22 + ecosystem.json | 51 + lib/btc.js | 46 + lib/btc.min.js | 2 + lib/btc.min.js.map | 1 + lib/calHandler.js | 184 ++ lib/caltest.js | 28 + lib/clean.js | 49 + lib/events.js | 135 ++ lib/fx.js | 46 + lib/fx.min.js | 2 + lib/fx.min.js.map | 1 + lib/jade/test.jade | 9 + lib/jade/today.jade | 59 + lib/microevent.js | 55 + lib/newdata.json | 1 + lib/password.js | 68 + lib/swedishword.js | 45 + lib/today.html | 1 + lib/today.js | 463 +++++ lib/train.js | 181 ++ lib/train.min.js | 2 + lib/train.min.js.map | 1 + lib/weather.js | 44 + lot.js | 605 ++++++ package.json | 43 + recipes.json | 49 + routes/btc.js | 3 + savetodisk.js | 74 + scrapetest.js | 57 + single.js | 41 + snapshot.js | 52 + views/pages/cinema.ejs | 24 + views/pages/clock.ejs | 54 + views/pages/events.ejs | 25 + views/pages/slack.ejs | 363 ++++ views/pages/temp.ejs | 46 + views/pages/today.ejs | 16 + views/partials/angular_footer.ejs | 4 + views/partials/angular_head.ejs | 22 + views/partials/calendar.ejs | 13 + views/partials/cinemas.ejs | 6 + views/partials/footer.ejs | 3 + views/partials/head.ejs | 65 + views/partials/history.ejs | 14 + views/partials/trains.ejs | 18 + views/partials/tv.ejs | 13 + views/partials/weather.ejs | 26 + web-server.js | 106 + web-server.min.js | 2 + web-server.min.js.map | 1 + web-server.old.js | 145 ++ www/css/mui.css | 3053 +++++++++++++++++++++++++++++ www/css/mui.min.css | 1 + www/index.html | 7 + www/slack.htm | 487 +++++ 95 files changed, 14683 insertions(+) create mode 100644 .gitignore create mode 100644 app.js create mode 100644 app/Robots.txt create mode 100644 app/app.js create mode 100644 app/app.min.js create mode 100644 app/app.min.js.map create mode 100644 app/coins.js create mode 100644 app/css/clock.css create mode 100644 app/css/mui.css create mode 100644 app/css/mui.min.css create mode 100644 app/gfx/information-icon-24.png create mode 100644 app/gfx/information-icon-32.png create mode 100644 app/gfx/popout.png create mode 100644 app/index.html create mode 100644 app/jessica.html create mode 100644 app/js/clock.js create mode 100644 app/js/jessica.js create mode 100644 app/js/temp.js create mode 100644 app/js/tempSocket.js create mode 100644 app/js/weight.js create mode 100644 app/libs/ejs.js create mode 100644 app/libs/ejs_production.js create mode 100644 app/libs/microevent.js create mode 100644 app/libs/password.js create mode 100644 app/libs/skycons.js create mode 100644 app/libs/view.js create mode 100644 app/lot.csv create mode 100644 app/newermobile.htm create mode 100644 app/newmobile.htm create mode 100644 app/oldslack.htm create mode 100644 app/password.html create mode 100644 app/password.new.html create mode 100644 app/slack.htm create mode 100644 app/slack.new.html create mode 100644 app/template/password.ejs create mode 100644 app/template/trains.ejs create mode 100644 app/template/watchlist.ejs create mode 100644 app/watch.html create mode 100644 app/watchlist.json.js create mode 100644 data.json create mode 100644 ecosystem.json create mode 100644 lib/btc.js create mode 100644 lib/btc.min.js create mode 100644 lib/btc.min.js.map create mode 100644 lib/calHandler.js create mode 100644 lib/caltest.js create mode 100644 lib/clean.js create mode 100644 lib/events.js create mode 100644 lib/fx.js create mode 100644 lib/fx.min.js create mode 100644 lib/fx.min.js.map create mode 100644 lib/jade/test.jade create mode 100644 lib/jade/today.jade create mode 100644 lib/microevent.js create mode 100644 lib/newdata.json create mode 100644 lib/password.js create mode 100644 lib/swedishword.js create mode 100644 lib/today.html create mode 100644 lib/today.js create mode 100644 lib/train.js create mode 100644 lib/train.min.js create mode 100644 lib/train.min.js.map create mode 100644 lib/weather.js create mode 100644 lot.js create mode 100644 package.json create mode 100644 recipes.json create mode 100644 routes/btc.js create mode 100644 savetodisk.js create mode 100644 scrapetest.js create mode 100644 single.js create mode 100644 snapshot.js create mode 100644 views/pages/cinema.ejs create mode 100644 views/pages/clock.ejs create mode 100644 views/pages/events.ejs create mode 100644 views/pages/slack.ejs create mode 100644 views/pages/temp.ejs create mode 100644 views/pages/today.ejs create mode 100644 views/partials/angular_footer.ejs create mode 100644 views/partials/angular_head.ejs create mode 100644 views/partials/calendar.ejs create mode 100644 views/partials/cinemas.ejs create mode 100644 views/partials/footer.ejs create mode 100644 views/partials/head.ejs create mode 100644 views/partials/history.ejs create mode 100644 views/partials/trains.ejs create mode 100644 views/partials/tv.ejs create mode 100644 views/partials/weather.ejs create mode 100644 web-server.js create mode 100644 web-server.min.js create mode 100644 web-server.min.js.map create mode 100644 web-server.old.js create mode 100644 www/css/mui.css create mode 100644 www/css/mui.min.css create mode 100644 www/index.html create mode 100644 www/slack.htm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..56877ed --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +# https://git-scm.com/docs/gitignore +# https://help.github.com/articles/ignoring-files +# Example .gitignore files: https://github.com/github/gitignore +/bower_components/ +/node_modules/ +.idea +/.idea diff --git a/app.js b/app.js new file mode 100644 index 0000000..66a6652 --- /dev/null +++ b/app.js @@ -0,0 +1,38 @@ +/*var app = require('express').createServer(); +app.get('/', function(req, res) { + res.send('Hello from AppFog.com'); +}); +app.listen(process.env.VCAP_APP_PORT || 3000);*/ + + +var express = require('express'), path = require('path'), http = require('http'); +var app = express(); +app.configure(function() { + app.set('port', process.env.VCAP_APP_PORT || 3000); + app.use(express.logger('dev')); + /* 'default', 'short', 'tiny', 'dev' */ + app.use(express.methodOverride()); + app.use(express.bodyParser()); + app.use(function(req, res, next) { + res.header("Access-Control-Allow-Origin", "*"); + res.header("Access-Control-Allow-Headers", "X-Requested-With"); + next(); + }); + app.use(app.router); + app.use(express.static(path.join(__dirname, 'www'))); +app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); +}); + + +/** + * Routing handlers + */ + + +/** + * create the server + */ +http.createServer(app).listen(app.get('port'), function() { + console.log("Express server listening on port " + app.get('port')); +}); + diff --git a/app/Robots.txt b/app/Robots.txt new file mode 100644 index 0000000..4e0bfc5 --- /dev/null +++ b/app/Robots.txt @@ -0,0 +1,2 @@ +User-Agent: * +Disallow: / \ No newline at end of file diff --git a/app/app.js b/app/app.js new file mode 100644 index 0000000..e627ea8 --- /dev/null +++ b/app/app.js @@ -0,0 +1,390 @@ +(function () { + + var lastGBP = 0.0, + lastUSD = 0.0, + _fasttimer, _slowTimer, myBTC = 3.49524333; + var lows = { + gbp: 0, + usd: 0 + }, + highs = { + gbp: 0, + usd: 0 + }; + + var list = [{ + title: '101B ends', + y: 2013, + m: 9, + d: 24, + add: 1001 + }, + { + title: 'Ends', + y: 2016, + m: 4, + d: 4 + }]; + + MicroEvent.mixin(this); + var self = this; + + var addDays = function (myDate, days) { + return new Date(myDate.getTime() + days * 24 * 60 * 60 * 1000); + }; + + var getDays = function (startdate, enddate) { + var r, s, e; + s = startdate.getTime(); + e = enddate.getTime(); + r = (e - s) / (24 * 60 * 60 * 1000); + return r; + }; + + var tick = function () { + var today = new Date(); + var start101 = new Date(); + var end101; + var endContract = new Date(); + var third = new Date(); + start101.setFullYear(2013, 9, 24); + end101 = addDays(start101, 1001); + endContract.setFullYear(2016, 4, 4); + third.setFullYear(2013, 7, 25); + $('#one').text('101B ends: ' + Math.ceil(getDays(today, + end101)) + " days / " + Math.ceil(getDays(today, + end101) / 7) + " weeks"); + $('#two').text('Ends: ' + Math.ceil(getDays(today, + endContract)) + " days / " + Math.ceil(getDays(today, + endContract) / 7) + " weeks"); + $('#three').hide(); + }; + + var get_weather = function () { + navigator.geolocation.getCurrentPosition(show_weather); + }; + + this.bind('displayWeather', function (data) { + $('#weather').html(data.currently.summary + ' ' + data.currently.temperature + '°c ' + data.daily.summary + ''); + }); + + var show_weather = function (position) { + var latitude = position.coords.latitude; + var longitude = position.coords.longitude; + // let's show a map or do something interesting! + $.ajax({ + type: 'GET', + url: 'https://api.forecast.io/forecast/0657dc0d81c037cbc89ca88e383b6bbf/' + latitude.toString() + ',' + longitude.toString() + '?units=uk2', + data: '', + dataType: 'jsonp', + timeout: 10000, + context: $('body'), + contentType: ('application/json'), + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type' + }, + success: function (data) { + self.trigger('displayWeather', data); + }, + error: function (xhr, type) { + console.log("ajax error"); + console.log(xhr); + console.log(type); + } + }); + }; + + var updateBTC = function (g, u) { + var title, total, elm = $('#btc'); + if (lastGBP !== 0) { + + elm.removeClass(); + if (g > lastGBP) { + elm.addClass('up'); + } else if (g < lastGBP) { + elm.addClass('down'); + } + + } else { + lows.gbp = g; + lows.usd = u; + + highs.gbp = g; + highs.usd = u; + } + + lastGBP = g; + lastUSD = u; + + if (g < lows.gbp) lows.gbp = g; + if (u < lows.usd) lows.usd = u; + + if (highs.gbp < g) highs.gbp = g; + if (highs.usd < u) highs.usd = u; + + total = myBTC * g; + + title = "High: $" + parseFloat(highs.usd.toFixed(2)) + " / Low $" + parseFloat(lows.usd.toFixed(2)); + elm.html("$" + parseFloat(u.toFixed(2)) + " / £" + parseFloat(g.toFixed(2)) + " (£" + parseFloat(total.toFixed(2)) + ")"); + elm.prop('title', title); + }; + + var updateFX = function (data) { + var elm = $('#fx'); + elm.html("£1 = $" + parseFloat(data.gpbe.toFixed(2)) + " = " + parseFloat(data.sekex.toFixed(2)) + " SEK"); + }; + + this.bind('updateFX', function (data) { + $('#fx').html("£1 = $" + parseFloat(data.gpbe.toFixed(2)) + " = " + parseFloat(data.sekex.toFixed(2)) + " SEK"); + }); + + + var btcValue = function () { + var url = '/btc'; + + $.ajax({ + type: 'GET', + url: url, + data: '', + dataType: 'json', + + timeout: 10000, + + //contentType: ('application/json'), + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type' + + }, + success: function (data) { + // console.log(data); + var gbp = data.bpi.GBP.rate_float, + usd = data.bpi.USD.rate_float; + + updateBTC(gbp, usd); + }, + error: function (xhr, type) { + console.log("ajax error"); + console.log(xhr); + console.log(type); + } + }); + }; + + this.bind('getBTC', function () { + btcValue(); + }); + + var getFX = function () { + var url = '/fx'; + + $.ajax({ + type: 'GET', + url: url, + data: '', + dataType: 'json', + + timeout: 10000, + + //contentType: ('application/json'), + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type' + + }, + success: function (data) { + var gpbex = (1 / data.rates.GBP); + var sekex = (gpbex * data.rates.SEK); + var fxdata = { + usd: 1, + gbp: data.rates.GBP, + sek: data.rates.SEK, + gpbe: gpbex, + sekex: sekex + }; + self.trigger('updateFX', fxdata); + }, + error: function (xhr, type) { + console.log("ajax error"); + console.log(xhr); + console.log(type); + } + }); + }; + + this.bind('getFX', function () { + getFX(); + }); + + var getNextTrainTime = function (toStation, fromStation) { + var url = '/getnexttraintimes?from=' + fromStation + '&to=' + toStation; + var target = fromStation + toStation; + $.ajax({ + type: 'GET', + url: url, + data: '', + dataType: 'json', + + timeout: 10000, + + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type' + }, + success: function (data) { + updateTrain(target, data); + }, + error: function (xhr, type) { + console.log("ajax error"); + console.log(xhr); + console.log(type); + } + }); + + }; + + var updateTrain = function (n, obj) { + var elm = $('#' + n); + + var output, status; + + output = (obj.eta == "On Time") ? obj.eta : obj.sta; + status = (obj.eta == "On Time") ? 'delayed' : 'ontime'; + + elm.html(output); + elm.prop('class', status); + }; + + var getTrainsCB = function (results) { + var dest$ = $('#trainResults'); + var html = new EJS({url: '/template/trains.ejs'}).render(results); + + dest$.empty(); + dest$.append(html); + dest$.toggle(); + }; + + var getTrains = function (from, to) { + var url = '/gettrains?from=' + from + "&to=" + to; + + $.ajax({ + type: 'GET', + url: url, + data: '', + dataType: 'json', + + timeout: 10000, + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type' + + }, + success: function (data) { + getTrainsCB(data); + }, + error: function (xhr, type) { + console.log("ajax error"); + console.log(xhr); + console.log(type); + } + }); + }; + + var formatPassword = function (data) { + + var dest$ = $('#passwordOut'); + var html = new EJS({url: '/template/password.ejs'}).render(data); + dest$.empty(); + dest$.append(html); + dest$.show(); + }; + + var generatePassword = function (from, to) { + var url = '/generate'; + + $.ajax({ + type: 'GET', + url: url, + data: '', + dataType: 'json', + + timeout: 10000, + + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type' + + }, + success: function (data) { + formatPassword(data); + }, + error: function (xhr, type) { + console.log("ajax error"); + console.log(xhr); + console.log(type); + } + }); + }; + + tick(); + get_weather(); + self.trigger('getBTC'); + self.trigger('getFX'); + getNextTrainTime('dbe', 'glq'); + getNextTrainTime('glq', 'dbe'); + + // start 15 minute timer + + _fastTimer = setInterval(function () { + self.trigger('getBTC'); + getNextTrainTime('dbe', 'glq'); + getNextTrainTime('glq', 'dbe'); + }, (60000)); + + _slowTimer = setInterval(function () { + + self.trigger('getFX'); + get_weather(); + }, (60000 * 15)); + + $('#dbeglq').on('click', function () { + self.trigger('getTrains', 'dbe', 'glq'); + }); + + $('#glqdbe').on('click', function () { + self.trigger('getTrains', 'glq', 'dbe'); + }); + + $('#newPassword').on('click', function () { + generatePassword(); + }); + + this.bind('getTrains', function (start, end) { + getTrains(start, end); + }); + + document.title = 'Slack'; +})(); + +var popitout = function (url) { + var newwindow = window.open(url, 'name', 'height=600,width=570'); + if (window.focus) { + newwindow.focus() + } + return false; +}; + +var popitoutSmall = function (url) { + var newwindow = window.open(url, 'name', 'height=400,width=520'); + if (window.focus) { + newwindow.focus() + } + return false; +}; diff --git a/app/app.min.js b/app/app.min.js new file mode 100644 index 0000000..02b9da6 --- /dev/null +++ b/app/app.min.js @@ -0,0 +1,10 @@ +(function(){var c=0,m=0,g=0,n=0,h=0;MicroEvent.mixin(this);var e=this,k=function(a,b){var d;d=a.getTime();return(b.getTime()-d)/864E5};this.bind("displayWeather",function(a){console.log("Update weather event:");$("#weather").html(a.currently.summary+" "+a.currently.temperature+"°c "+a.daily.summary+"")});var p=function(a){$.ajax({type:"GET",url:"https://api.forecast.io/forecast/0657dc0d81c037cbc89ca88e383b6bbf/"+a.coords.latitude.toString()+","+a.coords.longitude.toString()+"?units=uk2", + data:"",dataType:"jsonp",timeout:1E4,context:$("body"),contentType:"application/json",headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(a){e.trigger("displayWeather",a)},error:function(a,d){console.log("ajax error");console.log(a);console.log(d)}})},t=function(){$.ajax({type:"GET",url:"/btc",data:"",dataType:"json",timeout:1E4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS", + "Access-Control-Allow-Headers":"Content-Type"},success:function(a){var b=a.bpi.GBP.rate_float;a=a.bpi.USD.rate_float;var d,q,f=$("#btc");0!==c?(f.removeClass(),b>c?f.addClass("up"):b