Skip to content

Instantly share code, notes, and snippets.

View devAgam's full-sized avatar
👩‍🚀
Working from localhost

Agamjot Singh Jashan devAgam

👩‍🚀
Working from localhost
View GitHub Profile
const MAX_CONCURRENT_TASKS = 5;
async function fetchStories() {
const response = await fetch(
"http://localhost:8000/get-where-no-story-content"
);
return response.json();
}
async function updateStoryContent(_id, content) {
let currentPage = 1; // Initialize the current page number to 1
const lastPage = 5933; // Define the last page number to scrape, which is 5933
// Listen for messages from other parts of the Chrome extension (e.g., content scripts)
chrome.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
if (message.stories) { // Check if the message contains a 'stories' property (the scraped data)
try {
// Send the scraped data to an API endpoint on the local server
const response = await fetch("http://localhost:8000/api/stories", {
method: "POST", // Use the POST method to send data
@devAgam
devAgam / api.js
Last active August 26, 2024 04:26
const express = require("express");
const mongoose = require("mongoose");
const cors = require("cors");
const app = express();
const htmlToText = require("html-to-text");
app.use(cors());
app.use(express.json({ limit: "50mb" }));
mongoose.connect("mongodb://localhost:27017/web-scraper", {
@devAgam
devAgam / resume.action.js
Created June 12, 2023 07:30
Sample Function to Automate File Uploads through browser extensions
// This function does the following
// 1. fetches the PDF resume from the url provided
// 2. creates a file object with the resume data
// 3. triggers the change event on the file input element
// 4. the file input element gets the file object
// 5. the file object is uploaded to the website
async function handleResumeInput(remoteResumeURL) {
@devAgam
devAgam / api.js
Created October 8, 2022 05:45
URL Ternary decider
import axios from "axios";
const baseUrlMainServer =
process.env.ENV === "PROD"
? "https://api.project28.in"
: process.env.ENV === "QA"
? "https://qa.project28.in"
: (process.env.ENV = "DEV"
? "https://backend-staging.project28.in"
: "http://localhost:5000");
@devAgam
devAgam / gist:815a8bda1968175c4ce6d12fcffa8d1e
Created October 8, 2022 05:45
ENV Url ternary handler
import axios from "axios";
const baseUrlMainServer =
process.env.ENV === "PROD"
? "https://api.project28.in"
: process.env.ENV === "QA"
? "https://qa.project28.in"
: (process.env.ENV = "DEV"
? "https://backend-staging.project28.in"
: "http://localhost:5000");
@devAgam
devAgam / app.js
Created December 31, 2021 08:49
How to delete a key/cached data from redis
app.get("/sileo-depiction-revalidate/:package", async (req, res) => {
const dep_package = req.params.package; // package name
try {
const redisDepKey = `${dep_package}:depiction`; // redis key
return client.del(redisDepKey, async (err, success) => { // check if cached
if (success == 1) { // if success
res.status(200).send({ // send success acknowledgement
httpStatus: 200,
success: true,
@devAgam
devAgam / app.js
Created December 31, 2021 07:30
Sample of Redis cached route in nodejs
app.get("/sileo-depiction/:package", async (req, res) => {
const dep_package = req.params.package; // package name
try {
const redisDepKey = `${dep_package}:depiction`; // redis key
return client.get(redisDepKey, async (err, cachedData) => { // check if cached
if (cachedData) { // if cached
const parsedData = JSON.parse(depiction); // parse cached data
res.status(200).send({ // send cached data
httpStatus: 200,