Skip to content

Instantly share code, notes, and snippets.

View bonomiandreia's full-sized avatar
🐆

bonomiandreia

🐆
  • Lisboa, Portugal
View GitHub Profile
@bonomiandreia
bonomiandreia / gist:27c709f0b99f0515fa54e986d5cd9810
Created October 7, 2023 18:23
A password detection system similar
function countMinimumOperations(password) {
let operations = 0;
let vowels = 0;
let consonants = 0;
// Count the number of vowels and consonants in the password
for (let i = 0; i < password.length; i++) {
const char = password[i];
if ('aeiou'.includes(char)) {
vowels++;
@bonomiandreia
bonomiandreia / angularsignals.js
Last active March 13, 2023 22:22
angular signals
Signals are a value that can be observed, I can call a method in the last item of an array, example. as rxjs, they can work like "follow" updates in variables, objects etc.
.set: set a new value for a variable and notify dependents.
.update: update a value based with a current value (number ) => number + 1 and return the new value
.mutate: catch the new value and updated it. its similar with update, the diference is .mutate doesn't return a value and mentains a history.
effect and computed: will receive a notify and do something about it
effect(() => console.log(we have ${number} dogs now!
@bonomiandreia
bonomiandreia / mat-calendar-hover-date.scss
Last active August 16, 2022 10:18
scss example to change / override dates hover to mat-calendar angular material
@media(hover: hover) {
::ng-deep .mat-calendar-body-cell:not(.mat-calendar-body-disabled):hover>.mat-calendar-body-cell-content:not(.mat-calendar-body-selected):not(.mat-calendar-body-comparison-identical) {
background-color: red !important;
border-radius: 0 !important;
}
::ng-deep .mat-calendar-body-today:not(.mat-calendar-body-selected):not(.mat-calendar-body-comparison-identical) {
background-color: green !important;
border: 0 !important;
border-radius: 0 !important;
@bonomiandreia
bonomiandreia / observables.ts
Created March 25, 2022 02:53
observables and subject study
observables are lazy, means that if it doesnt have a subscribe, observables cant execute the code.
Subject are other type of observable, they both can emit many values.
observables can't emit data outside itself.
subjects can emit multiples values outside itself.
example: https://stackblitz.com/edit/angular-ivy-5tnmap
// sass can use directly inside @component
styles: [$font-size: 40em]
ng build doesnt need anymore of --prod flag
remove IE11 suppport to IE11
// angular 13
ngFor, ngIf says instructs for template what to do
I have a list, so ngFor, loop this array and show the list
I have this variable, if true, ngIf, show this variable
@bonomiandreia
bonomiandreia / decorators.ts
Last active March 24, 2022 03:29
decorators
@Injector // it says to angular that this service or class can be use without a parameter,
automatize without parameter of constructor
example:
class ServiceOrOtherClass {
constructor(http: httpClient) {
}
}
Decorator is a special kind of declaration that can be attached to a class declaration, method, accessor, property, or parameter
@bonomiandreia
bonomiandreia / ngModel.ts
Created March 23, 2022 00:41
study of ngModel
<input type=text [value]="received some value"/>
<input type=text (keyUp)="emit some value"/>
<input type=text [(value)]="emit and received some value (update template "html" and component (ts file)"/>
@bonomiandreia
bonomiandreia / inputAndOutput.ts
Created March 21, 2022 15:11
input and output test!
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<app-value-provider (typedValue)="recivedValue($event)"></app-value-provider>
<app-value-receiver *ngIf="valueOfInput" [printValue]="valueOfInput"></app-value-receiver>
`,
})
export class AppComponent implements OnChanges {
@bonomiandreia
bonomiandreia / promisestest.js
Last active March 8, 2022 17:55
promises test
// difference beetween race and all
// ALL
const promise1 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('promise1 resolved! timeout')
}, 2000)
})