3 ms·
Took me around 15 minutes in total. Can I be CTO at your silicon valley company now with 500k salary? const express = require('express') const app = ex
by romanovcode 9y ago
Took me around 15 minutes in total. Can I be CTO at your silicon valley company now with 500k salary?
const express = require('express')
const app = express()
const puppeteer = require('puppeteer')
const uuidv1 = require('uuid/v1')
const fs = require('fs')
const validUrl = require('valid-url')
app.get('/', function (req, res) {
(async () => {
const url = req.query.url;
if (!url) {
return res.send({error: 'Need to specify url param e.g. ?url=https://google.com/'});
}
if (!validUrl.isUri(url)) { // Also protects against file://...
return res.send({error: 'url not valid'})
}
const id = uuidv1();
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({ width: 1920, height: 1080})
await page.goto(url)
const buffer = await page.screenshot({path: id + '.png'})
const fullPath = __dirname + '/' + id + '.png';
res.sendFile(fullPath, function () {
fs.unlink(fullPath)
})
await browser.close()
})();
})
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})
- TomNomNom 9y agoDon't run this on EC2; you'll probably get your metadata stolen. Also: if (!validUrl.isUri(url)) { // Also protects against file://... It does? ▶ cat valid.js var validUrl = require('valid-url'); if (validUrl.isUri("file:///etc/passwd")){ console.log('Looks like a URI'); } ▶ node valid.js Looks like a URI Perhaps the problem requires a little more than 15 minutes to do well :)
- romanovcode 9y agoYeah, like 15 minutes more. Ergo my original statement - 30 minutes. As a bonus I would also stream binary data directly to client without creating an image file.
- davidpelayo 9y agook. congrats! While I would spend a few hours you would spend 30 minutes. However, this guy just published something to start making money, and it's working for him, no matter who is able to create what in how much time.
- dvt 9y agoApart from the smugness, I hope you realize that technology != success. It doesn't matter that I can replicate Tinder with a few weeks of coding. In fact, the two are often inversely correlated because engineers can be so worried about what technology, what stack, what language, instead of worrying about the real deal: getting the users.
- romanovcode 9y agoI know that you can build twitter and tinder and getting the users is hard. But my point was very different -- People will probably need this for some internal tooling (devops) and it is simple enough to just build it on your own without paying someone or relying on 3rd party. IMO there should be a line of what to outsource and what to build yourself. In my mind simple things like this go into second category.
- dvt 9y agoI see your point but I'm not fully convinced. Companies outsource simple stuff all the time. To wit, I think that line you drew might vary from company to company.
- imron 9y ago> Took me around 15 minutes in total. So assuming a rate of $80/hr (which is on the low-side), it cost you $20 in time to do what you could have for $7. A CTO worth 500k/year would probably realise that paying $7 is more cost effective.