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 / eight-queens-attack-check.js
Last active December 30, 2020 09:53
Eight Queens Attack Check
const getParsedQueenPosition = queenPosition => queenPosition.replace('(', '').replace(')', '').split(',');
const getDiagnolAttackPositions = ({ position: queenPosition, rowIncrement, colIncrement }) => {
const diagnolAttackPositions = {}
const position = getParsedQueenPosition(queenPosition);
const reviseRowPosition = currPosition => parseInt(currPosition) + (rowIncrement ? 1 : -1)
const reviseColPosition = currPosition => parseInt(currPosition) + (colIncrement ? 1 : -1)
let nextRowPosition = reviseRowPosition(position[0]);
let nextColPosition = reviseColPosition(position[1]);
isValidPosition = (rowPosition, colPosition) => {
@anushshukla
anushshukla / array-find-highest-number.js
Last active November 12, 2020 21:16
Find Highest Number in an Array of Numbers
const numbersList = [3, 6, 2, 99, 32, 5, 89, 32];
Array.prototype.findHighestNumber = function(currentIndex = 1, lastHighestNumber = this[0]) {
const currentNumber = this[currentIndex];
lastHighestNumber = lastHighestNumber > currentNumber ? lastHighestNumber : currentNumber;
if (currentIndex === this.length - 1) {
return lastHighestNumber;
}
const nextIndex = currentIndex + 1;
return this.findHighestNumber(nextIndex, lastHighestNumber);
}
@anushshukla
anushshukla / chocolate-wrapper-puzzle.js
Last active November 10, 2020 21:59
Find the maximum number of chocolates as per the price of a chocolate and exchange offer of wrappers for a chocolate
const getChocolates = (amount, price) => Math.floor(amount/price);
const getChocolatesExchangedCount = (chocolates, wrapperExchangeRate, totalExchangedChocolates = 0) => {
const exchangedChocolates = Math.floor(chocolates/wrapperExchangeRate);
const remainingChocolates = chocolates%wrapperExchangeRate;
const totalRemainingChocolates = exchangedChocolates + remainingChocolates
totalExchangedChocolates += exchangedChocolates;
if (totalRemainingChocolates < wrapperExchangeRate) {
return totalExchangedChocolates;
}
@anushshukla
anushshukla / getHighestRepeatingChar.js
Last active November 10, 2020 20:56
Get the most occurring character in a string
String.prototype.getHighestRepeatingChar = function() {
const charCountHash = {}
let highestOccurence = 0;
let highestRepeatingChar;
for (let charIndex = 0; charIndex < this.length; charIndex++) {
const currentChar = this[charIndex]
const prevCharCount = charCountHash[currentChar] || 0
const currentCharCount = prevCharCount + 1;
charCountHash[currentChar] = currentCharCount;
if (highestOccurence === 0) {
@anushshukla
anushshukla / check-palindrome.js
Last active November 10, 2020 20:09
Palindrome Check
String.prototype.isPalindrome = function(charIndex = 0) {
const stringLength = this.length;
const charIndexFromBehind = stringLength - charIndex - 1;
const isCharSame = this[charIndex] === this[charIndexFromBehind];
if (!isCharSame) {
return false;
}
const isIndexSame = charIndex === charIndexFromBehind;
if (isIndexSame) {
return true;
@anushshukla
anushshukla / fetch-aws-s3-archived-logs.sh
Last active October 26, 2020 19:58
Fetch AWS S3 Archived Logs for debugging
#!/bin/bash
AWS_S3_LS='s3://<your-bucket-name-here/<prefix-optional>'
SYS_DAY=$(date '+%d')
SYS_MONTH=$(date '+%m')
SYS_YEAR=$(date '+%Y')
DEFAULT_TIME_AFTER="00:00:00"
DEFAULT_TIME_BEFORE="23:59:59"
SORT_DATE=true
LOG_TYPE='out'
@anushshukla
anushshukla / aws-s3-api-commands.sh
Created October 21, 2020 15:03
AWS S3 API List Objects Queries
aws s3api list-objects-v2 \
--bucket <bucket-name-here> \
--max-keys=5 \
--query "sort_by(Contents, &LastModified)[*].{Key:Key,Size:Size,LastModified:LastModified}"
--query "reverse(sort_by(Contents,&LastModified))" \
--query "Contents[?contains(Key, '<file-name-here>')]"
--query "Contents[?LastModified>='2020-10-18T17:49:00.000Z'][]" \
--query 'Contents[?LastModified>2020-08-29][].{Key: Key,LastModified: LastModified}'
--query 'Contents[?contains(LastModified, "2020-08-30")].Key'
@anushshukla
anushshukla / file-helper.ts
Created October 18, 2020 10:15
Filer Helper to detect mime via CLI
import { exec as defaultExec } from 'child_process'
import fs from 'fs'
import util from 'util'
import safePromise from './safe-promise'
const exec = util.promisify(defaultExec)
const detectFile = async (filePath: string): Promise<string> => {
// mmmagic avoided due to https://github.com/mscdex/mmmagic/issues/141#issuecomment-570085390
// file-typ avoided due to https://github.com/sindresorhus/file-type#supported-file-types
image: node:10.13.0
stages:
- setup
- lint
- coverage
- deploy
cache:
untracked: true
sudo gitlab-runner register \
--non-interactive \
--url "https://gitlab.com/your-user-name" \
--registration-token "PROJECT_REGISTRATION_TOKEN" \
--executor "ssh" \
--docker-image alpine:latest \
--description "ssh-runner-local-server" \
--tag-list "ci,cd,lint-check,test,coverage" \
--run-untagged="true" \
--locked="false" \