This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "math/rand" | |
| "time" | |
| ) | |
| func main() { | |
| rand.Seed(time.Now().UnixNano()) // initialisation du générateur de nombres aléatoires |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Visitor pattern solves the problem elegantly. Start by modifying our base Fruit class: | |
| */ | |
| interface FruitVisitor { | |
| visit(fruit: Orange): void; | |
| visit(fruit: Apple): void; | |
| visit(fruit: Banana): void; | |
| } | |
| abstract class Fruit { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {Injectable} from '@angular/core'; | |
| import {Configuration} from '../../../assets/config/config'; | |
| import {HttpClient} from '@angular/common/http'; | |
| @Injectable() | |
| export class ConfigService { | |
| private defaultConfig: Configuration; | |
| private runningConfig: Configuration; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Enum Alternatives in Typescript. | |
| * Enums are simple value-type flags that provide very minimal protection from invalid values and no behavior. | |
| * Displaying enums in UI elements like DropDownLists is another challenge if they need to have spaces. | |
| */ | |
| class Role { | |
| public static allRoles = []; | |
| public static Author: Role = new Role(0, 'Author'); | |
| public static Editor: Role = new Role(1, 'Editor'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function makeProductList(productDb) { | |
| return Object.freeze({ | |
| addProduct, | |
| }) | |
| function addProduct() { | |
| return 1; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as R from 'ramda'; | |
| import { HttpParams } from '@angular/common/http'; | |
| import { Injectable } from '@angular/core'; | |
| import { Observable } from 'rxjs/Observable'; | |
| import { ApiService } from '@core/api-service/api.service'; | |
| import { ApiResponseLegacy } from '@core/api-service/apiResponse.interface'; | |
| import { Company } from '@shared/services/company/company.model'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Resolve promises one after another (i.e. in sequence) | |
| function sequence(tasks, fn) { | |
| return tasks.reduce((promise, task) => promise.then(() => fn(task)), Promise.resolve()); | |
| } | |
| function inSequence(tasks) { | |
| return tasks.reduce((p, task) => p.then(task), Promise.resolve()) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Constructors or Static Factory Methods VS. Polymorphism | |
| /* | |
| * Advantages to using static factory methods instead of constructors | |
| * They have names. | |
| * They can cache. | |
| * They can subtype. | |
| */ | |
| class Color { | |
| private hex: number; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person { | |
| public name: string = "default"; | |
| public address: string = "default"; | |
| public age: number = 0; | |
| public constructor(init?: Partial<Person>) { | |
| Object.assign(this, init); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Classes vs. Objects "classes" vs. "behavior delegation (OLOO-style)" | |
| */ | |
| /** | |
| * ES6 class | |
| * Example: common base widget behavior, and then child derived classes for specific widget types (like Button) | |
| */ | |
| class Widget { | |
| constructor(width, height) { |
NewerOlder