Skip to content

Instantly share code, notes, and snippets.

View munkacsitomi's full-sized avatar

Tamás Munkácsi munkacsitomi

  • Amsterdam, Netherlands
View GitHub Profile
@munkacsitomi
munkacsitomi / iife.js
Last active February 16, 2018 13:27
Self-Executing Anonymous Function / IIFE
// IIFE in ES5
(function() {
console.log('IIFE ES5');
})()
// IIFE in ES6
(() => {
console.log('IIFE ES6');
})()
@munkacsitomi
munkacsitomi / index.html
Last active February 16, 2018 14:11
Responsive Design Basics
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
</head>
@munkacsitomi
munkacsitomi / app.component.ts
Last active March 1, 2020 15:55
Angular RxJS BehaviorSubject
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: `
<app-parent></app-parent>
<app-unrelated></app-unrelated>
`,
styles: []
})
@munkacsitomi
munkacsitomi / user.component.ts
Last active October 25, 2018 17:38
Angular UserComponent Example
export class UserComponent implements OnInit {
users: User[];
constructor(private userService: UserService) {}
ngOnInit() {
this.userService.getUsers().subscribe((users: User[]) => this.users = users);
}
userCreated(user: User) {
Abstraction: objects, classes, and variables
Encapsulation: private, public, protected
Inheritance: new classes share some of the attributes of existing classes (parent, child class, extends)
Polymorphism: method overloading, method overriding
S: Single Responsibility Principle
- A class should have only one job.
O: Open-Closed Principle
- Software entities (Classes, modules, functions) should be open for extension, not modification.
L: Liskov Substitution Principle
const kittens = animals.find(x => x.type === 'cat' && x.ageMonths < 12);
const kittens = animals.find(animal => animal.type === 'cat' && animal.ageMonths < 12);
const kittens = animals.filter(animal => animal.type === 'cat').filter(cat => cat.ageMonths < 12);
const kittens = animals.filter(onlyKittens);
const onlyKittens = ({ type, ageMonths }) => type === 'cat' && ageMonths < 12;
// When to use map?
// .map() when you want to transform elements in an array.
<div *ngIf="(user$ | async) as user; else loading">
<user-profile
[user]="user">
</user-profile>
<user-messages
[user]="user">
</user-messages>
</div>
<ng-template #loading>
<ng-container
*ngIf="isLoggedIn; then loggedIn; else loggedOut">
</ng-container>
<ng-template #loggedIn>
<div>
Welcome back, friend.
</div>
</ng-template>
<ng-template #loggedOut>
<div [ngClass]="{
'is-active': condition,
'is-inactive': !condition,
'is-focused': condition && anotherCondition,
}">
</div>
export const ROUTES: Routes = [
{
path: '',
canActivate: [CoursesGuard],
component: CoursesComponent,
},
{
path: ':id',
canActivate: [CoursesGuard],
component: CourseComponent,