const getFormattedContent = function (prev, details) { prev += `{cyan-fg}{bold}${details.label}{/}${ _.repeat(" ", longestLabel - details.label.length + 1) }{green-fg}${details.data}{/}\n`; return prev; }
_.remove(todoHashes, todo => { if (todo.index + 1000 < index) { return true } if (hash.includes(_.repeat(todo.char, 5))) { validHashes.push(todo.index) return true } return false })
describe('get/set urlTitle', () => { it('should set urlTitle', () => { let urlTitle = 'Test URL title'; this.message.urlTitle = urlTitle; expect(this.message.urlTitle).to.equal(urlTitle); }); it('should throw exception on invalid value', () => { expect(() => { this.message.urlTitle = _.repeat('*', 51); }).to.throw(Error); }); });
function print_script ( script ) { console.log ( chalk.white ( _.repeat ( '-', 88 ) ) ); var script_header = sprintf ( "-- %s :: %s", _.padEnd ( script.alias + '[' + script.index + ']', 40 ), script.route ); console.log ( script_header ); console.log ( _.trim ( script.script ) ); }
before(async function() { accounts = _.times(16, () => ({ secretKey: crypto.randomBytes(32), balance: 100 + _.repeat('0', 18) })); provider = ganache.provider({ accounts: accounts, }); // Suppress max listener warnings. provider.setMaxListeners(4096); provider.engine.setMaxListeners(4096); });
var avpsToString = function(avps, indent) { var indentString = _.repeat(' ', indent); return _.reduce(avps, function(out, avp) { out += indentString + chalk.cyan(avp[0]) + ': '; if (avp[1] instanceof Array) { out += '\n' + avpsToString(avp[1], indent + 2); } else { if (_.isString(avp[1])) { out += '"' + avp[1] + '"'; } else if (Buffer.isBuffer(avp[1])) { out += '0x' + avp[1].toString('hex'); } else { out += avp[1]; } out += '\n'; } return out; }, ''); }
const option = { value: item[lhs], text: _.repeat(' ', level) + item[rhs]
it("should support very large strings", (done) => { _.find(api.paths["/pets"][method].parameters, { name: "PetData" }).schema = { type: "string" }; api.paths["/pets"][method].responses[201].schema = { type: "string" }; api.paths["/pets/{PetName}"].get.responses[200].schema = { type: "string" }; api.paths["/pets"][method].consumes = ["text/plain"]; api.paths["/pets"][method].produces = ["text/plain"]; api.paths["/pets/{PetName}"].get.produces = ["text/plain"]; helper.initTest(api, (supertest) => { let veryLongString = _.repeat("abcdefghijklmnopqrstuvwxyz", 5000); supertest[method]("/api/pets") .set("Content-Type", "text/plain") .send(veryLongString) // The full value should be returned .expect(201, veryLongString) // The resource URL should be truncated to 2000 characters, for compatibility with some browsers .expect("Location", "/api/pets/" + veryLongString.substring(0, 2000)) .end(helper.checkResults(done, (res) => { // Verify that the full value was stored supertest .get(res.headers.location) .expect(200, veryLongString) .end(helper.checkResults(done)); })); }); });
buildTableQueryForDataRow(keyspace, tableInfo, row) { row = _.omitBy(row, (item) => (item === null)); let query = util.format('INSERT INTO "%s"."%s" ("%s") VALUES (?%s)', keyspace, tableInfo.name, _.keys(row).join('","'), _.repeat(',?', _.keys(row).length - 1)); let params = _.values(row); if (tableInfo.isCounterTable) { const primaryKeyFields = _.pick(row, tableInfo.primaryKeys); const otherKeyFields = _.omit(row, tableInfo.primaryKeys); const setQueries = _.map(_.keys(otherKeyFields), (key) => util.format('"%s"="%s" + ?', key, key)); const whereQueries = _.map(_.keys(primaryKeyFields), (key) => util.format('"%s"=?', key)); query = util.format('UPDATE "%s"."%s" SET %s WHERE %s', keyspace, tableInfo.name, setQueries.join(', '), whereQueries.join(' AND ')); params = _.values(otherKeyFields).concat(_.values(primaryKeyFields)); } params = _.map(params, (param) => { if (_.isPlainObject(param)) { if (param.type === 'Buffer') { return Buffer.from(param); } const omittedParams = _.omitBy(param, (item) => (item === null)); Object.keys(omittedParams).forEach((key) => { if (_.isObject(omittedParams[key]) && omittedParams[key].type === 'Buffer') { omittedParams[key] = Buffer.from(omittedParams[key]); } }); return omittedParams; } return param; }); return { query, params }; }
log(data) { let dataToWrite = '' let level = 0 const toStr = (d) => { level++ if (typeof d === 'object') { if (d instanceof Buffer) { dataToWrite += '(buffer)' + d.toString('hex') + '\n' } else { const isArray = d instanceof Array dataToWrite += (isArray ? '[\n' : '{\n') for (let i in d) { const isArray = d instanceof Array dataToWrite += _.repeat(tab, level) + '"' + i + '": ' toStr(d[i]) } dataToWrite += _.repeat(tab, level - 1) + (isArray ? ']' : '}') + '\n' } } else { dataToWrite += '(' + typeof d + ')' + d + '\n' } level-- } toStr(data) fs.appendFileSync(path, dataToWrite) }
_.remove(todoHashes, todo => { if (todo.index + 1000 < index) { return true } if (hash.includes(_.repeat(todo.char, 5))) { validHashes.push(todo.index) fs.writeFileSync('./2016/day14/cache.json', JSON.stringify(validHashes)) return true } return false })
describe('get/set title', () => { it('should set title', () => { let title = 'Test title'; this.message.title = title; expect(this.message.title).to.equal(title); }); it('should throw exception on invalid value', () => { expect(() => { this.message.title = _.repeat('*', 101); }).to.throw(Error); }); });
describe('get/set url', () => { it('should set url', () => { let url = 'Test URL'; this.message.url = url; expect(this.message.url).to.equal(url); }); it('should throw exception on invalid value', () => { expect(() => { this.message.url = _.repeat('*', 501); }).to.throw(Error); }); });
return item === null; }); var query = util.format('INSERT INTO "%s"."%s" ("%s") VALUES (?%s)', keyspace, tableInfo.name, _.keys(row).join('","'), _.repeat(',?', _.keys(row).length - 1)); var params = _.values(row); if (tableInfo.isCounterTable) {