From c4f85271dd86b7d6fbf8371435e9b98fbbed8b56 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sat, 16 Jul 2016 09:59:26 +0100 Subject: [PATCH 1/9] remove .jshintrc (obsolete) and remove from package.json --- .jshintrc | 29 ----------------------------- .travis.yml | 2 +- package.json | 3 --- 3 files changed, 1 insertion(+), 33 deletions(-) delete mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index e33784d..0000000 --- a/.jshintrc +++ /dev/null @@ -1,29 +0,0 @@ -{ - "asi" : true, - "laxbreak" : true, - "bitwise" : true, - "boss" : false, - "curly" : true, - "eqeqeq" : true, - "eqnull" : false, - "evil" : false, - "expr" : false, - "forin" : false, - "immed" : true, - "indent" : 2, - "latedef" : true, - "loopfunc" : false, - "noarg" : true, - "node" : true, - "regexp" : true, - "regexdash" : false, - "strict" : false, - "scripturl" : true, - "shadow" : false, - "supernew" : false, - "sub" : true, - "undef" : true, - "white" : true, - "browser" : true, - "globals": { "$": true, "io": true, "Cookies": true } -} diff --git a/.travis.yml b/.travis.yml index 06063d8..f6be9cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: - - 0.12 + - 4 services: - redis-server env: diff --git a/package.json b/package.json index 3c9e574..a8763c2 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "quick": "./node_modules/tape/bin/tape ./test/*.js", "test": "./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape ./test/*.js", "coverage": "./node_modules/.bin/istanbul cover ./node_modules/tape/bin/tape ./test/*.js && ./node_modules/.bin/istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100", - "jshint": "./node_modules/jshint/bin/jshint -c .jshintrc --exclude-path .gitignore .", "start": "node server.js" }, "repository": { @@ -35,12 +34,10 @@ "devDependencies": { "decache": "^3.0.3", "istanbul": "^0.4.2", - "jshint": "^2.9.1", "pre-commit": "^1.1.2", "tape": "^4.4.0" }, "pre-commit": [ - "jshint", "coverage" ] } From 32abb3893cdd455a8797d03de6d9e2e4349c4589 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sat, 16 Jul 2016 10:11:00 +0100 Subject: [PATCH 2/9] update dependencies to latest --- README.md | 12 ++++++------ package.json | 25 +++++++++++++------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 4b3342e..a09b5b9 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,12 @@ What if there was a *simple+easy* way to see how many people have viewed your GitHub Repository? -[![Build Status](https://travis-ci.org/nelsonic/hits.svg)](https://travis-ci.org/nelsonic/hits) +[![Build Status](https://travis-ci.org/dwyl/hits.svg)](https://travis-ci.org/dwyl/hits) [![HitCount](https://hitt.herokuapp.com/nelsonic/hits.svg)](https://github.com/nelsonic/hits) -[![Code Climate](https://codeclimate.com/github/nelsonic/hits/badges/gpa.svg)](https://codeclimate.com/github/nelsonic/hits) -[![codecov.io](http://codecov.io/github/nelsonic/hits/coverage.svg?branch=master)](http://codecov.io/github/nelsonic/hits?branch=master) -[![Dependency Status](https://david-dm.org/nelsonic/hits.svg)](https://david-dm.org/nelsonic/hits) -[![devDependency Status](https://david-dm.org/nelsonic/hits/dev-status.svg)](https://david-dm.org/nelsonic/hits#info=devDependencies) +[![Code Climate](https://codeclimate.com/github/dwyl/hits/badges/gpa.svg)](https://codeclimate.com/github/dwyl/hits) +[![codecov.io](http://codecov.io/github/dwyl/hits/coverage.svg?branch=master)](http://codecov.io/github/dwyl/hits?branch=master) +[![Dependency Status](https://david-dm.org/dwyl/hits.svg)](https://david-dm.org/dwyl/hits) +[![devDependency Status](https://david-dm.org/dwyl/hits/dev-status.svg)](https://david-dm.org/dwyl/hits#info=devDependencies) ## Why? @@ -23,7 +23,7 @@ to know where we need to be investing our time. A simple way to add (*very basic*) analytics to your GitHub repos. -There are already *many* "Badges" available which people put in their repos: https://github.com/dwyl/repo-badges +There are already *many* "Badges" available which people put in their repos: https://github.com/dwyl/repo-badges But we haven't seen one that gives a "***hit counter***" of the number of times a page has been viewed ... diff --git a/package.json b/package.json index a8763c2..68edf3d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hits", - "version": "2.0.2", + "version": "2.0.3", "description": "all the hits", "main": "lib/hits.js", "directories": { @@ -14,28 +14,29 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/nelsonic/hits.git" + "url": "git+https://github.com/dwyl/hits.git" }, "keywords": [ - "hits" + "hits", + "hit counter" ], "author": "this guy", "license": "GPL-2.0", "bugs": { - "url": "https://github.com/nelsonic/hits/issues" + "url": "https://github.com/dwyl/hits/issues" }, - "homepage": "https://github.com/nelsonic/hits#readme", + "homepage": "https://github.com/dwyl/hits#readme", "dependencies": { - "env2": "^2.0.4", - "redis-connection": "^4.0.1", + "env2": "^2.1.0", + "redis-connection": "^5.0.0", "uniki": "^1.0.3", - "wreck": "^7.0.0" + "wreck": "^8.0.0" }, "devDependencies": { - "decache": "^3.0.3", - "istanbul": "^0.4.2", - "pre-commit": "^1.1.2", - "tape": "^4.4.0" + "decache": "^4.0.0", + "istanbul": "^0.4.4", + "pre-commit": "^1.1.3", + "tape": "^4.6.0" }, "pre-commit": [ "coverage" From 43b665cb7d0f2eab647976e376aaafc8d2066df5 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sat, 16 Jul 2016 10:13:50 +0100 Subject: [PATCH 3/9] remove Procfile as Heroku "understands" npm start :wink: --- Procfile | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Procfile diff --git a/Procfile b/Procfile deleted file mode 100644 index 4309650..0000000 --- a/Procfile +++ /dev/null @@ -1 +0,0 @@ -web node server.js From 570e4dc6b4c72a8fb38165aef8b1168bcbf3f142 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sat, 16 Jul 2016 11:20:31 +0100 Subject: [PATCH 4/9] DRY headers to and use Object.assign to clone --- README.md | 21 +++++++++- lib/1x1px.png | Bin 0 -> 1088 bytes lib/hits.js | 2 +- image_50x50.png => lib/image_50x50.png | Bin package.json | 7 ++-- server.js | 53 ++++++++++--------------- 6 files changed, 46 insertions(+), 37 deletions(-) create mode 100644 lib/1x1px.png rename image_50x50.png => lib/image_50x50.png (100%) diff --git a/README.md b/README.md index a09b5b9..07cbdf7 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,25 @@ We then have a user-agent hash where we can lookup the by id: Given that shields.io has a badge creation service, and it has acceptable latency, we are proxying the their service. +## Run it! + +Download (clone) the code to your local machine: +```sh +git clone https://github.com/dwyl/hits.git && cd hits +``` +> Note: you will need to have Redis running on your localhost, +> if you are new to Redis see: https://github.com/dwyl/learn-redis + +Install dependencies: +```sh +npm install +``` +Run locally: +```sh +npm run dev +``` +Visit: http://localhost:8000/any/url/count.svg + ## Research @@ -79,7 +98,7 @@ need to perform a lookup on each hit which requires network IO ... (*expensive*!) What if there was a way of *deriving* a `String` representation of the the user-agent string ... oh, that's right, here's one I made earlier... -https://github.com/ideaq/aguid +https://github.com/dwyl/aguid ### Log Formats diff --git a/lib/1x1px.png b/lib/1x1px.png new file mode 100644 index 0000000000000000000000000000000000000000..e24736418f7f691018c444a25eee1c7f361f7499 GIT binary patch literal 1088 zcmV-G1i$-4Tx062|}Ro!pfR1`mnZ(O7nKcKOW4i$^9Ra0BJ8yc;~21%2p=|UR0&DbiW z$#rfTQ`a`O(`{9s_5yDV_yd5l2Of}kLK+Oj_Ok5(v`JGz71bo9J#^YYXp{DWs&KBa zQ@dTpxRI}aIp=pi@6k0t$5)!;m`NF6-tt{FpOKHBn3g+MAqmexC-gw4rh87hTrL7G z#)U`L!(So6-Zux@>;H3gR;i~0B%VTSS3P|m@o9jRsXML@Al^p#@G0Lx-0?i(9WEw_ zSYddU<1E8793KxjQ|c&UmW!mTC>k>?{om1c9S zUx<6_jj_!T&^M{wWM#>IBbOSf*xP<^F{$j$aOQ5Y{cT zROCL1M7^NKKL z&(yA}mSw#iM0^;IB{ZO5!wl{^Sg-*ysE~&Yz8!E;Qv(A`lu*=Clo*MpVGd>OdF6n^ zam1Jntk;<}MrqIC5$=Q>n{*R}?8oOIDUw5En2dl--Xw34!z7E+5pr-OgyQ-soSab)C%saskMla`aQLVzg0+MZf20tJU&K{hZoBrUc+U4e9&3o zw|KmGEe4#xz17wBu{f`SS_4i66?j31EjY7n{zGfhONK~c+td!TS#B}JoR}5UAd7p& z5phTyXSkK0xCeD3xaYP^o&J~#Xp9xFb0C;HHml5fA<%h1eR|qw7wxF+oNL9T1Aits?sKNIwvGaN)^WO$I^cUV)HzL_| z1K?{9p!>B*)`xfEv!4N6IG{J&h49W#Bz^(#YWw%`e_a{8n{G9m5AeR~_yl0%<7V@p z>'+url); + if (url.match(/svg/)) { hits.add(r, function(err, count) { console.log(r.url, ' >> ', count); - var newurl = "https://img.shields.io/badge/hits-" + count +"-brightgreen.svg" - wreck.get(newurl, function (error, response, html) { - // expiry headers see: http://stackoverflow.com/a/2068407/1148249 - var head = { - "Cache-Control": "no-cache, no-store, must-revalidate", // HTTP 1.1 - "Pragma": "no-cache", // HTTP 1.0 - "Expires": "0", // Proxies - "Location": newurl, - "Content-Type":"image/svg+xml" - } + var newurl = 'https://img.shields.io/badge/hits-' + count +'-brightgreen.svg'; + wreck.get(newurl, function (error, response, raw) { + var head = Object.assign(HEADERS, { "Location": newurl }); res.writeHead(200, head); - res.end(html); + res.end(raw); }); - }) - + }); } else if (url.match(/png/)) { hits.add(r, function(err, count) { console.log(r.url, ' >> ', count) - // var newurl = "https://img.shields.io/badge/hits-" + count +"-brightgreen.png" - // wreck.get(newurl, function (error, response, html) { - // expiry headers see: http://stackoverflow.com/a/2068407/1148249 - // console.og() - var head = { - "Cache-Control": "no-cache, no-store, must-revalidate", // HTTP 1.1 - "Pragma": "no-cache", // HTTP 1.0 - "Expires": "0", // Proxies - "Content-Type":"image/png" - } - res.writeHead(200, head); - res.end(png); - // }); + var head = Object.assign(HEADERS, { "Content-Type": "image/png" }); + res.writeHead(200, head); + res.end(png); }) - } else if(url === '/favicon.ico') { - var fav = 'https://www.google.com/images/google_favicon_128.png' + var fav = 'https://www.google.com/images/google_favicon_128.png'; res.writeHead(301, {"Location": fav }); res.end(); } @@ -58,7 +47,7 @@ http.createServer(function handler(req, res) { console.log(" - - - - - - - - - - record:", r); res.writeHead(200, {"Content-Type": "text/plain"}); res.end(JSON.stringify(r, null, " ")); // see next line - } // For pretty JSON in Browser see: http://stackoverflow.com/a/5523967/1148249 + } // pretty JSON in Browser see: http://stackoverflow.com/a/5523967/1148249 }).listen(port); console.log('Visit http://localhost:' + port); From 4a5a47804c9f922b1a9fb991bb87cd21b61573e1 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sat, 16 Jul 2016 11:25:09 +0100 Subject: [PATCH 5/9] remove 50x50px image as not longer used > using 1x1px instead --- lib/image_50x50.png | Bin 1170 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 lib/image_50x50.png diff --git a/lib/image_50x50.png b/lib/image_50x50.png deleted file mode 100644 index 95e6148fa510aa5f484636e0ed0a431a5214090d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1170 zcmV;D1a13?P)4Tx062|}Ro!pfR1`mnZ(O7nKcKOW4i$^9Ra0BJ8yc;~21%2p=|UR0&DbiW z$#rfTQ`a`O(`{9s_5yDV_yd5l2Of}kLK+Oj_Ok5(v`JGz71bo9J#^YYXp{DWs&KBa zQ@dTpxRI}aIp=pi@6k0t$5)!;m`NF6-tt{FpOKHBn3g+MAqmexC-gw4rh87hTrL7G z#)U`L!(So6-Zux@>;H3gR;i~0B%VTSS3P|m@o9jRsXML@Al^p#@G0Lx-0?i(9WEw_ zSYddU<1E8793KxjQ|c&UmW!mTC>k>?{om1c9S zUx<6_jj_!T&^M{wWM#>IBbOSf*xP<^F{$j$aOQ5Y{cT zROCL1M7^NKKL z&(yA}mSw#iM0^;IB{ZO5!wl{^Sg-*ysE~&Yz8!E;Qv(A`lu*=Clo*MpVGd>OdF6n^ zam1Jntk;<}MrqIC5$=Q>n{*R}?8oOIDUw5En2dl--Xw34!z7E+5pr-OgyQ-soSab)C%saskMla`aQLVzg0+MZf20tJU&K{hZoBrUc+U4e9&3o zw|KmGEe4#xz17wBu{f`SS_4i66?j31EjY7n{zGfhONK~c+td!TS#B}JoR}5UAd7p& z5phTyXSkK0xCeD3xaYP^o&J~#Xp9xFb0C;HHml5fA<%h1eR|qw7wxF+oNL9T1Aits?sKNIwvGaN)^WO$I^cUV)HzL_| z1K?{9p!>B*)`xfEv!4N6IG{J&h49W#Bz^(#YWw%`e_a{8n{G9m5AeR~_yl0%<7V@p zogQ7qxr>&Rd!M2mk;807*qoM6N<$f*6H4@c;k- From 2c3e6c563f02f97fe7be0fb4316273e2fe10538c Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sat, 16 Jul 2016 11:46:06 +0100 Subject: [PATCH 6/9] borrow index.html from https://github.com/dwyl/hapi-socketio-redis-chat-example/blob/master/index.html --- lib/index.html | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 lib/index.html diff --git a/lib/index.html b/lib/index.html new file mode 100644 index 0000000..02cfc07 --- /dev/null +++ b/lib/index.html @@ -0,0 +1,26 @@ + + + + Chat + + + + +

You joined the chat!

+ +
    + +
    + + +
    + + + + + + + From 8e3620a72fc26d723035bd8c4e037f47cbedde05 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sat, 16 Jul 2016 12:06:37 +0100 Subject: [PATCH 7/9] add client.js and style.css + corresponding "routes" in server.js --- lib/client.js | 1 + lib/index.html | 10 +++------- lib/style.css | 0 server.js | 35 +++++++++++++++++++++++++---------- test/hits.test.js | 8 ++++---- 5 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 lib/client.js create mode 100644 lib/style.css diff --git a/lib/client.js b/lib/client.js new file mode 100644 index 0000000..f306140 --- /dev/null +++ b/lib/client.js @@ -0,0 +1 @@ +console.log('Hai!'); diff --git a/lib/index.html b/lib/index.html index 02cfc07..34594c6 100644 --- a/lib/index.html +++ b/lib/index.html @@ -2,20 +2,16 @@ Chat + + -

    You joined the chat!

    +

    Stats!

    -
      - -
      - - -
      diff --git a/server.js b/server.js index eed8817..95f22cd 100644 --- a/server.js +++ b/server.js @@ -36,7 +36,7 @@ var app = http.createServer(function handler(req, res) { }) } else if(url === '/favicon.ico') { - var favicon = 'https://www.google.com/images/google_favicon_128.png'; + var favicon = 'http://i.imgur.com/zBEQq4w.png'; // dwyl favicon res.writeHead(301, { "Location": favicon }); res.end(); } @@ -68,7 +68,9 @@ var app = http.createServer(function handler(req, res) { var io = require('socket.io')(app); io.on('connection', function (socket) { - // console.log('Totes Works!', socket); + console.log(' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '); + console.log(socket.client.conn); + console.log(' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '); socket.emit('news', { msg: 'welcome to stats-ville!' }); socket.on('my other event', function (data) { console.log(data);