Skip to content

Instantly share code, notes, and snippets.

View xettri's full-sized avatar
🍻
Chill And Code

Bharat Rawat xettri

🍻
Chill And Code
View GitHub Profile
export const uploadFile = ({
api,
fileId,
payload,
onSuccess: _onSuccess,
onProgress: _onProgress,
onError: _onError,
onAbort: _onAbort,
abortMaker,
}) => {
@xettri
xettri / proxy.js
Created April 27, 2024 17:22
Simple nodejs http proxy, works with https and http forwarding
const http = require("http");
const https = require("https");
// Ignore SSL error
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
const createProxyServer = ({ url, headers, responseHeaders } = {}) => {
let forwardUrl;
try {
forwardUrl = new URL(url);
/**
* Uploads a file using XMLHttpRequest with progress, error, and abort handling.
*
* @param {Object} options - The options for the file upload.
* @param {string} options.api - The API endpoint for the file upload.
* @param {File} options.file - The File object to be uploaded.
* @param {string} options.type - The MIME type of the file.
* @param {string} [options.method="PUT"] - The HTTP method for the request.
* @param {function} [options.onProgress] - A callback function to handle upload progress.
* @param {function} [options.onError] - A callback function to handle upload errors.
const webpack = require("webpack");
const { RawSource } = require("webpack-sources");
class DynamicLoadScript {
constructor(options = { filename: "bundle.js" }) {
this.options = options;
}
apply(compiler) {
compiler.hooks.thisCompilation.tap("DynamicLoadScript", (compilation) => {
compilation.hooks.processAssets.tapPromise(
const { deepEqual } = require('assert');
Object.defineProperty(Object.prototype, 'deepEqual', {
writable: false,
enumerable: false,
configurable: false,
value: (a, b) => deepEqual(a, b),
})
// Usage:
{
"extends": [
"react-app",
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"prettier"
],
"plugins": ["react", "import"],
"parserOptions": {
function sumDiagonal(a){
const n = Math.sqrt(a.length);
const op = { d1: 0, d2: 0 };
for(let i = 0; i < n; i++){
op.d1 += a[i + n * i ];
op.d2 += a[n - i - 1 + n * i];
}
return op;
}
const ds = function (p) {
let s = 1;
if (p[0] === '-') {
s = -1;
p = p.substr(1);
}
return function (a, b) {
let r = 0;
if (typeof a[p] === 'string' || typeof b[p] === 'string') {
let _a = String(a[p]);
git filter-branch --env-filter '
WRONG_EMAIL="old-email@example.com"
NEW_NAME="New Name"
NEW_EMAIL="new-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ]
then
export GIT_COMMITTER_NAME="$NEW_NAME"
export GIT_COMMITTER_EMAIL="$NEW_EMAIL"
fi
{
"BD": {
"countryName": "Bangladesh",
"currency": "BDT",
"symbol": "Tk"
},
"BE": {
"countryName": "Belgium",
"currency": "EUR",
"symbol": "€"