This file contains 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 today = format(new Date(), "ddMMyyyyHHmmssSSS"); | |
const sqs = new SQS({ apiVersion: "2012-11-05" }); | |
let params: SQS.SendMessageRequest = { | |
MessageAttributes: { | |
attribute1: { | |
DataType: "String", | |
StringValue: "attrubute1", | |
}, |
This file contains 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
import { NextApiRequest, NextApiResponse } from "next"; | |
import S3 from "aws-sdk/clients/s3"; | |
const s3 = new S3({ | |
region: process.env.AWSDEFAULTREGION, | |
accessKeyId: process.env.AWSACCESSKEYID, | |
secretAccessKey: process.env.AWSSECRETACCESSKEY, | |
signatureVersion: "v4", | |
}); |
This file contains 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
import axios from "axios"; | |
import { useEffect, useState } from "react"; | |
export default function FileUpload() { | |
const [file, setFile] = useState<any>(null); | |
const [uploadingStatus, setUploadingStatus] = useState<boolean>(false); | |
const uploadFile = async () => { | |
setUploadingStatus(true); |
This file contains 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
//cols: Width of the image representing total number of columns | |
//x: Row position of this pixel | |
//y: Column position of this pixel | |
const extractPixelColor = (cols: number, x: number, y: number) => { | |
//To get the exact pixel, the logic is to multiply total columns in this image with the row position of this pixel and then add the column position of this pixed | |
let pixel = (cols * x) + y; | |
//To get the array position in the entire image data array, simply multiply your pixel position by 4 (since each pixel will have its own r,g,b,a in that order) | |
let position = pixel * 4; | |
//the rgba value of current pixel will be the following | |
return { |
This file contains 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
<canvas id="myCanvas"> </canvas> | |
<script> | |
let img = new (window as any).Image(); | |
img.crossOrigin = `Anonymous`; | |
img.src = "https://images.unsplash.com/photo-1667461143891-d52ffd5500f5"; | |
img.onload = function () { | |
canvas = document.getElementById("myCanvas") as HTMLCanvasElement; |
This file contains 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
router.post( | |
'/', | |
checkSchema(charitySchema), | |
validateCharity, | |
async (req: Request, res: Response, next: NextFunction) => { | |
// Insert business logic post validation here | |
} | |
) |
This file contains 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
import { | |
Result, | |
ValidationError, | |
validationResult, | |
} from 'express-validator' | |
import { Request, Response, NextFunction } from 'express' | |
export const validateCharity = async ( | |
req: Request, | |
res: Response, |
This file contains 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
{ | |
"name": "Lorem", | |
"category": "Ipsum", | |
"registrationCode": "123", | |
"address": { | |
"country": "GB", | |
"postcode": "SW12 2AA", | |
"city": "London", | |
"addressLine": "Kings Road" | |
} |
This file contains 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
import { checkSchema } from 'express-validator' | |
import { charitySchema } from '../schemas/chaity-schema' | |
router.post( | |
'/', | |
checkSchema(charitySchema), | |
async (req: Request, res: Response, next: NextFunction) => { | |
//Add business logic after validation | |
} | |
) |
This file contains 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
import { | |
Schema, | |
} from 'express-validator' | |
export const organisationSchema: Schema = { | |
name: { | |
notEmpty: true, | |
errorMessage: 'Name field cannot be empty', | |
}, | |
category: { |
NewerOlder