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 / output.json
Created February 14, 2019 07:47
The data we need to get.
{
"title": "Arrow",
"runtime": "42min",
"year": "2012",
"story": "Oliver Queen and his father are lost at sea when their luxury yacht sinks, apparently in a storm. His father dies, but Oliver survives for five years on an uncharted island and eventually returns home. But he wasn't alone on the island where he learned not only how to fight and survive but also of his father's corruption and unscrupulous business dealings. He returns to civilization a changed man, determined to put things right. He disguises himself with the hood of one of his mysterious island mentors, arms himself with a bow and sets about hunting down the men and women who have corrupted his city.",
"creators": [
"Greg Berlanti",
"Marc Guggenheim",
"Andrew Kreisberg"
],
@anshulrgoyal
anshulrgoyal / worker.js
Created February 14, 2019 13:03
Woker for the pahse
const {
Worker,
isMainThread,
parentPort,
workerData
} = require("worker_threads");
const lib = require("./lib");
if (isMainThread) {
@anshulrgoyal
anshulrgoyal / index.js
Created February 14, 2019 13:06
Index.js
const workers = require("./woker");
workers("tt2193021")
.then(console.log)
.catch(console.error);
@anshulrgoyal
anshulrgoyal / lib.js
Created February 15, 2019 11:47
Example For Episodes
function getEpisode(id, season, callback) {
request(
`https://www.imdb.com/title/${id}/episodes/_ajax?season=${season}`,
function(error, response, data) {
const episodes = [];
const $ = cheerio.load(data);
$(".eplist > .list_item").each(function(i) {
const story = $(
`.eplist > div:nth-child(${i + 1}) > .info > .item_description`
)
@anshulrgoyal
anshulrgoyal / lib.js
Created February 15, 2019 12:06
Example cast
function getCast(id, n, callback) {
request(
`https://m.imdb.com/title/${id}/fullcredits/cast?ref_=m_ttfc_3`,
(error, response, data) => {
const $ = cheerio.load(data);
let cast = [];
let i = 0;
while (i < n) {
try {
cast.push({
import React from "react";
import s from "./app.component.css";
export default function App(props) {
return (
<form className={s.form}>
<input
type="email"
placeholder="Enter email"
name="email"
@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: ""
};
@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 / 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 / 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