Skip to content

Instantly share code, notes, and snippets.

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

Аневризма aneurysmjs

💭
асинхорнный
View GitHub Profile
@aneurysmjs
aneurysmjs / someHook.tsx
Last active May 9, 2024 11:56
some considerations when using useEffect
useEffect(() => {
// componentDidMount ?
}, []);
useEffect(() => {
// componentDidUpdate ?
}, [foo, bar]);
useEffect(() => {
return () => {
@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.
*/
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,
@aneurysmjs
aneurysmjs / conditionals.sh
Last active July 23, 2023 11:38
some basic bash
num=10
# -eq equals
# -ne not equal
# -gt greather than
# -ge greather than or equal
# -lt less than
# -le less than or equal
if [ $num -eq 10]
@aneurysmjs
aneurysmjs / git-tricks.md
Last active July 6, 2023 09:00
git tricks

ignore files temporarily

start ignoring changes to a file:

git update-index --assume-unchanged path/to/file

keep tracking again:

git update-index --no-assume-unchanged path/to/file

see here

get a list of files marked --assume-unchanged:

git ls-files -v | grep '^[[:lower:]]'

/**
<template>
<div id="foo" @click="handleClick">Yo!</div>
</template>
*/
import {
createElementVNode as _createElementVNode,
openBlock as _openBlock,
createElementBlock as _createElementBlock,
@aneurysmjs
aneurysmjs / scope.js
Last active February 10, 2023 09:42
practical use of 'var' statement
/*
* @desc closure in loops
*/
// the problem here, is we're thinking we're getting
// a new 'i' for each iteration, so at the end it only
// prints 6, because 'i' is 6 at the end of the loop and
// the timers runs after so it'll print 6.
for (var i = 0; i <= 5; i += 1) {
setTimeout(function () {
@aneurysmjs
aneurysmjs / jscodeshift-scope-methods.js
Last active December 18, 2022 22:07
Jscodeshift's scope methods
// getScope() is a method provided by jscodeshift that can be used to get the Scope object for a given Node.
// A Scope object represents the lexical scope of a node in the abstract syntax tree (AST).
// It contains information about the variables, functions, and other declarations that are in scope at a given point in the code.
// Here's an example of how getScope() can be used:
import { getScope } from 'jscodeshift';
const source = `
function foo() {
@aneurysmjs
aneurysmjs / generics.rs
Last active November 10, 2022 00:12
Generics in Rust
struct Point<T, U> {
x: T,
y: U,
}
impl<T, U> Point<T, U> {
// Methods that use different generic types than their struct’s definition
fn mixup<V, W>(self, other: Point<V, W>) -> Point<T, W> {
Point {
x: self.x,
@aneurysmjs
aneurysmjs / rust_cheat_sheet.rs
Created November 9, 2022 15:49
Rust cheatsheet
// represents the `possible` absence of a value
enum Option<T> {
Some(T),
None,
}
let email: Option<String> = Some(email_str);
let email: Option<String> = None;
// representsan operation that could have failed