This file contains hidden or 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
// Load the node-router library by creationix | |
var server = require('node-router').getServer(); | |
// Configure our HTTP server to respond with Hello World the root request | |
server.get("/", function (request, response) { | |
response.simpleText(200, "Hello World!"); | |
}); | |
// Listen on port 8080 on localhost | |
server.listen(8000, "localhost"); |
This file contains hidden or 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 fs = require('fs'); | |
var readline = require('readline'); | |
var filename = 'readme.txt'; | |
//read sample data line by line and create samples with less than 500 records | |
var rl = readline.createInterface({ | |
input : fs.createReadStream(filename), | |
output: process.stdout, |
This file contains hidden or 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 _ = require('lodash'); | |
module.exports = function (node, options) { | |
var best = {node: null, score: -Infinity} | |
, opts = options || {} | |
, color = opts.color || -1 | |
, depth = opts.depth || 10; | |
// negamax algorithm taken from http://wikipedia.org/wiki/Negamax | |
function getScore(node, depth, alpha, beta, color) { |
This file contains hidden or 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 mqtt = require('mqtt') | |
var client = mqtt.connect('mqtt://test.mosquitto.org') | |
client.on('connect', function () { | |
client.subscribe('presence') | |
client.publish('presence', 'Hello mqtt') | |
}) | |
client.on('message', function (topic, message) { | |
// message is Buffer |
This file contains hidden or 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 md5 = require('md5'); | |
console.log(md5('message')); |
This file contains hidden or 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 fs = require('fs'); | |
var applog = '../logs/app.log'; | |
var errlog = '../logs/error.log'; | |
function timestamp() { | |
var date = new Date(); | |
function pad2(n) { | |
return n < 10 ? '0' + n : n; | |
} | |
return (date.getFullYear().toString() + pad2(date.getMonth() + 1) + pad2(date.getDate()) + pad2(date.getHours()) + pad2(date.getMinutes()) + pad2(date.getSeconds())); |
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head><title>blank</title></head> | |
<body> | |
<script> | |
// Store | |
localStorage.setItem("lastname", "Smith"); | |
// Retrieve | |
document.getElementById("result").innerHTML = localStorage.getItem("lastname"); | |
</script> |
This file contains hidden or 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
console.log('Loading function'); | |
// Load the AWS SDK | |
var AWS = require("aws-sdk"); | |
// Set up the code to call when the Lambda function is invoked | |
exports.handler = (event, context, callback) => { | |
// Load the message passed into the Lambda function into a JSON object | |
var eventText = JSON.stringify(event, null, 2); | |
// Log a message to the console, you can view this text in the Monitoring tab in the Lambda console or in the CloudWatch Logs console |
This file contains hidden or 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 AWS = require('aws-sdk'); | |
//Policies | |
//AWSLambdaFullAccess | |
//CloudWatchFullAccess | |
//AmazonSESFullAccess | |
//CloudWatchLogsFullAccess | |
exports.handler = (event, context, callback) => { |
This file contains hidden or 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 AWS = require('aws-sdk'); | |
var s3 = new AWS.S3(); | |
//from a s3 trigger | |
exports.handler = function(event, context, callback) { | |
// Retrieve the bucket & key for the uploaded S3 object that | |
// caused this Lambda function to be triggered | |
var src_bkt = event.Records[0].s3.bucket.name; | |
var src_key = event.Records[0].s3.object.key; |