Skip to content

Instantly share code, notes, and snippets.

View bernardobelchior's full-sized avatar

Bernardo Belchior bernardobelchior

View GitHub Profile
module.exports = function (RED) {
var LowerCaseNode = /** @class */ (function () {
function LowerCaseNode(config) {
RED.nodes.createNode(this, config);
this.on('input', function (msg) {
msg.payload = msg.payload.toLowerCase();
this.send(msg);
});
}
return LowerCaseNode;
module.exports = function (RED: Red) {
class LowerCaseNode {
constructor(config: NodeProperties) {
RED.nodes.createNode(this, config);
this.on('input', function(msg: any) {
msg.payload = msg.payload.toLowerCase();
this.send(msg);
});
}
module.exports = function(RED) {
function LowerCaseNode(config) {
RED.nodes.createNode(this,config);
var node = this;
node.on('input', function(msg) {
msg.payload = msg.payload.toLowerCase();
node.send(msg);
});
}
RED.nodes.registerType("lower-case", LowerCaseNode)
fn main() {
lambda::gateway::start(|req| {
//...
let encoded_thumbnail = encode_png_image(thumbnail)?;
let encoded_thumbnail = base64::encode(&encoded_thumbnail);
let res = lambda::gateway::response() // Create a response
.status(200) // Set HTTP status code as 200 (Ok)
.body(lambda::gateway::Body::from(encoded_thumbnail))?; // Convert the encoded_thumbnail to
fn encode_png_image(image: DynamicImage) -> Result<Vec<u8>, ImageError> {
let mut result: Vec<u8> = Vec::new(); // Creates the output `Vec<u8>`
image.write_to(&mut result, ImageOutputFormat::PNG)?; // Writes `image` to `result` as a PNG
Ok(result)
}
fn main() {
lambda::gateway::start(|req| {
fn main() {
lambda::gateway::start(|req| {
//...
let image = load_from_memory(&image)?;
let thumbnail = image.thumbnail(128, 128); // Create the 128x128 thumbnail
// ...
})
}
extern crate aws_lambda as lambda;
extern crate image;
use image::{DynamicImage, ImageError, ImageOutputFormat};
use image::load_from_memory;
fn encode_png_image(image: DynamicImage) -> Result<Vec<u8>, ImageError> {
let mut result: Vec<u8> = Vec::new();
image.write_to(&mut result, ImageOutputFormat::PNG)?;
fn main() {
lambda::gateway::start(|req| {
let base64_image: &str = req.body().as_str()?;
let image: Vec<u8> = base64::decode(base64_image)?; // Decode base64 image
let image: DynamicImage = load_from_memory(&image)?; // Convert image into `DynamicImage`
// ...
})
fn main() {
lambda::gateway::start(|req| {
let base64_image: &str = req.body().as_str()?;
//...
})
}
@bernardobelchior
bernardobelchior / main.rs
Last active November 7, 2018 17:47
Hello world for Rust AWS Lambda
extern crate aws_lambda as lambda;
fn main() {
lambda::gateway::start(|_req /* API Gateway Request */| {
let res = lambda::gateway::response() // Construct API Gateway Response
.status(200)
.body(lambda::gateway::Body::from("Hello, World!"))?; // Convert String to Body
Ok(res) // Return response
})