Skip to content

Instantly share code, notes, and snippets.

@p1ho
p1ho / generate-report.js
Created June 17, 2019 05:13
Generates HTML report from site-validator-cli exported json
const fs = require('fs')
const htmlCreator = require('html-creator')
let filename = 'testdata.json' // insert name of exported json here
let raw = fs.readFileSync(filename)
let rawJson = JSON.parse(raw)
let utils = {
pass: '<span style="color: green">&#10004;</span>',
fail: '<span style="color: red;">&#10060;</span>'
@p1ho
p1ho / sendAttachment.js
Last active May 28, 2019 02:17
Sending Attachment through fb-messenger-cli
// Send an attachment in a thread
// recipient: Url name of recipient, also called vanity (eg: alexandre.rose)
// recipientId : Facebook numeric id of recipient. Can be a person or a thread
// path : path of the file
// callback(err) does not get any data
sendAttachment(recipient, recipientId, path, callback) {
const recipientUrl = `${this.baseUrl }/t/${ recipient}`; // Your recipient;
const utcTimestamp = new Date().getTime();
const localTime = new Date().toLocaleTimeString().replace(/\s+/g, '').toLowerCase();
const messageId = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
@p1ho
p1ho / Cache.js
Created February 25, 2019 07:20
Cache that implements expiration on top of flat-cache
'use strict'
const flatCache = require('flat-cache')
module.exports = class Cache {
constructor (name, path, cacheTime = 0) {
this.name = name
this.path = path
this.cache = flatCache.load(name, path)
this.expire = cacheTime === 0 ? false : cacheTime * 1000 * 60