Skip to content

Instantly share code, notes, and snippets.

View Bucephalus-lgtm's full-sized avatar
🎴
Work hard in silence and let your success makes the noise.

Bhargab Nath Bucephalus-lgtm

🎴
Work hard in silence and let your success makes the noise.
View GitHub Profile
@Bucephalus-lgtm
Bucephalus-lgtm / post-yoti
Last active March 8, 2022 06:28
Send Email After Verifying User Credentials
const express = require('express');
const bodyParser = require('body-parser');
const nodemailer = require('nodemailer');
const app = express();
const path = require('path');
const dotenv = require('dotenv');
dotenv.config();
app.use(express.static('public'));
// To use the AWS SDK, first import it from aws-sdk npm package
import AWS from 'aws-sdk';
const s3Bucket = `__your_aws_s3_bucket_name__`;
const region = `__your_aws_region_name__`;
const urlExpirationTime = `__your_aws_s3_url_expiration_time__`
AWS.config.update({
accessKeyId: `__your_aws_access_key_id__`,
secretAccessKey: `__your_aws_secret_access_key__`,
// Create a file, say, User.js(basically this file keeps all the configurations and setup for initializing User table in the database)
// Sequelize is an ORM, right?
// So, you don't need to learn SQL to use MySQL, that's what we will do below:
// Import Sequelize from sequelize npm package
const {Sequelize, DataTypes} = require("sequelize");
const sequelize = new Sequelize(
'__your_db_name__',
'__your_db_password__',
{
// Import bcrypt from bcrypt npm package
const bcrypt = require("bcrypt);
// Hash the incoming password using bcyrpt
// Use it during SIGNUP, thus save the hashed password only in Database
async function hashPassword(plaintextPassword) {
    const hashedPassword = await bcrypt.hash(plaintextPassword, 10);
    // Now store it in the database instead of plainText password
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Google reCaptcha Example</title>
<meta charset="utf-8″>
<meta name="viewport" content="width=device-width, initial-scale=1″>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<?php
error_reporting(0);
if (isset($_POST[‘submit’]) && !empty($_POST[‘submit’])) {
if (isset($_POST[‘g-recaptcha-response’]) && !empty($_POST[‘g-recaptcha-response’])) {
$secret = ‘__your_secret_key__’;
$captchaResponse = file_get_contents(‘https://www.google.com/recaptcha/api/siteverify?secret=’ . $secret . ‘&response=’ . $_POST[‘g-recaptcha-response’]);
$responseData = json_decode($captchaResponse );
if ($responseData->success) {
$name = !empty($_POST[‘name’]) ? $_POST[‘name’] : ”;

Obtain Predictions for Your Replicate API

Within pages/api folder of your root directory for your Next.js app, create a folder called replicate.

Now this looks like: pages/api/replicate, right?

Here, write a file called index.js and then insert the following code:

const getPredictions = async (req, res) => {
  const response = await fetch("https://api.replicate.com/v1/predictions", {
 method: "POST",
import requests

headers = {
  'Authorization': 'Bearer <__jwt__>',
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'User-Agent': 'demoApp/1.0',
  'X-Snowflake-Authorization-Token-Type': '<__keyPair_JWT__>',
}

Dockerize the app using the Alpine Version 16 of Node.js

Dockerfile

# Use an existing image, node:16-alpine in this case as the base image
FROM node:16-alpine

# Set the working directory in the container
WORKDIR /app

# Copy the package.json and package-lock.json files into the container

The basic flow is this:

First build the Docker image and then run it in Portainer.

Steps:

  • Build the Docker image:
 docker build -t <__your_image_name__>
  • Launch Portainer:
docker run -d -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer