Skip to content

Instantly share code, notes, and snippets.

@tkrotoff
tkrotoff / #assert.ts
Last active May 10, 2024 13:43
TypeScript friendly assert
/**
* Writes an error message to the console if the assertion is false.
*
* If the assertion is true, nothing happens.
* This is similar to React invariant: https://github.com/zertosh/invariant
*
* If your code only runs in Node.js, prefer `import { strict as assert } from 'node:assert'`
* because it throws.
*
* What is an assertion?
@tkrotoff
tkrotoff / #RouterProgressBar.tsx
Last active May 14, 2023 22:55
Progress bar like NProgress in 90 lines of code (vs NProgress v0.2.0 is 470 lines .js + 70 lines .css)
import { useRouter } from 'next/router';
import { useEffect } from 'react';
import { useProgressBar } from './useProgressBar';
// https://github.com/twbs/bootstrap/blob/v5.3.0-alpha1/scss/_variables.scss#L1529
const transitionSpeed = 600;
// https://gist.github.com/tkrotoff/db8a8106cc93ae797ea968d78ea28047
// https://stackoverflow.com/q/60755316
@tkrotoff
tkrotoff / #calculator.ts
Last active February 20, 2025 14:03
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 / #wait.ts
Last active June 18, 2023 08:47
Cancelable await wait()
// https://gist.github.com/tkrotoff/c6dd1cabf5570906724097c6e3f65a12
// https://stackoverflow.com/a/67911932
export function wait(ms: number, options: { signal?: AbortSignal } = {}) {
const { signal } = options;
return new Promise<void>((resolve, reject) => {
// FIXME Not supported by Jest 29.3.1 + Node.js 19.3.0
//signal?.throwIfAborted();
if (signal?.aborted) reject(signal.reason);
@tkrotoff
tkrotoff / ReactNative-vs-Flutter.md
Last active April 2, 2025 00:46
React Native vs Flutter
@tkrotoff
tkrotoff / MinimalHTML5.md
Last active May 26, 2021 10:49
Minimal HTML5 structure
<!DOCTYPE html><title>Hello, World!</title>
  • doctype is mandatory
  • title is mandatory
  • head is not
  • body is not

Verified with https://validator.w3.org/

@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 / HowToTest.md
Last active January 29, 2021 22:19
How I structure my tests

File structure

  • src/fooBar.js
  • src/fooBar.html
  • src/fooBar.scss
  • src/fooBar....
  • src/fooBar.test.js => npm run test
  • src/fooBar.test.e2e.js (if I have E2E tests - Puppeteer, Playwright...) => npm run test:e2e

Tests should not be separated from the source code (think autonomous modules).

@tkrotoff
tkrotoff / FrontendFrameworksPopularity.md
Last active March 30, 2025 15:37
Front-end frameworks popularity (React, Vue, Angular and Svelte)
@tkrotoff
tkrotoff / RemoveWin10DefaultApps.ps1
Last active February 18, 2025 12:10
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