Skip to content

Instantly share code, notes, and snippets.

View appletreeat56's full-sized avatar

appletreeat56

View GitHub Profile
const today = format(new Date(), "ddMMyyyyHHmmssSSS");
const sqs = new SQS({ apiVersion: "2012-11-05" });
let params: SQS.SendMessageRequest = {
MessageAttributes: {
attribute1: {
DataType: "String",
StringValue: "attrubute1",
},
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",
});
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);
//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 {
<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;
router.post(
'/',
checkSchema(charitySchema),
validateCharity,
async (req: Request, res: Response, next: NextFunction) => {
// Insert business logic post validation here
}
)
import {
Result,
ValidationError,
validationResult,
} from 'express-validator'
import { Request, Response, NextFunction } from 'express'
export const validateCharity = async (
req: Request,
res: Response,
{
"name": "Lorem",
"category": "Ipsum",
"registrationCode": "123",
"address": {
"country": "GB",
"postcode": "SW12 2AA",
"city": "London",
"addressLine": "Kings Road"
}
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
}
)
import {
Schema,
} from 'express-validator'
export const organisationSchema: Schema = {
name: {
notEmpty: true,
errorMessage: 'Name field cannot be empty',
},
category: {