Skip to content

Instantly share code, notes, and snippets.

View zehan12's full-sized avatar
:electron:
Focusing

Zehan Khan zehan12

:electron:
Focusing
View GitHub Profile
class Notification {
constructor(service) {
this.service = service;
}
notify(message) {
this.service.send(message);
}
}
class DeliveryService {
deliverOrder() {
console.log("Delivering order...");
}
}
class PaymentService {
processPayment() {
console.log("Processing payment...");
}
class Notification {
send(message) {
console.log(`Sending notification: ${message}`);
}
}
class EmailNotification extends Notification {
send(message) {
console.log(`Sending email: ${message}`);
}
class Payment {
constructor(strategy) {
this.strategy = strategy;
}
pay(amount) {
this.strategy.processPayment(amount);
}
}
class User {
constructor(name) {
this.name = name;
}
}
class UserRepository {
save(user) {
console.log(`Saving ${user.name} to the database.`);
}
import { useSelector, useDispatch } from "react-redux";
function MyReduxComponent() {
const count = useSelector((state) => state.counter);
const dispatch = useDispatch();
return (
<div>
<p>Count: {count}</p>
<button onClick={() => dispatch({ type: "INCREMENT" })}>Increment</button>
import React, { useEffect } from "react";
function MyComponent() {
useEffect(() => {
// Set up some side effect here, such as an event listener
window.addEventListener("resize", handleResize);
// Cleanup when the component unmounts
return () => {
window.removeEventListener("resize", handleResize);
import React, { useEffect, useState } from "react";
function MyComponent() {
const [count, setCount] = useState(0);
useEffect(() => {
// This is similar to componentDidUpdate
console.log(`Component updated, current count: ${count}`);
// Conditionally trigger updates to avoid infinite loops
import React, { useEffect, useState } from "react";
function MyComponent() {
const [data, setData] = useState(null);
useEffect(() => {
// This is similar to componentDidMount
console.log("Component mounted");
// API call
@zehan12
zehan12 / alphabet150.md
Created February 20, 2024 19:45 — forked from kamui-fin/alphabet150.md
An archive of the interview and system design playlists from alphabet150.com