npm install bluebird ws
node server.js
node client.js
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
<form class="well span8"> | |
<div class="row"> | |
<div class="span3"> | |
<label>First Name</label> | |
<input type="text" class="span3" placeholder="Your First Name"> | |
<label>Last Name</label> | |
<input type="text" class="span3" placeholder="Your Last Name"> | |
<label>Email Address</label> | |
<div class="input-prepend"> | |
<span class="add-on"><i class="icon-envelope"></i></span><input type="text" id="inputIcon" class="span2" style="width:233px" placeholder="Your email address"> |
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
module.exports = function(col, limit=5000) { | |
this.bulk = col.initializeUnorderedBulkOp() | |
let cnt = 0 | |
this.add = record => { | |
cnt++ | |
this.bulk.insert(record) | |
if(cnt >= limit) { | |
this.flush() | |
} |
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
var gpio = require('rpi-gpio-mod'); | |
function onoff(v) { | |
gpio.setup(8, gpio.DIR_OUT, write); | |
function write() { | |
gpio.write(8, v, function(err) { | |
if (err) throw err; | |
console.log('Written to pin'); |
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
// tested with mongodb 2.2.25 | |
const MongoClient=require('mongodb').MongoClient | |
const Promise = require('bluebird') | |
module.exports = (connOpts) => { | |
return MongoClient | |
.connect(connOpts, {promiseLibrary: Promise}) | |
// .then(db => db) /* not necessary */ | |
.disposer(db => { | |
console.log('to disconnect') |
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 inquirer = require('inquirer') | |
const genList = (list) => { | |
const choices = list.map((item, index) => { | |
return { | |
key: index, | |
name: `${item.id}: ${item.quantity}@${item.price}`, | |
value: item.id | |
} | |
}) |
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 fetch = require('node-fetch') | |
const Promise = require('bluebird') | |
const headers = { | |
'User-Agent': 'YOUR-GITHUB-USERNAME' | |
} | |
const repos = [ | |
'scottwrobinson/camo', | |
'facebook/react', |
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 mongoose = require('mongoose') | |
mongoose.Promise = require('bluebird') // optional, use this to get rid of | |
// the mpromise DeprecationWarning | |
const conn = mongoose.createConnection('mongodb://localhost/testDB') | |
const Schema = mongoose.Schema | |
const UserSchema = new Schema({ | |
username: String, | |
email: String | |
}) |
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
async function main() { | |
const Hapi = require('./lib'); | |
const server = Hapi.server({ port: 80 }); | |
server.event('test'); | |
server.events.once('test', (update) => console.log(update)); | |
await server.emit('test', 'hello'); | |
await server.emit('test', 'hello'); // Ignored | |
} |
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
// using array | |
const bluebird = require('bluebird') | |
const things = [{a: 1}, {b: 2}, {c: 3}] | |
function doit(doc) { | |
return bluebird.delay(1000).then(() => {return doc}) | |
} | |
async function main() { |
OlderNewer