Skip to content

Instantly share code, notes, and snippets.

View aneurysmjs's full-sized avatar
💭
асинхорнный

Аневризма aneurysmjs

💭
асинхорнный
View GitHub Profile
@aneurysmjs
aneurysmjs / iterators.rs
Created September 15, 2024 09:32
Rust iterators
pub struct RectIter {
points: Vec<(f64, f64)>,
idx: usize,
}
impl Iterator for RectIter {
type Item = (f64, f64);
/*
* The reason why is mutable (&mut self), is that the only way to iterate through something,
@aneurysmjs
aneurysmjs / .md
Created September 4, 2024 07:44
Typescript shit

How to Extract The Indexes of Any Array in TypeScript

see

copy relative file to clipboard

To copy the relative path in Vim, you can use the following command:

:let @+=expand("%:.")

Here's how it works:

@aneurysmjs
aneurysmjs / vimmotions.md
Last active September 2, 2024 22:24
vim motions

BASICS

To exit Vim type: <ESC> :q! <ENTER> to trash all changes.
OR type: <ESC> :wq <ENTER> to save the changes.

NORMAL mode

navigation

h left

solve ERR_PNPM_BAD_PM_VERSION

discussion

message

ERR_PNPM_BAD_PM_VERSION  This project is configured to use v9.1.1 of pnpm. Your current pnpm is v9.0.4

If you want to bypass this version check, you can set the "package-manager-strict" configuration to "false" or set the "COREPACK_ENABLE_STRICT" environment variable to "0"

solution

@aneurysmjs
aneurysmjs / playground.vue
Last active May 31, 2024 11:52
some vue stuff
// @see https://play.vuejs.org/#eNqtV19zm0YQ/yoXpjNCEwmlap9UrHHruNNmpnamTtMHoQcMh0QCB4VDtkaj797dvTs4sCwnk/hFsLf7273982N9cH4tS2/XcGfh+HVUpaVkWSg2F4Ej68BhNZdNuQxEmpdFJdmBVTyZsIdQRlv9c50kPJITJvij/JBGnyesqflVXX8Mq5odWVIVORuBg1EgWpi3TZ7vfy+qXB97s1aCsYCqVryVW171FFtJX/EOfjPe0+xEWjUQUSFqyfJ6wy7wIu7oD55lBfu3qLL41WhsKcyNRlIU3UFUNELqkzcgNXLR5LUWC/7A7rh0xx1aWN505yvC8HZh1vC1BZHv/wpLCwPe/FpWqdhAapv8nler9dJdrUZhlo0mbPVmvV6jj0AkjYhkWgi2DUWc8asMiuCO2SEQTAWsnL1+jYLZjIJVIi+MY9dSAThmHUM05jYrz/O6g4mNi5c4YhxhvRcRG0QD1+gF9LL/nsaXh0CGlESNDZ3r6mTpCrROnmprP/BOfmwcLqAKvHbHyssgoyDqoQMQAdiyfqzK/XPO6Qz+TJ17QGCLZ6pt6ArhQ5hC++nRcyHLF8s20Wed0Pk5P6TQZvaID7rQwxIXMc8+op1L1gum+lZXHIapjYB+NQqRh4sVnTArbpyGIuNeVmzcEc1VBG42PMYpxCiMJd3teVM1T09s1bABQ1VvQxnqeSNrlC3YaDTBF56HaYZvxm5w539A+a65z1Ppop26as8/iiGvdErlMj7bZKBA5yIQ/kyRL1AtvEgO1BVKDm+M+dsfl4cDsdbx6M/gDTReTadQHjruyDTHSkwJH/gbDIDAL5syBqRF/2xYOVCcLdl0Sg6V0wokqs+6AOZdBCDuyHk3JfhFvre9zwn1FJqiZoa2HZxF4RoPYEzWXrhJVw/tkxDLSmWQMQj/3d3tjac6M032VDYERnbNsgmbj+FuZDVTZlQITLMJ3t/Ol0BEEPCcUAET+1Nb3TdSQntcRsh2bVzE
@aneurysmjs
aneurysmjs / Foo.tsx
Last active May 9, 2024 08:58
Artificially slow down a component
function Foo() {
const now = performance.now();
/**
* The result of the first performance.now() call (stored in now) is subtracted from the current time.
* This effectively calculates the time elapsed since the loop began.
*
* the loop keeps running as long as it hasn't been a full second since the startTime was captured.
* Once the elapsed time hits or goes above 200ms, the loop condition becomes false, and the loop terminates.
*/
@aneurysmjs
aneurysmjs / someHook.tsx
Last active May 9, 2024 11:56
some considerations when using useEffect
useEffect(() => {
// componentDidMount ?
}, []);
useEffect(() => {
// componentDidUpdate ?
}, [foo, bar]);
useEffect(() => {
return () => {

Debounce:

Debouncing is a technique used to ensure that a function doesn't get called too frequently.

It's commonly employed in scenarios where we want to wait for a pause in user input before triggering an action.

For example, in search bars, debounce delays the execution of the search function until the user has finished typing, preventing unnecessary API requests with each keystroke.

⏱️ Throttling:

describe('useQueryProductById', () => {
afterEach(() => {
jest.clearAllMocks();
});
it('should return a single product', async () => {
const product = {
id: 2,
title: 'Mens Casual Premium Slim Fit T-Shirts ',
price: 22.3,