This file contains 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
using System; | |
using System.Security.Cryptography; | |
public class Program | |
{ | |
/** | |
* You can try this code at https://dotnetfiddle.net/ZkY1HV | |
*/ | |
private const int SALT_LENGTH = 16; |
This file contains 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
using System; | |
public class Program | |
{ | |
/** | |
* You can this code at https://dotnetfiddle.net/uH4B69 | |
*/ | |
public static void Main() | |
{ | |
string text = "Hello World!"; |
This file contains 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
public getRandomColor(): string { | |
const letters = '0123456789ABCDEF'; | |
let color = '#'; | |
for (let i = 0; i < 6; i++) { | |
color += letters[Math.floor(Math.random() * 16)]; | |
} | |
return color; | |
} |
This file contains 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
public downloadBlob(blob: Blob, documentName: string, extension: string) | |
{ | |
const fileURL = URL.createObjectURL(blob); | |
const a: HTMLAnchorElement = document.createElement('a'); | |
document.body.appendChild(a); | |
a.href = fileURL; | |
a.download = `${documentName}.${extension}`; | |
a.click(); | |
} |
This file contains 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
/** Converts hexadecimal color to RGBA with transparency. */ | |
public transparentize(color: string, opacity: number = 0.5): string { | |
return this.hexToRgbA(color, 1 - opacity); | |
} | |
/** Converts an hexadecimal color to RGBA */ | |
public hexToRgbA(hex: string, opacity: number = 1): string { | |
let c: any; | |
if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) { | |
c = hex.substring(1).split(''); |
This file contains 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
/** Removes the current UTC offset. */ | |
public removeUtcOffset(utcDate: any): Date { | |
let date: Date; | |
if (utcDate instanceof Date) { | |
date = utcDate; | |
} else { | |
date = moment(utcDate, this.localGlobalService.getDashDateMomentFormat()).toDate(); | |
} | |
const noOffsetDate: Date = moment(date).utc().subtract(date.getTimezoneOffset(), 'm').toDate(); | |
return noOffsetDate; |
This file contains 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
/** | |
* | |
* Duplica el contenido de un objeto sobre otro del mismo tipo. | |
* | |
* @param source Objeto a partir de cual obtener los valores | |
* @param destiny Objeto al cual asignar dichos valores | |
*/ | |
mapAll<T>(source: T, destiny: T) { | |
const keys: any[] = Object.keys(source); | |
keys.forEach((key) => { |
This file contains 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
/** | |
* Compares two same type objects to check if their properties and values are equals. | |
* | |
* Attention: It is not recursively. | |
* @param original Original element to have as a base. | |
* @param compareTo element to compare to with the original one. | |
* @returns The result from comparing both. | |
*/ | |
equals<T>(original: T, compareTo: T): boolean { | |
if (!original && !compareTo) { |
This file contains 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
/** | |
* Checks if an object is has all the properties defined. | |
* | |
* Attention: It does not work recursively. | |
* @param obj Object to scan. | |
* @param type Object type. | |
* @returns Boolean, depending on if all the properties are defined or not. | |
*/ | |
defined<T>(obj: T, type: new () => T): boolean { | |
if (!obj) { |
This file contains 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
/* This method detects when the user is leaving without prompting anything. */ | |
@HostListener('window:unload', ['$event']) | |
unloadHandler(event) { | |
console.log('window:unload'); | |
} |
OlderNewer