Tuesday, November 14, 2017

Comparison Tool

Comparison Tool

Choose the text file you wish to examine for unique values:




 

Choose the text file you are comparing the first file to:


The values that appear in the first file that do not appear in the second are:

Friday, January 6, 2017

What makes us human

We are looking at some big changes in the near future. Once again, machines are replacing people en masse and we just can't quite see what the future holds.

You don't know what the future holds so don't put too much stock in predictions. Rather, develop a deep love of learning and of the fundamentals, and develop an insatiable urge to push at the outer edges every chance you get. Those are two things machines will never know to do, no matter how complex they get.  

For example, here is some pretty good analysis I read the other day:

"Software development is growing fast. Learning to code is easier than ever, and soon enough we will be in a survival-of-the-fittest environment. But the developer who survives is not going to be the developer who first learned about the cool new framework. It's going to be the developer who asked himself what's new about it and what's different this time. If you want to stay up to date with technology stacks, then stop worrying so much about being up to date and start hacking."
- https://techbeacon.com/what-full-stack-developer-should-mean

Be fearless. Keep learning. Keep hacking.

Monday, January 2, 2017

Trying to explain and understand "A simple chat server using Socket.IO, Express, and Async" - PART I

  //
  // # SimpleServer
  //
  // A simple chat server using Socket.IO, Express, and Async.
  //
var http = require('http');  //OK, to use Node's HTTP server and client, one must require('http') from the get-go
var path = require('path');  // OK, there is a lot that goes into using and manipulating file and directory paths; this provides a set of utilities to do that

var async = require('async'); // OK, this provides a whole host of powerful functions for working with asynchronous JavaScript
var socketio = require('socket.io'); // OK, WebSockets facilitates ongoing conversation between browser and web server without being solicited by the client,  while keeping the connection open.

var express = require('express');  // OK, just a bunch of additional web application tools inside of Node

  //
  // ## SimpleServer `SimpleServer(obj)`
  //
  // Creates a new instance of SimpleServer with the following options:
  //  * `port` - The HTTP port to listen on. If `process.env.PORT` is set, _it overrides this value_.
  //
var router = express();
      // OK, first of all, "routing." What is routing in node? Here is the basic format: app.method(path, handler) (see https://expressjs.com/en/starter/basic-routing.html )
        //"app" is an instance of express (in this example, the app is called 'router' since 'var router = express()')
        //"method" is one of several HTTP request methods (get, post, put, delete, etc)
        // "path" is a path on the server to a particular resource
        // "handler" is whatever function is to be carried out when Node finds a match for the route
      // SO, what's going on here is you are saying the "app" part of 'app.method(path, handler)' is going to be called 'router'

var server = http.createServer(router); // OK, this calls http.Server() internally and returns the resulting instance

var io = socketio.listen(server); // OK, this marks the socket referred to as a passive socket that will be used to accept incoming connection requests  

router.use(express.static(path.resolve(__dirname, 'client')));  // OK you are passing the name of the directory that contains the static assets to the express.static middleware function


var messages = []; // OK, this is just creating an array called messages
var sockets = []; // OK, this is just creating an array called sockets

io.on('connection', function (socket) {
    messages.forEach(function (data) {
      socket.emit('message', data);
    });

    sockets.push(socket);

    socket.on('disconnect', function () {
      sockets.splice(sockets.indexOf(socket), 1);
      updateRoster();
    });

    socket.on('message', function (msg) {
      var text = String(msg || '');

      if (!text)
        return;

      socket.get('name', function (err, name) {
        var data = {
          name: name,
          text: text
        };

        broadcast('message', data);
        messages.push(data);
      });
    });

    socket.on('identify', function (name) {
      socket.set('name', String(name || 'Anonymous'), function (err) {
        updateRoster();
      });
    });
  });

function updateRoster() {
  async.map(
    sockets,
    function (socket, callback) {
      socket.get('name', callback);
    },
    function (err, names) {
      broadcast('roster', names);
    }
  );
}

function broadcast(event, data) {
  sockets.forEach(function (socket) {
    socket.emit(event, data);
  });
}

server.listen(process.env.PORT || 3000, process.env.IP || "0.0.0.0", function(){
  var addr = server.address();
  console.log("Chat server listening at", addr.address + ":" + addr.port);
});

Thursday, December 22, 2016

Learnyoumongo Exercise 3 solution and explanations


var mongoDatabaseBeingUsed = require('mongodb').MongoClient  // MongoClient is a set of functions that allow your code to connect to the mongo database. Without something like MongoClient, your code would have no way of reading or writing to the database

var threshold = parseInt(process.argv[2])  // Why is parseInt getting used here? Because one of the things it does is take a string and change it to an integer. You are going to need this variable to be in integer form later on


var url = 'mongodb://localhost:27017/learnyoumongo'  // 'The database' // 'is being listened to here' // 'and this is the resource from it we want'

