Skip to content

Instantly share code, notes, and snippets.

View davidcsejtei's full-sized avatar

Dávid Csejtei davidcsejtei

  • CEO & Co-Founder of Amicode Expert Kft.
  • Hungary
View GitHub Profile
class LRUCache {
constructor(capacity) {
this.capacity = capacity
this.cache = new Map()
}
get(key) {
if (this.cache.has(key)) {
// If the key exists in the cache, move it to the front
const value = this.cache.get(key)
@davidcsejtei
davidcsejtei / angular-theory.md
Created October 4, 2023 14:19
Interview pack

1. What is Angular?

Angular is a platform and framework for building client-side applications with HTML, CSS, and JavaScript/TypeScript. It's particularly suited for building single-page applications (SPAs). Angular provides developers with tools and design patterns to build and scale complex applications. It's maintained by Google and a community of individuals and corporations.

2. What is TypeScript?

TypeScript is a superset of JavaScript developed by Microsoft. It introduces static types, classes, interfaces, and other Object-Oriented Programming (OOP) features to the language. When TypeScript code is compiled, it is translated into plain JavaScript code, making it compatible with any browser. TypeScript enhances the development experience by catching errors early through a robust type system.

3. What is the difference between constructor and ngOnInit?

@davidcsejtei
davidcsejtei / readme.md
Created September 15, 2023 07:21
Add ESLint and Prettier to an existing Angular project

GOAL

if you save a file in your project, the IDE should "autoformat" the file following a given ruleset (ESLint and Prettier configurations).

Example of adding semicolons on save:

Example using ESLint and Prettier

STEPS

package com.holnor.moviedatabase.controller;
import com.holnor.moviedatabase.dto.CreateMovieCommand;
import com.holnor.moviedatabase.dto.MovieDetailsItem;
import com.holnor.moviedatabase.dto.MovieListItem;
import com.holnor.moviedatabase.service.MovieService;
import jakarta.validation.Valid;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@davidcsejtei
davidcsejtei / cores
Created February 7, 2023 21:02
Get Mac number of CPU cores
sysctl -n hw.ncpu
@davidcsejtei
davidcsejtei / remove.sh
Created July 5, 2022 08:05
Remove untraced git files and folders from local repo
# shows what would be removed, but not removing anything
git clean -d -n
# removes files and folders
git clean -d -f
@davidcsejtei
davidcsejtei / deleteSheet.js
Created June 28, 2022 08:58
Delete a selected worksheet (or tab) from an excel file in Node.js
const xlsx = require('xlsx');
const deleteWorksheet = (filePath, workSheetName) => {
const workBook = xlsx.readFile(filePath);
const workSheetNames = Object.keys(workBook.Sheets);
if (workSheetNames.includes(workSheetName)) {
delete workBook.Sheets[workSheetName];
delete workBook.SheetNames[workSheetName];
indexToDelete = workBook.SheetNames.indexOf(workSheetName);
@davidcsejtei
davidcsejtei / squash.sh
Created December 13, 2021 09:08
Squash commits into one
```
git checkout feature/TICKET-123
git merge master
git reset master
git add .
git commit -m "TICKET-123 add something"
git push -f origin feature/TICKET-123
```
@davidcsejtei
davidcsejtei / GetAllUsers.ts
Created June 18, 2021 10:14
GetAllUsers endpoint and test
import { Request, Response } from "express";
import { findAllUsers } from "../services/userService";
export default function getAllUsers(request: Request, response: Response) {
const users = findAllUsers();
response.statusCode = 200;
response.send().json({ users });
}
@davidcsejtei
davidcsejtei / getAllUsers.spec.ts
Created May 26, 2021 18:21
Test private class method with Jest
import { Request, Response } from 'express';
import GetAllUsers from './getAllUsers';
describe('Get all users request', () => {
let mockRequest: Partial<Request>;
let mockResponse: Partial<Response>;
let responseObject = {};
beforeEach(() => {
mockRequest = {