Skip to content

Instantly share code, notes, and snippets.

@ryanlanciaux
Created July 13, 2020 04:03
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ryanlanciaux/3e29e75bd32efee9681c2ab85b99cc6f to your computer and use it in GitHub Desktop.
Save ryanlanciaux/3e29e75bd32efee9681c2ab85b99cc6f to your computer and use it in GitHub Desktop.
// This app initially started from Flavio Copes analytics example
// but diverged quite a bit to generate images as well as track views
// https://flaviocopes.com/count-visits-static-site/
const express = require('express')
const app = express()
// no db - so global var to keep track of count
let counter = 0
function getCountImage(count) {
// This is not the greatest way for generating an SVG but it'll do for now
const countArray = count.toString().padStart(6, '0').split('');
const parts = countArray.reduce((acc, next, index) => `
${acc}
<rect id="Rectangle" fill="#000000" x="${index * 32}" y="0.5" width="29" height="29"></rect>
<text id="0" font-family="Courier" font-size="24" font-weight="normal" fill="#00FF13">
<tspan x="${index * 32 + 7}" y="22">${next}</tspan>
</text>
`, '');
return `<?xml version="1.0" encoding="UTF-8"?>
<svg width="189px" height="30px" viewBox="0 0 189 30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Count</title>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
${parts}
</g>
</svg>
`
}
// get the image
app.get('/count.svg', (req, res) => {
counter++;
// This helps with GitHub's image cache
// see more: https://rushter.com/counter.svg
res.set({
'content-type': 'image/svg+xml',
'cache-control': 'max-age=0, no-cache, no-store, must-revalidate'
})
// Send the generated SVG as the result
res.send(getCountImage(counter));
})
const listener = app.listen(process.env.PORT, () => {
console.log('Your app is listening on port ' + listener.address().port)
})
@refs
Copy link

refs commented Jul 16, 2020

for I in {1..800}
do
curl 'https://camo.githubusercontent.com/f428d5a0306d32cebc1396e58667b6cbc34d7e16/68747470733a2f2f7279616e2d6c616e63696175782d636f756e7465722e676c697463682e6d652f636f756e742e737667' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0' -H 'Accept: image/webp,*/*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: https://github.com/' -H 'Connection: keep-alive' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache'
done

essentially substitute f428d5a0306d32cebc1396e58667b6cbc34d7e16/68747470733a2f2f7279616e2d6c616e63696175782d636f756e7465722e676c697463682e6d652f636f756e742e737667 with yours and funs ensured :D, someone else can also boost your visits since there is no authentication :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment