Skip to content

Instantly share code, notes, and snippets.

@mustafadalga
mustafadalga / cancelLinkedinOldInvitations.js
Created January 6, 2025 09:56
Linkedin Cancel All Old Invitations
async function cancelOldInvitations() {
const list = document.querySelectorAll(".invitation-card.artdeco-list__item");
const old = [
"Sent 1 months ago", "Sent 2 months ago", "Sent 3 weeks ago",
"Sent 2 weeks ago",
"Sent 3 months ago", "Sent 4 months ago", "Sent 5 months ago"
];
for (let row of [...list]) {
@mustafadalga
mustafadalga / createStore.ts
Created November 10, 2024 16:03
Building a Custom JavaScript State Management Library Inspired by Zustand
interface User {
_id: string;
name: string;
}
interface State {
users: User[];
addUser: (user: User) => void;
@mustafadalga
mustafadalga / App.tsx
Created April 1, 2024 20:35
Modal Transition Effect in React.js
import { lazy, Suspense, useEffect } from "react";
import useModalStore from "@/hooks/useModalStore.ts";
const Modal = lazy(() => import("@/components/Modal.tsx"))
function Loading() {
return <h2>🌀 Loading...</h2>;
}
function App() {
@mustafadalga
mustafadalga / memo.ts
Created March 31, 2024 16:10
Custom Memoization Function in JavaScript
/**
* This Gist demonstrates a simple yet effective implementation of a memoization function in JavaScript.
* Memoization is an optimization technique used to speed up computer programs by storing the results of expensive function
* calls and returning the cached result when the same inputs occur again.
*/
const memoMap = new Map();
const complexFunction = (a1: number[], a2: number[]): number => {
// Simulate heavy calculations
@mustafadalga
mustafadalga / App.vue
Created March 17, 2024 09:55
Modal Slide In / Up Animation with Transition in vue.js 3
<template>
<div class="app">
<button @click="store.mutations.open()">Open Modal </button>
<Modal v-if="store.state.isModalOpen"/>
</div>
</template>
<script setup>
import store from "./store";
import Modal from "./Modal.vue";
@mustafadalga
mustafadalga / App.vue
Last active March 17, 2024 09:56
Modal Fade In / Fade Out Animation with Transition in vue.js 3
<template>
<div class="app">
<button @click="store.mutations.open()">Open Modal </button>
<Modal v-if="store.state.isModalOpen"/>
</div>
</template>
<script setup>
import store from "./store";
import Modal from "./Modal.vue";
@mustafadalga
mustafadalga / store.ts
Created January 8, 2024 10:36
Unit Testing Vue.js Composables: Verifying Vuex Store Interaction and Reactive Behavior in useCheckUserPosts
import { createStore } from "vuex";
import type { Post } from "@/types";
export interface ApisLoadState {
isCalled: boolean;
isLoaded: boolean;
}
export interface ApiLoadState extends ApisLoadState {
api: string;
@mustafadalga
mustafadalga / amplitude.d.ts
Last active December 17, 2023 14:35
Amplitude Type Declaration
declare global {
interface AmplitudeInstance {
logEvent(eventName: string, eventProperties?: object): void;
identify(identifyObject: object): void;
setUserId(userId: string | null): void;
init(apiKey: string, userId?: string, options?: object, callback?: () => void): void;
}
interface Amplitude {
getInstance(): AmplitudeInstance;
@mustafadalga
mustafadalga / useFetchPosts.test.ts
Created November 18, 2023 11:17
Unit Testing React Hooks with MSW, Vitest, and Testing Library: Fetching and Updating Posts
import { expect, describe, it, beforeAll, afterEach, afterAll, beforeEach } from "vitest";
import { QueryClientProvider } from "react-query";
import { ReactNode } from "react";
import { http, HttpResponse } from "msw";
import { useCommonStore } from "@/_store/useCommonStore";
import { act, renderHook, waitFor } from "@testing-library/react";
import { createTestServer, queryClient } from "@/__tests__/utilities";
import useFetchCustomVariables from "@/_hooks/useFetchCustomVariables";
const successResponse = [
@mustafadalga
mustafadalga / useDeepCompareMemoize.test.ts
Created November 18, 2023 09:24
Unit Tests for useDeepCompareMemoize: Testing Deep Comparison React Hook with Vitest and Testing Library
import { describe, it, expect } from "vitest";
import { renderHook } from "@testing-library/react";
import useDeepCompareMemoize from "./useDeepCompareMemoize";
describe("useDeepCompareMemoize", () => {
it('should return a memoized version of the input value based on deep comparison', () => {
const initialData = { user: { name: 'John', age: 25, city: 'New York' } };
const newData = { user: { name: 'Alice', age: 30, city: 'San Francisco' } };
const identicalData = { user: { name: 'John', age: 25, city: 'New York' } };