Skip to content

Instantly share code, notes, and snippets.

View Zubs's full-sized avatar
👨‍🍳
Cooking

Zubair Idris Aweda Zubs

👨‍🍳
Cooking
View GitHub Profile
@Zubs
Zubs / validator.js
Created March 12, 2022 13:09
Easy Request Validation In ExpressJs
/**
* Validates request body using a set of rules
* @param req Request body, req.body
* @param rules Array of required fields
* @return {{body: {}, errors: string}} Required fields and errors
* @example
const { body, errors } = ValidateRequest(req.body, [
'username',
'last_name',
'email',
@Zubs
Zubs / handleErrors.ts
Created September 13, 2021 13:12
Format errors ( usuually authentication errors) as human readble json
type errors = {
email: string,
password: string,
name?: string
}
/**
* Formats errors as human readable json
* @param error Error object or empty object incase of incorrect password
* @param incorrectEmail boolean
@Zubs
Zubs / login
Created July 25, 2021 13:26
Vue Login
<template>
<v-app style="background: #e2e8eb;">
<v-container>
<v-row justify="center">
<v-col cols="12" md="5">
<v-container>
<v-card class="ma-5 pa-5" color="#e2e8eb">
<v-card-title>
<h1>Login</h1>
@manzari
manzari / two-staged-example.Dockerfile
Last active November 16, 2022 14:04
Dockerfile for two staged build of an react app
# Build
FROM node:alpine
WORKDIR /myReactApp
COPY package.json ./
RUN npm install
COPY . ./
RUN npm run-script build
# Serve
FROM nginx:alpine
@joeytwiddle
joeytwiddle / async-await-forEach-alternatives.md
Last active October 24, 2025 14:23
Do not use forEach with async-await

Do not use forEach with async-await

TLDR: Use for...of instead of forEach() in asynchronous code.

For legacy browsers, use for(...;...;...) or [].reduce()

To execute the promises in parallel, use Promise.all([].map(...))

The problem

@a-h
a-h / index.js
Last active May 17, 2022 05:27
JSON logging in winston with a timestamp
const winston = require('winston');
const MESSAGE = Symbol.for('message');
const jsonFormatter = (logEntry) => {
const base = { timestamp: new Date() };
const json = Object.assign(base, logEntry)
logEntry[MESSAGE] = JSON.stringify(json);
return logEntry;
}
@oxguy3
oxguy3 / deploy.php
Last active April 16, 2025 07:58
Script used to automatically deploy from GitHub to a cPanel shared hosting server
<?php
/**
* deploy.php by Hayden Schiff (oxguy3)
* Available at https://gist.github.com/oxguy3/70ea582d951d4b0f78edec282a2bebf9
*
* No rights reserved. Dedicated to public domain via CC0 1.0 Universal.
* See https://creativecommons.org/publicdomain/zero/1.0/ for terms.
*/
// random string of characters; must match the "Secret" defined in your GitHub webhook