Skip to content

Instantly share code, notes, and snippets.

@night-fury-rider
night-fury-rider / design-pattern-pubsub.js
Last active April 22, 2025 12:21
Design Pattern - Pub/Sub
class PubSub {
constructor() {
this.events = {};
}
subscribe(eventName, callback) {
if (!this.events[eventName]) {
this.events[eventName] = [];
}
this.events[eventName].push(callback);
@night-fury-rider
night-fury-rider / jest-render-test-component-using-method.test.ts
Last active February 12, 2025 04:51
jest - Render Test Component using Method
import { Provider } from "react-redux";
import thunk, { ThunkMiddleware } from "redux-thunk";
import { render, RenderAPI } from "react-test-renderer";
import configureMockStore from "redux-mock-store";
import TestComponent from "./TestComponent";
import { describe } from "node:test";
const middlewares: Array<ThunkMiddleware> = [thunk];
const createMockStore = configureMockStore(middlewares);
@night-fury-rider
night-fury-rider / jest-mocking-partial-mock-library-methods-1.test.tsx
Created February 10, 2025 08:49
Jest - Partially Mocking Library Methods 1
import Notifee from "@notifee/react-native";
jest.spyOn(Notifee, "requestpermission");
Notifee.requestPermission.mockImplementation(() => {
throw new Error();
});
@night-fury-rider
night-fury-rider / vscode-windows-keybindings.json
Created January 5, 2025 03:08
Visual Studio Code - Windows - Keyboard Shortcuts Customization.
[
{
"key": "shift+ctrl+f",
"command": "editor.action.formatSelection",
"when": "editorHasDocumentSelectionFormattingProvider && editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+k ctrl+f",
"command": "-editor.action.formatSelection",
"when": "editorHasDocumentSelectionFormattingProvider && editorTextFocus && !editorReadonly"
@night-fury-rider
night-fury-rider / react-component-props-interface.ts
Created December 29, 2024 17:05
Interface for React Component Props
import React from "react";
interface iPieChart {
data: any[];
pieContainerCustomStyles?: React.CSSProperties;
}
const PieChart = ({
data,
@night-fury-rider
night-fury-rider / vscode-mac-keybindings.json
Last active January 5, 2025 03:07
Visual Studio Code - Mac - Keyboard Shortcuts Customization.
// Update `~/Library/Application Support/Code/User/keybindings.json` file for keyboard shortcuts
[
{
"key": "shift+cmd+f",
"command": "editor.action.formatSelection",
"when": "editorHasDocumentSelectionFormattingProvider && editorTextFocus && !editorReadonly"
},
{
"key": "cmd+k cmd+f",
"command": "-editor.action.formatSelection",
@night-fury-rider
night-fury-rider / vscode-settings.json
Last active December 30, 2024 06:18
Visual Studio Code - Settings
{
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"diffEditor.ignoreTrimWhitespace": false,
@night-fury-rider
night-fury-rider / jest-mocking-partial-mock-own-methods-2.test.tsx
Created September 11, 2024 18:05
Jest - Partially Mocking Own Methods 2
jest.mock(“$dashboard/Contact service", ()=> ({
_esModule: true,
default: ()=> ({
getDashboardData: jest.fn()
})
@night-fury-rider
night-fury-rider / react-native-component-props-interface.ts
Created July 4, 2024 05:53
Interface for React Native Component Props
import {StyleProp, ViewStyle} from 'react-native';
interface IInputProps {
inputValue: string | number;
handleChange?: (updatedValue: string) => void;
inputLabel?: string;
customStyle?: StyleProp<ViewStyle>;
}
export type {IInputProps};
@night-fury-rider
night-fury-rider / rare-contacts-screenshot-data.json
Created June 14, 2024 17:59
Rare Contacts Screenshot Data
[
{
"id": "dadawa-dagdhwaj",
"displayName": "Arya Stark",
"jobTitle": "Warrior",
"contactStr": "",
"imageBase64Path": "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wgARCAEAAQADASIAAhEBAxEB/8QAGwAAAQUBAQAAAAAAAAAAAAAAAAECAwQFBgf/xAAZAQEBAQEBAQAAAAAAAAAAAAAAAQIDBAX/2gAMAwEAAhADEAAAAfKgAACeKxvLGrLZDK6SyokyTULXGK2Vsiyb/O2ZrUz235rIfdhWpDerswituYxzUAAAAAACSVk/TCPRmsvVjJQLCVHXSapt1bGemMnVWMdOPi9K1MvIZe54TWdGrDuTeHW0a15wMe25QAAAABzX2Pngl3lkiNRrFizu7cgt9/M981ydDqcnpfP6rVtLfLcMN2HNyec6ujnfkOhe57vwv1rdUr171TWIwEAAACaGbUc5j9Zs15qljGkvPd2eOf0+W3pVNbn3s7ePteb161ita56ssnVjOh06vPfJeVe2eWdFWk9nbjJVliuYxUQAAAWSN2o5zVsmrSRQl6lY1nVt5V7v5dW9iv5ejptrluo8/r0refZ570pcepcb9TjuXX0bzufIbwJGr14QjkZYioAAACvjksVVi1Bo7NLddms6FTRqbxUOnz86pdrw/bc+vVcp23Cc+/Nt6el145/X8k2XpeOj6PO+bbLV1zuRPqkaAyAAACoVNE51kTkIvNdc9Hmq21drNtZW655ffcJ6R4/odNTuQefvn529zfS5eD0vRaz