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
| // written while juggling a baby- not tested and not verified | |
| function maxScoreWithReset(nums) { | |
| let maxScore = 0; | |
| let aboveZero = false; | |
| let reset = false; | |
| for(const num in nums) { | |
| maxScore = maxScore + num; | |
| // only one reset allowed |
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 (arr){ | |
| if(arr.length <= 3) { | |
| return true; | |
| } | |
| const even = arr[0]; | |
| const odd = arr[1]; | |
| let result = true; | |
| for (let i =2;i < arr.length; i++) { | |
| If(i%2===0) { | |
| result = arr[i] === even; |
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
| interface ResourceOptions<T> { | |
| query: () => Observable<T> | Promise<T>; | |
| } | |
| interface Resource<T> { | |
| query: () => void; | |
| data: Signal<T>; | |
| state: Signal<'IDLE' | 'PROCESSING' | 'EMITTING' | 'COMPLETE'>; | |
| } |
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
| export class SignalHttpService { | |
| constructor(private httpClient: HttpClient) {} | |
| getSomeData() { | |
| const result = signal(null); | |
| this.httpClient.get(url).subscribe(data => result.set(data)); | |
| return result; | |
| } |
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
| // minimal working dependency injection | |
| // the dependency injection works with a property based injection | |
| const clazzMap = Symbol('clazzMap'); | |
| globalThis[clazzMap] = new Map(); // <clazz, instance> | |
| const clazzes = Symbol('clazzes') | |
| globalThis[clazzes] = []; | |
| function register(clazz) { | |
| globalThis[clazzes].push(clazz); |
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 { Component, computed, Signal, signal, WritableSignal } from '@angular/core'; | |
| import { bootstrapApplication } from '@angular/platform-browser'; | |
| import { FormsModule } from '@angular/forms'; | |
| import { NgFor } from '@angular/common'; | |
| @Component({ | |
| selector: 'app-root', | |
| standalone: true, | |
| imports: [ | |
| NgFor, |
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
| // belongs to SpecialModule which is a generic lib, every App needs to provide their implementation of UserService. | |
| // The lib uses this special implementation as UserService internally | |
| abstract class UserService { | |
| } | |
| @Injectable() | |
| class SpecialService { | |
| constructer(private userService: UserService) {} | |
| } |
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
| @customElement('my-element') | |
| export class MyElement extends LitElement { | |
| @property({ | |
| hasChanged(newVal: number, oldVal: number) { | |
| const hasChanged: boolean = newVal !== oldVal; | |
| console.log(`${newVal}, ${oldVal}, ${hasChanged}`); | |
| return hasChanged; | |
| }, | |
| }) |
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
| <ng-template *ngIf="stream$ | async as result"> | |
| <div>{{result}} can be an empty string</div> | |
| </ng-template> |
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
| // simple German normalize | |
| function normalizeIt(str) { | |
| const normalized = str.normalize('NFC') | |
| .toLocaleUpperCase() | |
| .trim() | |
| .replace(/Ä/g, 'AE' ) | |
| .replace(/Ö/g, 'OE' ) | |
| .replace(/Ü/g, 'UE' ) | |
| .replace(/ß/g, 'SS' ) |
NewerOlder