Skip to content

Instantly share code, notes, and snippets.

@rohangeorge91
rohangeorge91 / packageUpgrade.js
Created December 28, 2022 06:10
A nodejs script to read and upgrade all dependencies (please check if the project works properly after this since this might break peer dependencies)
const fs = require('fs/promises')
const { execSync } = require('node:child_process')
const readJsonFile = async (filepath, encoding = 'utf8') =>
JSON.parse(await fs.readFile(filepath, { encoding }))
const upgradePackage = (dependency, type = 'non-dev') => {
const addFlags = type === 'non-dev' ? '' : ' --dev'
execSync(`yarn remove ${dependency}`);
execSync(`yarn add ${dependency}${addFlags}`);
@rohangeorge91
rohangeorge91 / dayOfWeek.js
Created February 7, 2022 06:37
An interesting way to store 2 days of the week in a 64 bits.
// lookup <- one time cost
let dict = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
// gives the two days based on the number
const getDay = (num) => ([(num % 7), (num / (7 - (num % 7)))]).map((val) => dict[val]);
// based on the days as mentioned above
const getNum = (arr) => [1]
.concat(arr.map((val) => dict.lastIndexOf(val)))
.reduce((acc, val) => (acc * val));