Skip to content

Instantly share code, notes, and snippets.

View VinceOPS's full-sized avatar
👌

Vincent G VinceOPS

👌
View GitHub Profile
@VinceOPS
VinceOPS / lib.rs
Created November 14, 2019 22:34
Rust: count calendar days between 2 timestamps
/// Count the number of calendar days between two dates given as
/// timestamps in milliseconds. Make the assumption that One day is
/// 86_400_000 milliseconds (leap seconds are ignored).
pub fn count_days_between(timestamp_ms_a: u64, timestamp_ms_b: u64) -> u64 {
let days_count_a = timestamp_ms_a / 1000 / 3600 / 24;
let days_count_b = timestamp_ms_b / 1000 / 3600 / 24;
let days_count_between = match days_count_a.checked_sub(days_count_b) {
Some(difference) => difference,
None => days_count_b - days_count_a,
};
@VinceOPS
VinceOPS / wait-for-assertion.spec.ts
Last active June 1, 2022 13:41
Nest: testing (E2E) asynchronous side-effects with Jest and RxJs
import { TimeoutError } from 'rxjs';
import { waitForAssertion } from './wait-for-assertion';
describe('waitForAssertion', () => {
let mockWitness: jest.Mock;
beforeEach(() => {
mockWitness = jest.fn().mockReturnValue(false);
});
@VinceOPS
VinceOPS / inherit-validation.decorator.spec.ts
Last active January 10, 2019 15:36
Inherit validation metadata of another property, using class-validator
import { getFromContainer, IsDateString, IsEmail, IsNumber, IsOptional, IsString, Max, MaxLength, MetadataStorage, validate } from 'class-validator';
import { ValidationMetadata } from 'class-validator/metadata/ValidationMetadata';
import _ from 'lodash';
import { InheritValidation } from './inherit-validation.dtodep.decorator';
/**
* Used as a base for validation, in order for partial classes
* to pick validation metadatas, property by property.
*/