⚠WARNING

ZOMBIE ATTACK IMMINENT 

HISTORY TIME

Get pumped!

@benspoon

HISTORY TIME

Get pumped!

Zombies Ate My Neighbors

1993

@benspoon

@benspoon

LiveScript JavaScript was born

HISTORY TIME

Get pumped!

1995

@benspoon

HISTORY TIME

Get pumped!

@benspoon

HISTORY TIME

Get pumped!

1999

ECMAScript third edition

  • powerful regular expressions
  • better string handling
  • new control statements
  • try/catch exception handling
  • tighter definition of errors
  • formatting for numeric output

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. 

HISTORY TIME

Get pumped!

 - Steve Champeon, 2001

JavaScript: How Did We Get Here? http://archive.oreilly.com/pub/a/javascript/2001/04/06/js_history.html Accessed 6/5/2015

@benspoon

Most of the people writing in JavaScript are not programmers. They lack the training and discipline to write good programs... 

HISTORY TIME

Get pumped!

- Douglas Crockford, 2001

JavaScript: The World's Most Misunderstood Programming Language http://www.crockford.com/javascript/javascript.html Accessed 6/5/2015

@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. 

HISTORY TIME

Get pumped!

- Douglas Crockford, 2001

JavaScript: The World's Most Misunderstood Programming Language http://www.crockford.com/javascript/javascript.html Accessed 6/5/2015

@benspoon

But it isn't 2001

@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

Zombies

@benspoon

In our scenario

  • The Zombies didn't kill all the electricity
  • Or the internet
  • Or are very intelligent 
  • Or move very fast 
  • And may or may not be vulnerable to water

@benspoon

And Luckily:

  • You know how to program in JavaScript
  • You own a few drones
  • You own a bunch of Arduino boards and parts
  • You own a bunch of computers

@benspoon

Getting Started:

Protecting the perimeter

@benspoon

Detect

Getting Started:

Protecting the perimeter

Alert

Take Action

@benspoon

@benspoon

Getting Started:

Protecting the perimeter

Detect

@benspoon

Getting Started:

Protecting the perimeter

@benspoon

So let's talk about robots

Getting Started:

Protecting the perimeter

@benspoon

Johnny-Five

Getting Started:

Protecting the perimeter

@benspoon

Getting Started:

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

Getting Started:

Protecting the perimeter

Zombies don't care about console.log()

@benspoon

Getting Started:

Protecting the perimeter

Alert

@benspoon

Getting Started:

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

Getting Started:

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

Getting Started:

Protecting the perimeter

Database time

@benspoon

Getting Started:

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

Getting Started:

Protecting the perimeter

Take Action

@benspoon

Getting Started:

Protecting the perimeter

@benspoon

Getting Started:

Protecting the perimeter

Parrot Rolling-Spider

@benspoon

Getting Started:

Protecting the perimeter

Parrot AR.Drone 2.0

@benspoon

Getting Started:

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

Getting Started:

Protecting the perimeter

Sending Email (SMTP)

@benspoon

Getting Started:

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

Getting Started:

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

  • Laster Trip Wire - Johnny-Five
  • Web Server - Express
  • Sending a request - Request
  • MongoDB & Mongoose
  • Sending email - Nodemailer
  • Launching a drone - rolling-spider

LETS DO IT

@benspoon

@benspoon

"Ok cool story"

"but why?"

@benspoon

@benspoon

Maybe not

But hopefully

#notBad

@benspoon

Thanks.

@benspoon

Made with Slides.com