Skip to content

Instantly share code, notes, and snippets.

View myildizCH's full-sized avatar
🚀

Mehmet Yildiz myildizCH

🚀
View GitHub Profile
@myildizCH
myildizCH / observer-pattern.ts
Last active August 8, 2023 09:54
Observer Pattern
// Observer Interface
interface Observer {
update(steps: number, heartRate: number, sleep: number): void;
}
// Subject Interface
interface Subject {
registerObserver(observer: Observer): void;
removeObserver(observer: Observer): void;
notifyObservers(): void;
@myildizCH
myildizCH / decorator-pattern.ts
Created July 26, 2023 19:35
Decorator Pattern
// Step 1: Create the Component Interface
interface Coffee {
cost(): number;
description(): string;
}
// Step 2: Implement the Component Interface
class SimpleCoffee implements Coffee {
cost(): number {
return 1;
@myildizCH
myildizCH / adapter-pattern.ts
Created July 25, 2023 15:47
Adapter Pattern TypeScript
// Step 1: Define the Interface our System Expects
interface IMessageClient {
sendMessage(channel: string, user: string, message: string): void;
}
// Step 2: Implement Slack Client (Adaptee)
class SlackClient {
postMessageToUserInChannel(channel: string, user: string, message: string) {
console.log(`Posting message to ${user} in ${channel} through Slack: ${message}`);
}
@myildizCH
myildizCH / builder-pattern.ts
Created July 19, 2023 19:01
Builder Pattern
// Step 1: Create the Product Class
class GameCharacter {
name?: string;
class?: string;
weapon?: string;
armor?: string;
// ... any other game character attributes
describe() {
@myildizCH
myildizCH / prototype-pattern.ts
Created July 16, 2023 16:32
Prototype Pattern
// Step 1: Create a Prototype
// Create a Cloneable interface
interface Cloneable {
clone(): Cloneable;
}
// Create a GameObject class that implements Cloneable
class GameObject implements Cloneable {
constructor(private sprite: string, private position: number) {}
@myildizCH
myildizCH / facade-pattern.ts
Created July 16, 2023 08:36
Facade Pattern
// Step 1: Define the Subsystem Interfaces and Implementation
// Define interfaces
interface LightSystem {
turnOn(): void;
turnOff(): void;
}
interface SecuritySystem {
arm(): void;
@myildizCH
myildizCH / factory-pattern.ts
Created July 7, 2023 20:01
factory-pattern-typescript
// Step 1: Define the Product Interface
interface Car {
model: string;
drive(): void;
}
// Step 2: Implement Concrete Products
class Tesla implements Car {
model = "Tesla";
@myildizCH
myildizCH / parse-environment-variables-with-zod.ts
Created January 17, 2023 11:43
Parsing environment variables using zod
// env.ts
import { z } from 'zod';
const envVariables = z.object({
DATABASE_URL: z.string();
})
envVariables.parse(process.env);
@myildizCH
myildizCH / transform.interceptor.ts
Created January 15, 2023 20:11
transform.interceptor.ts
import {
NestInterceptor,
ExecutionContext,
Injectable,
CallHandler,
} from '@nestjs/common';
import { classToPlain } from 'class-transformer';
import { map } from 'rxjs/operators';
@Injectable()
@myildizCH
myildizCH / database-normalization.md
Created January 15, 2023 16:06
Database Normalization

First Normal Form (INF)

  1. Using row order to convey information is not permitted.
  2. Mixing data types within the same column is not permitted.
  3. Having a table without a primary key is not permitted.
  4. Repeating groups are not permitted.

Second Normal Form (2NF)

Each non-key attribute in the table must be dependent on the entire primary key.

Third Normal Form (3NF)

Each non-key attribute in the table must depend on the key, the whole key, and nothing but the key.

Boyce-Codd Normal Form (BCNF)