Skip to content

Instantly share code, notes, and snippets.

View questsin's full-sized avatar

Nicholas Manolakos questsin

View GitHub Profile
// 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");
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,
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) {
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
var md5 = require('md5');
console.log(md5('message'));
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()));
<!DOCTYPE html>
<html>
<head><title>blank</title></head>
<body>
<script>
// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML = localStorage.getItem("lastname");
</script>
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
var AWS = require('aws-sdk');
//Policies
//AWSLambdaFullAccess
//CloudWatchFullAccess
//AmazonSESFullAccess
//CloudWatchLogsFullAccess
exports.handler = (event, context, callback) => {
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;