Skip to content

Instantly share code, notes, and snippets.

View anushshukla's full-sized avatar
💭
Silently and secretly building awesome applications

Anush Shukla anushshukla

💭
Silently and secretly building awesome applications
View GitHub Profile
@anushshukla
anushshukla / helpful-prototypes.js
Created November 13, 2018 17:01
Helpful Prototypes #js
Element.prototype.getAncestorByClassName = function(className){
var el = this;
while ((el = el.parentNode)) {
if(typeof el.className === "string" && el.className.match(className)) {
return el;
}
}
}
@anushshukla
anushshukla / react-setup.sh
Created December 1, 2018 10:04
Installs node (nvm automatically) and yarn
## Ypdating Yarn repositories
curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
## Ypdating Yarn repositories
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
## Updating apt with updated repositories
sudo apt-get update
import React, { Suspense, lazy } from 'react';
const DefaultSpinner = () => null;
export default (dynamicImport, Spinner) => {
const Component = lazy(dynamicImport);
return props => (
<Suspense fallback={Spinner ? <Spinner /> : <DefaultSpinner />}>
<Component {...props} />
</Suspense>
import React from 'react';
export default dynamicImport =>
class MockAsyncComponent extends React.Component {
state = { Component: null };
componentDidMount = () => dynamicImport.then(({ default: Component }) => this.setState({ Component })).error(error => null);
render = () => {
const { Component } = this.state;
console.error(Component);
return <Component {...this.props} />;
@anushshukla
anushshukla / palindromeCheck.js
Created May 21, 2019 01:41
Check if string is palindrome if 1 or 2 characters can be removed from anywhere
const handlePrintAfterCharRemoval = (result, char) => {
switch (result) {
case 'palindrome': return char;
case 'not possible': return result;
default :
if (result.length === 1) {
return `${result}${char}`;
}
return ''; // implies that function should continue to try other ways to check the plaindrome
@anushshukla
anushshukla / lis.js
Created June 2, 2019 20:35
Longest Whole Number Integer Sequence regardless of continuity.
function LongestIncreasingSequence(arrayOfNaturaNumbers) {
let lis = 1;
let lastNumber;
const totalNumbers = arrayOfNaturaNumbers.length;
let internalLoop = totalNumbers - 1;
const lisFound = lis > lis;
const sequenceRecords = [];
for (let index = 0; index < totalNumbers - 1 && !lisFound; index++) {
// if (index > 0) break; // testing
const currNumber = arrayOfNaturaNumbers[index];
@anushshukla
anushshukla / isPalindrome.php
Last active June 2, 2019 22:14
Check if string is palindrome (case insensitive)
<?php
// Complexity: O(n/2)
function isPalindrome($str) {
$array = str_split($str);
$arrayLen = sizeof($array) - 1;
foreach ($array as $index => $currChar) {
$indexFromBehind = $arrayLen - $index;
$charFromBehind = $array[$indexFromBehind];
$charFromBehindLowerCase = strtolower($charFromBehind);
$currCharLowserCase = strtolower($currChar);
@anushshukla
anushshukla / getLongestRepeatedSubStrings.php
Last active June 7, 2019 01:26
Get Longest Repeated Sub String
<?php
function getLongestRepeatedString($array, $prevStartIndex = 0, $prevEndIndex = 0, $repeatOf = 2, $longestMatchFound = 0, $longestRepeatString = '') {
$matchCount = 0;
$startIndex;
$endIndex = $prevEndIndex ?: $repeatOf - 1;
$consecutiveMatchCount = 0;
$prevLongestRepeatString = $longestRepeatString;
if ($longestRepeatString) $longestRepeatString .= ', ';
// var_dump("=========================");
@anushshukla
anushshukla / getAppearanceCount.php
Created June 6, 2019 06:18
Get Appearance Count
<?php
function appearanceCount($str1len, $str2len, $str1, $str2)
{
$matches = $chunk = $i = 0;
$str1len = strlen($str1);
$str2len = strlen($str2);
for($i; $i <= $str2len; $i++ ) {
if(isset($matched)) {
$chunk = $matched === 4 ? $chunk + 1 : $chunk + $matched;
}
@anushshukla
anushshukla / getJumpAttempts.php
Created June 6, 2019 06:21
Get Jump Attempts
<?php
function getJumpAttempts($maxJump,$slipsBy,$wallHeights)
{
$attempts = 0;
foreach($wallHeights as $wallHeight) {
$attempts++;
do {
if($wallHeight > $maxJump) {
$wallHeight -= $maxJump - $slipsBy;