Skip to content

Instantly share code, notes, and snippets.

@tkrotoff
tkrotoff / FrontendFrameworksPopularity.md
Last active April 24, 2024 16:27
Front-end frameworks popularity (React, Vue, Angular and Svelte)
@tkrotoff
tkrotoff / #deepFreeze.ts
Last active April 18, 2024 08:44
Deeply freezes an object
import { ReadonlyDeep } from 'type-fest';
/**
* Deeply freezes an object by recursively freezing all of its properties.
*
* - https://gist.github.com/tkrotoff/e997cd6ff8d6cf6e51e6bb6146407fc3
* - https://stackoverflow.com/a/69656011
*
* FIXME Should be part of Lodash: https://github.com/Maggi64/moderndash/issues/139
*
@tkrotoff
tkrotoff / #calculator.ts
Last active April 9, 2024 14:45
Calculator function using shunting yard algorithm and reverse Polish notation (RPN)
// https://gist.github.com/tkrotoff/b0b1d39da340f5fc6c5e2a79a8b6cec0
// WTF!
// parseFloat('-0') => -0 vs parseFloat(-0) => 0
// -0 === 0 => true vs Object.is(-0, 0) => false
const minus0Hack = (value: number) => (Object.is(value, -0) ? '-0' : value);
export const operators: {
[operator: string]:
| {
@tkrotoff
tkrotoff / #getRandomNumber.ts
Last active April 9, 2024 14:39
getRandomInt() & getRandomFloat()
// https://gist.github.com/tkrotoff/f3f36926edeeb3f4ce4411151bde37b2
// Exported for testing purposes only
// https://stackoverflow.com/a/45736131
export function getNumberWithDecimalPlaces(num: number, decimalPlaces: number) {
const power = 10 ** decimalPlaces;
return Math.floor(num * power) / power;
}
type GetRandomNumberOptions = {
@tkrotoff
tkrotoff / RemoveWin10DefaultApps.ps1
Last active April 6, 2024 01:52
Remove Windows 10 default apps
# See Remove default Apps from Windows 10 https://thomas.vanhoutte.be/miniblog/delete-windows-10-apps/
# See Debloat Windows 10 https://github.com/W4RH4WK/Debloat-Windows-10
# Command line to list all packages: Get-AppxPackage -AllUsers | Select Name, PackageFullName
Get-AppxPackage Microsoft.Windows.ParentalControls | Remove-AppxPackage
Get-AppxPackage Windows.ContactSupport | Remove-AppxPackage
Get-AppxPackage Microsoft.Xbox* | Remove-AppxPackage
Get-AppxPackage microsoft.windowscommunicationsapps | Remove-AppxPackage # Mail and Calendar
#Get-AppxPackage Microsoft.Windows.Photos | Remove-AppxPackage
Get-AppxPackage Microsoft.WindowsCamera | Remove-AppxPackage
@tkrotoff
tkrotoff / CSSFrameworks.md
Last active March 18, 2024 04:26
CSS Frameworks (Bootstrap, Tailwind CSS, Bulma, React Bootstrap, Chakra UI, Ant Design)

The right question is: is there added value in reinventing the wheel? (button, form controls, badge, card, spinner, modal...). The existing wheels will probably ride better than yours.

I would go with vanilla Bootstrap (just the Sass part, not the JS part).

Bootstrap

Bootstrap CSS utilities are very nice: same principles as Tailwind CSS.

@tkrotoff
tkrotoff / #mockWindowLocation.ts
Last active March 14, 2024 16:39
Jest/Vitest mocks for JSDOM window.location & window.history
/* eslint-disable unicorn/no-null */
/*
* Resetting window.location between tests is unfortunately a hard topic with JSDOM.
*
* https://gist.github.com/tkrotoff/52f4a29e919445d6e97f9a9e44ada449
*
* FIXME JSDOM leaves the history in place after every test, so the history will be dirty.
* Also its implementations for window.location and window.history are lacking.
* - https://github.com/jsdom/jsdom/blob/22.1.0/lib/jsdom/living/window/Location-impl.js
@tkrotoff
tkrotoff / ReactNative-vs-Flutter.md
Last active February 27, 2024 15:40
React Native vs Flutter
@tkrotoff
tkrotoff / git-staged-warn-binaries.sh
Last active August 10, 2023 08:51
Warns about Git staged binary files
#!/usr/bin/env sh
# Warns about Git staged binary files
# https://gist.github.com/tkrotoff/dc49a8e501b6fdea5a4b66301f7682fc
# Capture the output of "git diff" in a temporary file
tmpfile=$(mktemp)
# https://stackoverflow.com/q/28109520
git diff -z --staged --name-only --diff-filter=ACMR > "$tmpfile"
@tkrotoff
tkrotoff / #assert.ts
Last active August 3, 2023 23:13
TypeScript friendly assert
/**
* Writes an error message to the console if the assertion is false.
*
* If the assertion is true, nothing happens.
*
* If your code only runs in Node.js, prefer `import { strict as assert } from 'node:assert'`
* because it throws.
*
* https://gist.github.com/tkrotoff/1a216f376cb4fba5bc7d8b5109c3a32e
* https://devblogs.microsoft.com/typescript/announcing-typescript-3-7/#assertion-functions