Ben Spoon
Front-end Developer @AWeber
⚠WARNING
ZOMBIE ATTACK IMMINENT
Get pumped!
@benspoon
Get pumped!
Zombies Ate My Neighbors
1993
@benspoon
@benspoon
LiveScript JavaScript was born
Get pumped!
1995
@benspoon
Get pumped!
@benspoon
Get pumped!
1999
ECMAScript third edition
ECMAScript® Language Specification http://www.ecma-international.org/ecma-262/5.1/ accessed 6/5/2015
@benspoon
Continuing lack of an IDE, debugger, and other standard development tools are still considered insurmountable problems by many programmers, who defend their Windows-only applications with the not unreasonable excuse that debugging is too hard on a platform that lacks a debugger.
Get pumped!
- Steve Champeon, 2001
@benspoon
Most of the people writing in JavaScript are not programmers. They lack the training and discipline to write good programs...
Get pumped!
- Douglas Crockford, 2001
@benspoon
...This has given JavaScript a reputation of being strictly for the amateurs, that it is not suitable for professional programming. This is simply not the case.
Get pumped!
- Douglas Crockford, 2001
@benspoon
@benspoon
@benspoon
We are kind of a big deal.
JavaScript Developers
@benspoon
@benspoon
Web Servers
SMTP Servers
Web Sockets
Games
Phone Calls
Text Messages
@benspoon
It's pretty amazing.
@benspoon
Node.js Serial Port
@benspoon
Serial Port Access
@benspoon
@benspoon
@benspoon
@benspoon
@benspoon
Protect Yourself Against Zombies
With JavaScript
(yes, JavaScript)
@benspoon
An Exploration of JavaScript Touching on The Acceptance and Diversity of the Language Within Real World Applications.
Sounded way too boring
@benspoon
@benspoon
@benspoon
@benspoon
Protecting the perimeter
@benspoon
Protecting the perimeter
@benspoon
@benspoon
Protecting the perimeter
@benspoon
Protecting the perimeter
@benspoon
So let's talk about robots
Protecting the perimeter
@benspoon
Protecting the perimeter
@benspoon
Protecting the perimeter
Laser Trip Wire
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var laser = new five.Led(9);
var detection = new five.Sensor("A0");
var isSecure = false;
laser.on();
detection.scale(0, 1).on("change", function() {
// Note that my sensor isn't as good as
// the one used in the example (I guess)
// so I had to change this next line to over
// 0.9 instead of 0 | 1.
var reading = !(this.value > 0.9);
if (isSecure !== reading) {
isSecure = reading;
if (!isSecure) {
console.log("Intruder");
}
}
});
});
@benspoon
Protecting the perimeter
Zombies don't care about console.log()
@benspoon
Protecting the perimeter
@benspoon
Protecting the perimeter
Express
var express = require('express'),
app = express();
var port = process.env.PORT || 8080;
// test route to make sure everything is working (accessed at GET http://localhost:8080/api)
app.get('/', function(req, res) {
res.send('Zombie protection service is up and running!');
// optionally we could use json in our response:
// res.json(message: 'Zombie protection service is up and running!');
});
//start server
app.listen(port);
console.log('Starting Zombie protection service on port ' + port);
$ node example/scripts server.js
Running "execute:server" (execute) task
-> executing /Users/spoon/git/zombies/scripts/server.js
Starting Zombie protection system on port 8080
@benspoon
Protecting the perimeter
Request
var request = require('request');
request('http://localhost:8080/', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
} else {
console.log('Some sort of error!');
}
})
$ node scripts/request.js
Zombie protection service is up and running!
@benspoon
Protecting the perimeter
Database time
@benspoon
Protecting the perimeter
var express = require("express");
var mongoose = require("mongoose");
mongoose.connect('mongodb://localhost/zombies');
var sensorListSchema = {
unit_id: Number,
location: String,
type: String
}
var SensorList = mongoose.model('SensorList', sensorListSchema, 'sensors');
var app = express();
// List all the sensors
app.get('/listSensors', function (req, res) {
SensorList.find(function (err, doc) {
res.send(doc);
});
});
app.listen(8080);
@benspoon
Protecting the perimeter
@benspoon
Protecting the perimeter
@benspoon
Protecting the perimeter
Parrot Rolling-Spider
@benspoon
Protecting the perimeter
Parrot AR.Drone 2.0
@benspoon
Protecting the perimeter
Parrot Rolling Spider
var RollingSpider = require("rolling-spider"),
temporal = require("temporal"),
drone = new RollingSpider();
drone.connect(function() {
drone.setup(function() {
temporal.queue([
{
delay: 0,
task: function () {
drone.flatTrim();
drone.startPing();
console.log('connected!');
drone.takeOff();
}
},
{
delay: 500,
task: function() {
console.log('landing!');
drone.land();
}
}]);
});
});
@benspoon
Protecting the perimeter
Sending Email (SMTP)
@benspoon
Protecting the perimeter
https://github.com/andris9/Nodemailer
var nodemailer = require('nodemailer'),
fs = require('fs'),
data = fs.readFileSync('./smtp-config.json'),
smtpConfig;
smtpConfig = JSON.parse(data);
// create reusable transporter object using SMTP transport
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: smtpConfig.username,
pass: smtpConfig.password
}
});
{
"username" : "youremail@gmail.com",
"password" : "yourPassword"
}
@benspoon
Protecting the perimeter
https://github.com/andris9/Nodemailer
// setup e-mail data with unicode symbols
var mailOptions = {
from: 'Ben Spoon <ben@benspoon.com>', // sender address
to: 'ben@benspoon.com', // list of receivers
subject: 'ZOMBIES ARE HERE', // Subject line
text: 'Dude, there are zombies. You should do something', // plaintext body
html: '<b>Dude, there are zombies. You should do something</b>' // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
@benspoon
Putting it all together
@benspoon
Putting it all together
LETS DO IT
@benspoon
@benspoon
"Ok cool story"
"but why?"
@benspoon
@benspoon
Maybe not
But hopefully
#notBad
@benspoon
Thanks.
@benspoon
By Ben Spoon
A walkthrough of JavaScript technologies using Node.js