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 / sexify_currency.py
Created July 24, 2017 09:17
python code to convert float values to indian money format
import locale
from math import log10
def sexify(value):
"""
formats the float value to indian money format
:param value:
:return:
"""
@dev-drprasad
dev-drprasad / simple_oauth.py
Created December 22, 2017 19:33
OAuth Client to refresh access token with caching
import json
import requests
from time import time
class OAuthClient:
def __init__(self, server, client_id, client_secret, grant_type, scope):
self.server = server
self.client_id = client_id
self.client_secret = client_secret
@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;
@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 / recursive_extract_zip_node.js
Last active May 29, 2024 15:39
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 / 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 / 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 / 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_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 = '<[email protected]>';
const options = {
hostname: 'api.mailgun.net',
path: MAILGUN_API_PATH,
@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");