Skip to content

Instantly share code, notes, and snippets.

View anshulrgoyal's full-sized avatar
🏠
Working from home

Anshul Goyal anshulrgoyal

🏠
Working from home
View GitHub Profile
@anshulrgoyal
anshulrgoyal / addFrame.js
Created June 5, 2020 13:29
Add Mlh Fellowship Frame To image
const { Steps, FromFile, LosslessPNG, FromURL } = require("@imazen/imageflow")
new Steps(new FromFile(process.argv[2]))
.watermark(new FromURL("https://res.cloudinary.com/unbaked/image/upload/v1591363414/frame_e2n8fi.png"), {})
.encode(new FromFile("./with_frame.png"), new LosslessPNG()).execute()
@anshulrgoyal
anshulrgoyal / lib.rs
Created April 14, 2020 13:42
Basic NAPI example
use nodejs_sys::{napi_env, napi_value, napi_create_string_utf8, napi_set_named_property};
use std::ffi::CString;
#[no_mangle]
pub unsafe extern "C" fn napi_register_module_v1(
env: napi_env,
m: napi_value,
) -> nodejs_sys::napi_value {
let key = CString::new("hello").expect("CString::new failed");
let mut local: napi_value = std::mem::zeroed();
@anshulrgoyal
anshulrgoyal / task.rs
Created April 12, 2020 22:21
Napi Async Example
use nodejs_sys::{
napi_async_work, napi_callback_info, napi_create_async_work, napi_create_promise,
napi_deferred, napi_delete_async_work, napi_env, napi_get_cb_info, napi_queue_async_work,
napi_resolve_deferred, napi_status, napi_value,napi_reject_deferred,napi_create_error
};
use std::ffi::c_void;
use crate::{request, scrap, types};
#[derive(Debug, Clone)]
@anshulrgoyal
anshulrgoyal / cmd.sh
Last active January 18, 2020 18:16
Sample for session
npm i -g create-react-app
create-react-app session
cd ./session
npm start
@anshulrgoyal
anshulrgoyal / index.html
Last active June 26, 2019 09:31
.input-blocksdfmdks
<input type="text" id="input">
<script>
const el= document.querySelector('#input')
el.addEventListener('change',(e)=>{
console.log(e.target.value);
})
</script>
@anshulrgoyal
anshulrgoyal / auth.js
Created May 21, 2019 18:30
Middleware for jwt validation
/**
* authenticator - check for token and add user to req
*
* @param {Object} req the req object contains all the info about request
* @param {Object} res the res object contains many methods to respond to request
* @param {Object} next to pass ther control to next middleware
*
* @returns {undefined}
*/
async function authenticator(req, res, next) {
@anshulrgoyal
anshulrgoyal / jwt.js
Created May 21, 2019 18:17
The jwt helper
const jwt = require("jsonwebtoken");
const config = require("../../config")();
module.exports = {
/**
* sign - create a jwt from payload.
*
* @param {Object} payload the payload send to the user
* @param {Function} callback function envoked with two parameters
* 1. error the error in operation
@anshulrgoyal
anshulrgoyal / example.js
Last active May 21, 2019 18:13
This example route for validation.
async function loginUser(userObject, callback) {
// some validation for the request body or data supplied to function
const { error, value } = Joi.validate(userObject, userObjectSchema);
if (error) {
callback(error);
} else {
try {
// check for validate of the access torken the code for it is given in pervious example
const isTokenValid = await fbHelper.validateToken(
userObject.access_token,
@anshulrgoyal
anshulrgoyal / vaidateFB.js
Created May 21, 2019 17:57
Access token validation
/**
* validateToken - validate the token supplied by the frontend
* @param {String} token the token supplied by the front end
* @param {String} ffid the ffid of the user
*/
async function validateToken(token, ffid) {
const data = await request.get(
`https://graph.facebook.com/debug_token?input_token=${token}&access_token=${
config.FB.APP_ID
}|${config.FB.APP_SECERET}`
@anshulrgoyal
anshulrgoyal / app.js
Created March 9, 2019 13:45
Form loading
import React, { useState, Fragment, useEffect } from "react";
import { Formik, Field } from "formik";
import s from "./app.component.css";
import * as yup from "yup";
const intialState = {
name: "",
email: "",
password: ""
};