mongoDatabaseBeingUsed.connect(url, function(err, db) { // 'Here, handle an error or handle the db'
  if (err) throw err
  var parrots = db.collection('parrots') // OK, here we actually get into what a mongo database is and how a mongo database works. It's kind of like mongo keeps all its information on a grocery list, (whereas something like SQL keeps all of its information on something that looks like an Excel spreadsheet). That mongo document is called a BSON and looks and acts kind of like a list of JSONs (if you have made it this far in FCC, you are familiar with JSON at this point). So picture a list  of JSONs on a piece of paper. Each individual JSON in mongo is called a 'collection.' The piece of paper containing the list of JSON-like entries is the mongo database. SO, "var parrots = db.collection('parrots')" means 'get me the collection called "parrots" from the database we are already connected to, and make the variable called "parrots" point to it.'


  parrots.find({     age: {       $gt: threshold     }   }).toArray(function(err, docs) {
// Arright, a couple of things to wrap your head around with the above statement. First of all, we don't want to end up with a variable containing a bunch of values. We want a pointer pointing to a certain section of the mongo db. This pointer is called a 'cursor' in mongo-speak.   Now, .find() points cursors at what we need the cursors pointed at, and whatever that cursor is pointing at, we want to then populate an array with so we can print it with console.log. So, that is why we are using the collection.find().toArray() convention here.


    if (err) throw err
    console.log(docs)
)
    db.close()
  })
})

Wednesday, December 21, 2016

Learnyoumongo (Mongo in C9) exercise 2 and 3 pitfalls for beginners

Sorry, no explicit solution here - I am writing for those who just need to get off the ground and are trying to understand exactly what is required of them for this tutorial.

It is important to realize that exercises one and two are not just their own exercises but the necessary steps leading up to getting everything running properly before you can even run your solution for exercise 3.

It took me a while to realize this (duh), so let me repeat the above information: Exercises one and two of the learnyoumongo tutorial get you connected and get the server running in the background. So you can't do exercise one day, two the next, then come back in a couple days, write your solution for three and expect it to run. After you have put together your solution for exercise three, you have to go back and repeat exercises one and two as the first steps of exercise three.

Before you do exercise 3:

1. Start a new terminal and enter the command $ learnyoumongo
2. Select exercise 1 and hit enter
3. If you have already done exercise one before, this time just enter $ learnyoumongo verify and hit enter
4. Enter the command $ learnyoumongo
5. Select exercise 2 and hit enter
6. When the directions say "To start mongo on port 27017, run mongod --port 27017 --dbpath=./data" don't do that. Do this:

    $ mongod --port 27017 --dbpath=./data --smallfiles

Otherwise you might get an error that you need to free up space

7. Open a second terminal and DO EVERYTHING ELSE IN THE SECOND TERMINAL, from "$ npm install mongodb" to "$ learnyoumongo verify [solution.js]" for exercise 2 to everything for exercise 3. Do it all in the second terminal with the db server running in the first terminal.

Side note:

If you are messing around trying to get stuff to work and get the "journal" or the "lock" error followed by the message that it failed to connect, do this:

    $ mongod --dbpaths=./data -- repair

...assuming you called your data file "data"

I still have not figured completely why that works, but it worked for me when I encountered CONNECTION errors.

Monday, December 12, 2016

Stylish CSS solution and explanations

var express = require('express')
var app = express();
var stylus = require('stylus') //sylus is yet another CSS preprocessor, written this time for Node
var STATIC_DIR = process.argv[3] // static files hold scripts, css files, etc - here the lesson is sending a request that contains one of these - the goal is convert it to regular CSS


app.use(stylus.middleware(STATIC_DIR))//ok app, I don't want to just write normal ole css, I'm fancy. I want to write stylus 
//instead 'cause it gives me all sorts of cool extra tools to keep my css code nice and tidy. 
app.use(express.static(STATIC_DIR))//I've let you know I want to use stylus, now when you're in the middle of firing up my app, 
//before you consider everything good to go, take a look around, find all my stylus files and convert them into normal css so 
//the browsers can understand them


app.listen(process.argv[2]) //OK to get the ball rolling listen for requests on this port

Friday, December 9, 2016

Param Pam Pam solution and explanations

Directions:
Create an Express.js server that takes a parameter from a browser’s request (in this case, it’s going to take a parameter from the request called ‘id’) and PUT it in a specified endpoint (in this case, PUT '/message/:id').
(So that if ‘id’ is ‘526aa677a8,’ the endpoint ends up like this:   ‘/message/526aa677a8’ )
Then, for your response, return the SHA1 hash of the current date
plus the sent ID (basically, take the current date plus the ID and encrypt all of it!)
Use SHA1 hash to encrypt stuff this way:
                                require('crypto')
                                  .createHash('sha1')
                                 .update(new Date().toDateString() + id)
                                .digest('hex')
Code:
var express = require('express')
var app = express();
app.put('/message/:id', function (req, res) {
                 var id = req.params.id // ‘params’ on the IncomingMessage object is ‘params: { id: '4b693a688d2115d70c6f1d95edac8651' }’
                // if you want to, do this to see the request from the browser:          var test1 = req      console.log(test1)
                 var str = require('crypto'). // Now, add it to the current date and encrypt everything
createHash('sha1').
update(new Date().
toDateString() + id).
digest('hex')
                 res.send(str)  // send the string of encrypted characters back to the client
})
app.listen(process.argv[2]) //OK, to get the ball rolling listen for requests here
OUTPUT:

1d408bcfd164a6c39dc07530c1505c353f103d98’  (yep, a bunch of gobbledygook-  because it’s encrypted!)