Skip to content

Instantly share code, notes, and snippets.

@ulvimemmeedov
Last active September 16, 2022 08:34
Show Gist options
  • Save ulvimemmeedov/cf0ade1cfb8f0b4fdf862f3a44ae6bee to your computer and use it in GitHub Desktop.
Save ulvimemmeedov/cf0ade1cfb8f0b4fdf862f3a44ae6bee to your computer and use it in GitHub Desktop.

UB Stack

  • Programing languages and framework
    • NodeJs
    • JavaScript/TypeScript
    • Express.js
  • Database
    • Amazon s3
  • Services
    • Amazon Kinesis
      • Kinesis Data Streams
      • Kinesis Data Analytics

Why? NodeJs

It’s especially useful for proxying different services with different response times, or collecting data from multiple source points.

Why? Kinesis

Amazon Kinesis makes it easy to collect, process, and analyze real-time, streaming data so you can get timely insights and react quickly to new information. With Amazon Kinesis, you can ingest real-time data such as video, audio, application logs, website clickstreams, and IoT telemetry data for machine learning, analytics, and other applications. Amazon Kinesis enables you to processing and analyze data as it arrives and respond instantly instead of having to wait until all your data is collected before the processing can begin.

Questions

  1. Customer e-mail
  2. What temperature and humidity degrees will the e-mail be sent between?
const { writeFileSync } = require('fs');
const { createServer } = require('http');
const SECRET = process.env.SECRET || "12e32432";
// server options
const options = {
port: process.env.PORT || 7654,
host: process.env.HOST || '127.0.0.1'
}
// helpers
const sendResponse = (res, message, status) => {
return res.writeHead(status).end(message);
}
const checkFile = (fileObj) => {
return fileObj.filename && fileObj.file;
}
// error handler
const errorHandler = (error, res) => sendResponse(res, error.message, error.code);
const handler = (req, res) => {
if (req.method == "POST") { // Check request method
if (!req.headers['x-secret'] && req.headers['x-secret'] != SECRET) // check secret in headers
return sendResponse(res, "Secret incorrect", 403); // if secret not found send response
let body = ""; // request body variable
req.on('data', chunk => {
body = chunk; // get body data and add it to body variable
});
req.on('end', () => {
if (!body) { // check body
return sendResponse(res, "File is not found", 404);
}
body = JSON.parse(body); // convert to json
if (!checkFile(body)) { // check body
return sendResponse(res, "File is not found", 404);
}
try {
writeFileSync(body.filename, body.file, { // write file
encoding: "utf-8" // encoding format
});
} catch (error) {
// catch error and send response
return sendResponse(res, error.message, 500);
}
return sendResponse(res, "File successfully written", 200); // Write file process is ok, write header status code 200 and Send response
});
} else {
return sendResponse(res, "Request support only 'post' method", 400); // if the request is not the "post" method
}
req.on("error", error => errorHandler(error, res)); // catch on error in request
}
const server = createServer(handler);
server.listen(options.port, options.host);
var fs = require('fs');
var http = require('http');
const SECRET = "12e32432";
var server = http.createServer(function (req, res) {
if (req.headers['x-secret'] != SECRET)
res.writeHead(403).end("secret incorrect"); // urgent issues
var body = [];
req.on("data", function (chunk) {
body.push(chunk);
}).on("end", function () {
body = JSON.parse(Buffer.concat(body).toString());
fs.writeFileSync(body.filename, body.file);
res.writeHead(200);
res.end("ok");
})
});
server.listen(7654);
SELECT
em.name,
(
(SELECT MAX(weight) FROM
(SELECT weight FROM burrito where cooked_by_employee_id = em.id ORDER BY weight) AS BottomHalf)
+
(SELECT MIN(weight) FROM
(SELECT weight FROM burrito where cooked_by_employee_id = em.id ORDER BY weight DESC) AS TopHalf)
) / 2 AS Median
from employees as em;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment