return new Promise(function(resolve, reject){ let salt = randomstring.generate(10); let token = _.sha1([password, salt].join(':')); let openid = _.sha1([mail, new Date().getTime()].join(':')); let now = new Date(); let sqls = { user_mail: mail, user_salt: salt, user_token: token, user_nick: mail.split('@')[0], user_expire: dateFormat(now), user_openid: openid, user_status: 1, user_timestramp: now.getTime(), user_sex: 0 } const QueryString = mysql.define(SQLBricks.insert('cloud_user', sqls).toString()).execute(); QueryString.on('end', function(result){ if ( result.affectedRows === 1 ){ resolve(result.insertId); }else{ reject(_.code.token(10001)); } }) QueryString.on('error', function(){ console.log(err); reject(_.code.token(10001)); }) })
module.exports = () => { const deploy = path.resolve(process.cwd(), 'deploy') const git = path.resolve(deploy, '.git') const _template = path.resolve(process.cwd(), '_template') const configJSON = path.resolve(process.cwd(), 'config.json') const simpleGit = require('simple-git')(deploy) const config = fs.readJsonSync(configJSON) const template = config.template if (!fs.existsSync(deploy)) { throw Error('Please run build first!') } if (Array.isArray(template) && template.length) { template.forEach(item => { const f = path.resolve(_template, item) const t = path.resolve(deploy, item) fs.copySync(f, t) }) } else { fs.copySync(_template, deploy) } if (!fs.existsSync(git)) { simpleGit.init() .addRemote('origin', config.git.repo) .checkoutBranch(config.git.branch) } simpleGit .add('./*') .commit(format('yyyy-MM-dd hh:mm:ss.SSS', new Date)) .push('origin', config.git.branch) }
.on('end', function(){ if(iflog) { var logtimestamp = date_format("[yyyy-MM-dd hh:mm:ss]", new Date()); //console.log('[my_pool_sql]' + logtimestamp + ' Query: ', result._parent._query); console.log('[my_pool_sql]' + logtimestamp + ' Query Effects: ', result.info); } pending.fn(null, {query: result, rows: rows, info: result.info}); });
_.each(inviteList, function (invite, token) { if (invite.time < threshold) { inviteId = invite.id; toDelete.push(inviteId); logger.info('Invite', inviteId, 'is marked for deletion (scheduled for ' + format('dd/MM/yyyy hh:mm', new Date(invite.time * 1000)) + ')'); delete(inviteList[token]); opeka.groups.getGroup('councellors').remote('inviteCancelled', inviteId); } });
.on('error', function(err){ // Send the error to the callback function. connection.end(); if(iflog) { var logtimestamp = date_format("[yyyy-MM-dd hh:mm:ss]", new Date()); console.log('[my_pool_sql]' + logtimestamp + ' Query error: ', err); } pending.fn(err); })
Pool.prototype._create = function() { // Check if a connection may be established. if (this._currentNumberOfConnections + this._currentNumberOfConnectionsEstablishing < this.max) { // Create a connection. var connection = new mariasql(); if(iflog) { var logtimestamp = date_format("[yyyy-MM-dd hh:mm:ss]", new Date()); console.log('[my_pool_sql]' + logtimestamp + ' Create new mariasql connection'); } connection.connect(this.options); // Retrieve the pool instance. var pool = this; // Increment the current number of connections being established. this._currentNumberOfConnectionsEstablishing++; // Connect to the database. connection.on('ready', function() { // Decrement the current number of connections being established. pool._currentNumberOfConnectionsEstablishing--; // Increment the current number of connections. pool._currentNumberOfConnections++; // Save the terminate function in case we want to dispose. connection._end = connection.end; // Change the behaviour of the termination of the connection. connection.end = function() { // Add the connection to the established _connections. pool._connections.push(this); // Update the connection pool and _pending queries. pool._update(); }; // Rebound a managed connection. connection.end(); }) .on('error', function(err){ // Check if the connection has been lost. if (err.fatal && err.code !== 'PROTOCOL_CONNECTION_LOST') { // Decrement the current number of _connections. pool._currentNumberOfConnections--; } // Update the connection pool. pool._update(); }) .on('end', function(){ if(iflog) { var logtimestamp = date_format("[yyyy-MM-dd hh:mm:ss]", new Date()); console.log('[my_pool_sql]' + logtimestamp + ' Done with all results, deposed this connection...'); } }); // Return true. return true; } // Otherwise return false. else return false; };
module.exports = function (req, res, next) { var info = { domain: req.hostname, path: req.path, account: (res.locals.ssoInfo && res.locals.ssoInfo.account) || null, loginTime: (res.locals.ssoInfo && timeFormat('yyyy-mm-dd hh:mm:ss.SSS', new Date(parseInt(res.locals.ssoInfo.loginTime))) ) || null, ssoToken: req.cookies.SSOID }; res.locals.reqInfo = info; return next(); }
FatLogger.prototype.readFile = function readFile(callback) { var self = this; var fileUri = 'rt-foobar.log-' + dateFormat('yyyyMMdd'); var uri = path.join(self.opts.folder, fileUri); fs.readFile(uri, function onFile(err, buf) { if (err) { return callback(err); } callback(null, String(buf)); }); };
function onlog(err) { assert.ifError(err); var fileUri = path.join(loc, 'rt-foobar.log-' + dateFormat('yyyyMMdd')); fs.readFile(fileUri, function (err, buf) { assert.ifError(err); buf = String(buf); assert.ok(buf.indexOf('hello') !== -1); assert.ok(buf.indexOf('foo=bar') !== -1); rimraf(loc, assert.end); }); }
rd.eachFileFilterSync(_posts, /\.md$/, (f, s) => { const source = fs.readFileSync(f).toString() const post = md.parseSourceContent(source) const title = post['title'] const date = post['date'] || format('yyyy-MM-dd', new Date) const tag = post['tag'] const json = { title: title, date: date, tag: tag, url: './posts/' + date + '/' + title + '.html' } let file = path.resolve(posts, date, title + '.html') if (!title) { fs.removeSync(posts) throw Error(f + ' title is empty!') } if (f.indexOf('about.md') > 0) { fs.outputFileSync(about, md.markdownToHTML(post.source), 'utf8') file = about } else { postsJSON[date] ? postsJSON[date].push(json) : postsJSON[date] = [json] tagsJSON[tag] ? tagsJSON[tag][date] ? tagsJSON[tag][date].push(json) : tagsJSON[tag][date] = [json] : tagsJSON[tag] = {} datesOftags[tag] ? datesOftags[tag][date] = 1 : datesOftags[tag] = {} if (_.isEmpty(tagsJSON[tag]) && _.isObject(tagsJSON[tag])) { tagsJSON[tag][date] = [json] } if (_.isEmpty(datesOftags[tag]) && _.isObject(datesOftags[tag])) { datesOftags[tag][date] = 1 } dates[date] = 1; fs.outputFileSync(file, md.markdownToHTML(post.source), 'utf8') } console.log('Create'.green, file) })
/** * Plot graph data * * @param {Arr} prices * * @return {Void} */ plot(prices) { const now = format("MM/dd/yy-hh:mm:ss", new Date()) Object.assign(this.graphs.outbound, { x: [...this.graphs.outbound.x, now], y: [...this.graphs.outbound.y, prices.outbound] }) Object.assign(this.graphs.return, { x: [...this.graphs.return.x, now], y: [...this.graphs.return.y, prices.return] }) this.widgets.graph.setData([ this.graphs.outbound, this.graphs.return ]) }
}, function (err) { assert.ifError(err); var fileUri = 'rt-foobar.log-' + dateFormat('yyyyMMdd'); fs.readdir(loc, function (err, files) { assert.ifError(err); assert.deepEqual(files, [fileUri]); fs.readFile(path.join(loc, fileUri), function (err, buf) { assert.ifError(err); buf = String(buf); assert.ok(buf.indexOf('some message') !== -1); assert.ok(buf.indexOf('some=object') !== -1); rimraf(loc, assert.end); }); }); });
import dateFormat from 'date-format'; import path from 'path'; import express from 'express'; import morgan from 'morgan'; import minimatch from 'minimatch'; import http from 'http'; import httpProxy from 'http-proxy'; import tinyLiveReload from 'tiny-lr'; import connectLiveReload from 'connect-livereload'; import eventStream from 'event-stream'; import find from 'array.prototype.find'; import yargs from 'yargs'; const argv = require('yargs').argv; const timestamp = dateFormat(argv['timestamp-format'] || process.env['GULP_TIMESTAMP_FORMAT'] || 'yyyyMMddhhmmss'); const liveReload = tinyLiveReload(); const project = require('./package.json'); function proxy(logPrefix, options, proxyPort) { let httpServer = http.createServer((req, res) => { let option = options.find((option) => { return (minimatch(req.url, option.pattern)) }); option.proxy.web(req, res); }); httpServer.on('error', (err, req, res) => { res.status(503).end();
read: function(val) { let format = "yyyy/MM/dd hh:mm"; return dateFormat(format, new Date(val)); },
function log(message) { var now = new Date(); console.log(dateFormat(now, "dd-mm-yyyy h:MM:ss TT") + " : "+ message); }
render = () => { //TODO render soundTableRow.message as tool tip const { index, action, gyaonAppActionBind, object } = this.props; const backgroundColor = object.highlight ? grey200 : 'white'; /* TODO フェードしたい */ const buttonTdStyle = { width: '35px' }; /* tdのstyle */ const iconStyle = { width: '15px', height: '15px' }; /* SVGアイコンの大きさ */ const iconButtonStyle = { width: '35px', height: '35px', padding: '6px' }; /* アイコンを入れるボタン */ const src = ENDPOINT + '/sound/' + object.name; const date = new Date(object.lastmodified); this.prevComment = object.comment; return ( //ReactAudioPlayerからcontrolsだけ消した <tr onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave} style={{ backgroundColor: backgroundColor, transition: 'background-color .25s ease', cursor: 'pointer', fontSize: '20px' }}> <audio className="react-audio-player" src={src} preload="metadata" ref={(ref) => this.audioEl = ref} onCanPlay={this.onCanPlay}> </audio> <td style={{ width: '160px', padding: '5px' }} className={"date"}> {asString('yyyy-MM-dd hh:mm', date)} </td> <td style={{ padding: '5px 20px 5px 20px' }} className={"comment"}> <TextField name={"comment-text-field"} fullWidth={true} defaultValue={object.comment} onChange={(text) => this.comment = text.target.value} onFocus={gyaonAppActionBind.startEditComment} onBlur={this.finishEditComment} /> </td> <td className={"duration"} style={{ width: '50px', padding: '5px 10px 5px 5px' }}> {object.duration} </td> <td style={buttonTdStyle}> <IconButton className={"delete-button"} iconStyle={iconStyle} style={iconButtonStyle} onClick={this.deleteItem} tooltip="delete"> <Clear /> </IconButton> </td> <CopyToClipboard text={src}> <td style={buttonTdStyle} className={"copy-button"}> <IconButton className={"copy-button"} iconStyle={iconStyle} style={iconButtonStyle} onClick={this.copyUrl} tooltip="copy URL"> <Copy /> </IconButton> </td> </CopyToClipboard> </tr> ) }
app.listen(PORT, () => { console.log(`server listening on ${PORT}`); console.log('RIGHT NOW: ', format(new Date())); console.log('TIME TOMMOROW:', format('MM', new Date()) + (parseInt(format('dd', new Date()), 10) + 1)); });
const targetUser = userArr.filter(each => each.dob !== format('MM', new Date()) + (parseInt(format('dd', new Date()), 10) + 1)).map(each => each.phone);
const bDayUser = userArr.filter(each => each.dob === format('MM', new Date()) + (parseInt(format('dd', new Date()), 10) + 1));
formatDate: function (date, tz, format) { return formatDate(format, date); }
.on('end', function() { if(iflog) { var logtimestamp = date_format("[yyyy-MM-dd hh:mm:ss]", new Date()); console.log('[my_pool_sql]' + logtimestamp + ' Query done'); } });
.on('end', function(){ if(iflog) { var logtimestamp = date_format("[yyyy-MM-dd hh:mm:ss]", new Date()); console.log('[my_pool_sql]' + logtimestamp + ' Done with all results, deposed this connection...'); } });
/** * Log data * * @param {Arr} messages * * @return {Void} */ log(messages) { const now = format("MM/dd/yy-hh:mm:ss", new Date()) messages.forEach((m) => this.widgets.log.log(`${now}: ${m}`)) }