This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const DEBUG = true | |
// const DEBUG = process.env.NODE_ENV !== 'production' | |
const LOG_DATE = true | |
const LOG_LOCALE = "en-US" | |
const LOG_DATE_OPTS = { year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit' } | |
const log = function (level, ...args) { | |
if (DEBUG) { | |
let prefix = '' | |
if (typeof level === 'string' && [ 'log', 'warn', 'error' ].includes(level)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'), | |
url = require('url'), | |
fs = require('fs'), | |
path = require('path'), | |
port = process.env.PORT || 3000, | |
docroot = process.argv[2] || process.env.DOCROOT || '.', | |
log = console.log.bind(console) | |
http.createServer(function (req, res) { | |
log(`${ req.method } ${ req.url }`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function assign(source, target) { | |
const fields = Object.getOwnPropertyNames(source.constructor.prototype).filter(f => f !== 'constructor') | |
for (const key of fields) { | |
if (key.substr(0, 1) === '_') | |
continue | |
const info = Object.getOwnPropertyDescriptor(source.constructor.prototype, key) | |
if (info.value) { | |
Object.defineProperty(target, key, { value: source[key].bind(source), configurable: true, writable: true }) | |
} else { | |
const field = { configurable: true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const EventEmitter = require('events').EventEmitter | |
class PrivateStateMachine { | |
constructor(sm, opts = {}) { | |
this.state = opts.state | |
Object.defineProperty(this, 'sm', { value: sm }) | |
Object.defineProperty(this, 'stateKey', { value: opts.stateKey || 'state' }) | |
this._setData(opts.data) | |
this._setStates(opts) | |
Object.defineProperty(this.sm, this.stateKey, { value: this.state, enumerable: true, configurable: true }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def visit_twitter_and_log_in | |
visit 'https://cards-dev.twitter.com/validator'📁 | |
find('input.js-username-field').set(ENV['TWITTER_USERNAME']) | |
find('input.js-password-field').set(ENV['TWITTER_PASSWORD']) | |
click_on('Log in') | |
end | |
def enter_url_and_click_preview(url) | |
find('input.FormControl').set(url) | |
click_on('Preview card') | |
result = has_content?('Page fetched successfully') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/questions/105034/how-to-create-guid-uuid | |
// https://gist.github.com/jed/982883 | |
function uuid(rng) { | |
rng = rng || Math.random.bind(Math) | |
function gen(a) { | |
return a | |
? (a ^ rng() * 16 >> a/4).toString(16) | |
: ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, gen) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Middleware { | |
constructor(obj) { | |
obj = obj || this | |
Object.defineProperty(this, '__obj', { value: obj }) | |
Object.defineProperty(this, 'go', { value: function go(...args) { | |
args[args.length - 1].apply(obj, args.slice(0, -1)) | |
}, writable: true }) | |
} | |
use(fn) { | |
this.go = (stack => (...args) => stack(...args.slice(0, -1), () => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const path = require('path') | |
const cheerio = require('cheerio') | |
const inputFile = process.env.INPUT || process.argv[2] || 'bookmarks.html' | |
const outputFile = process.env.OUTPUT || process.argv[3] || 'bookmarks.json' | |
const inputFilePath = path.resolve(inputFile) | |
const outputFilePath = path.resolve(outputFile) | |
fs.readFile(inputFilePath, { encoding: 'utf8' }, (error, data) => { | |
if (error) |