bare's notebooks

  • Fortune cookie - /bare/fortune-cookie
    Last edited 6 years ago
    const fortune = require('fortune-cookie') const cowsay = require('cowsay') const lolcat = require('lolcatjs') const Convert = require('ansi-to-html') const chalk = require('chalk') const convert = new Convert({newline: true}) const chalkForced = new chalk.constructor({level: 2}) const getHTML = (text) => { let html = [] for (let i = 0; i < text.length; i++) { const character = text[i] const color = lolcat.rainbow(lolcat.options.freq, lolcat.options.seed + i / lolcat.options.spread) html.push(convert.toHtml(chalkForced.rgb(color.red, color.green, color.blue)(character))) } return html.join('') } exports.endpoint = (req, res) => { const randomIndex = Math.floor(Math.random() * fortune.length + 1) const randomFortune = fortune[randomIndex] const cowsaid = cowsay.say({text: randomFortune}) lolcat.options.seed = Math.round(Math.random() * 1000) lolcat.options.colors = true res.setHeader('Content-Type', 'text/html') res.end(`<style>body{background: black}</style><pre>${getHTML(cowsaid)}</pre>`) }
  • Google search - /bare/google-search
    Last edited 6 years ago
    const pify = require("pify") const google = require("google") const search = pify(google) const result = await search("es6") for (const link of result.links) { const title = link.title const href = link.href if (href !== null) { console.log(`${title} - ${href}`) } }