This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Solution 1 without regex | |
function isLowerAlpha(char) { | |
return /^[a-z]+$/.test(char); | |
} | |
function getWordPos(word, text) { | |
for (var i = 0; i <= text.length - word.length; i++) { | |
if (text.substr(i, word.length) === word) { | |
if (i === 0 || !isLowerAlpha(text.charAt(i - 1))) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
export type ExtendHTMLProps<P extends object = {}> = Merge<React.HTMLAttributes<HTMLElement>, P>; | |
export type Merge<A, B> = Omit<A, keyof B> & B; | |
type ExtendAs<C extends React.ElementType = 'div'> = { | |
as?: C; | |
}; | |
export type PolymorphicExtendedProps< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const uploadFile = ({ | |
api, | |
fileId, | |
payload, | |
onSuccess: _onSuccess, | |
onProgress: _onProgress, | |
onError: _onError, | |
onAbort: _onAbort, | |
abortMaker, | |
}) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { deepEqual } = require('assert'); | |
Object.defineProperty(Object.prototype, 'deepEqual', { | |
writable: false, | |
enumerable: false, | |
configurable: false, | |
value: (a, b) => deepEqual(a, b), | |
}) | |
// Usage: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"extends": [ | |
"react-app", | |
"eslint:recommended", | |
"plugin:react/recommended", | |
"plugin:react-hooks/recommended", | |
"prettier" | |
], | |
"plugins": ["react", "import"], | |
"parserOptions": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
NewerOlder