Skip to content

Instantly share code, notes, and snippets.

View dev-drprasad's full-sized avatar

Reddy Prasad D dev-drprasad

View GitHub Profile
@dev-drprasad
dev-drprasad / gist:abb721f490258b5165b143c5b193a9ec
Created December 23, 2020 07:19 — forked from moraes/gist:2141121
LIFO Stack and FIFO Queue in golang
package main
import (
"fmt"
)
type Node struct {
Value int
}
function useMultiFetch<T>(args: [string, RequestInit][]) {
const [response, setResponse] = useState([] as [T | undefined, NS][]);
const ref = useRef([] as [T | undefined, NS][]);
const abortRef = useRef([] as AbortController[]);
useEffect(() => {
if (args.length === 0) return;
const lendiff = args.length - ref.current.length;
if (lendiff < 0) {
ref.current = ref.current.slice(0, lendiff);
@dev-drprasad
dev-drprasad / delete-github-tags-with-prefix.js
Last active June 20, 2020 17:23
JavaScript code to delete multiple git tags with given tag prefix. Run: GITHUB_TOKEN=<replace with yours> GITHUB_REPOSITORY=<owner>/<repo> TAG_PREFIX=<tag prefix> node delete-github-tags-with-prefix.js
/**
* run: GITHUB_TOKEN=<replace with yours> GITHUB_REPOSITORY=<owner>/<repo> TAG_PREFIX=<tag prefix> node delete-github-tags-with-prefix.js
*
* GITHUB_TOKEN: github secret token with access **repo**
* GITHUB_REPOSITORY: repo name in the form of <owner>/<repoName>
* TAG_PREFIX: prefix of tags that need to be deleted. refer: https://developer.github.com/v3/git/refs/#list-matching-references
*/
const https = require("https");
@dev-drprasad
dev-drprasad / send_email_mailgun_nodejs.js
Created April 25, 2019 10:05
Send email via mailgun using NodeJS standard library
const https = require('https');
const qs = require('querystring');
const MAILGUN_API_TOKEN = '<api-token>';
const MAILGUN_API_PATH = '<api-path>'; // API url without hostname
const MAILGUN_FROM_EMAIL = '<from@email.com>';
const options = {
hostname: 'api.mailgun.net',
path: MAILGUN_API_PATH,
@dev-drprasad
dev-drprasad / RangeHTTPServer.py
Created April 17, 2019 16:14 — forked from shivakar/RangeHTTPServer.py
Python's SimpleHTTPServer extended to handle HTTP/1.1 Range requests
import os
import SimpleHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
class RangeHTTPRequestHandler(SimpleHTTPRequestHandler):
"""RangeHTTPRequestHandler is a SimpleHTTPRequestHandler
with HTTP 'Range' support"""
def send_head(self):
"""Common code for GET and HEAD commands.
@dev-drprasad
dev-drprasad / send_email_mailgun_python3.py
Created April 11, 2019 14:47
Send email via mailgun using python3 standard library (urllib)
import base64
import urllib
MAILGUN_API_URL = "<api-url>"
MAILGUN_API_TOKEN = "<api-token>"
def send_mail(from_email, to_email, subject, message):
data = urllib.parse.urlencode({
"from": from_email,
@dev-drprasad
dev-drprasad / extract_specific_child_zips.js
Last active July 19, 2018 12:57
Extract specific child zips from zip file using node and express
const express = require('express');
const fs = require('fs');
const extract = require('extract-zip')
const formidable = require('formidable');
const path = require('path');
const uploadDir = path.join(__dirname, '/uploads/');
const extractDir = path.join(__dirname, '/app/');
if (!fs.existsSync(uploadDir)) {
fs.mkdirSync(uploadDir);
}
@dev-drprasad
dev-drprasad / recursive_extract_zip_node.js
Last active December 31, 2021 06:06
Extract uploaded zip files using express.js and nodejs with recursive extraction
const express = require('express');
const fs = require('fs');
const extract = require('extract-zip')
const formidable = require('formidable');
const path = require('path');
const uploadDir = path.join(__dirname, '/uploads/');
const extractDir = path.join(__dirname, '/app/');
if (!fs.existsSync(uploadDir)) {
fs.mkdirSync(uploadDir);
}
@dev-drprasad
dev-drprasad / pageWrapper.js
Created July 13, 2018 17:55
wrapper to make requests in nextjs components
import { Fragment } from 'react';
import querystring from 'querystring';
import PropTypes from 'prop-types';
import getTheme from 'styles/getTheme';
import { sanitizeCookies } from 'utils/utils';
import { fetcher } from 'utils/apiCaller';
import logger from 'utils/logger';
import ErrorPage from './ErrorPage';
@dev-drprasad
dev-drprasad / apiCaller.js
Last active July 13, 2018 17:44
helper function to make API requests using node/javascript
const fetch = require('isomorphic-fetch');
const { apiEndpoint } = require('./endpoint');
const logger = require('./logger');
// expected time for API service to respond
const RESPONSE_TIMEOUT = 2 * 60 * 1000;
const fetcher = (url, options = {}, mode = 'JSON') => {
const finalUrl = apiEndpoint + url;