Skip to content

Instantly share code, notes, and snippets.

View jotatoledo's full-sized avatar
🎯
Focusing

José Toledo Navarro jotatoledo

🎯
Focusing
View GitHub Profile
getUniques(): Hit[] {
const mergedHits = this.read().concat(this.previousData);
const hitsById = new Map(mergedHits.map(hit => [hit.id, hit]);
return [...mergedHitsById.values()];
}
// Based on https://codereview.stackexchange.com/a/223655/145828
static public IEnumerable<T> SkipLast<T>(this IEnumerable<T> data, int count)
{
if (data == null) throw new ArgumentNullException(nameof(data));
if (count <= 0) return data;
if (data is ICollection<T> collection)
return collection.Take(collection.Count - count);
IEnumerable<T> Skipper()
@jotatoledo
jotatoledo / retry-operator.ts
Created February 17, 2019 15:25
A custom operator used to retry an HTTP request
import { timer, throwError, Observable } from 'rxjs';
import { mergeMap } from 'rxjs/operators';
export interface RetryParams {
maxAttempts?: number;
scalingDuration?: number;
shouldRetry?: ({ status: number }) => boolean;
}
const defaultParams: RetryParams = {
export class MatSidenavMock {
_animationStarted = new EventEmitter<AnimationEvent>();
opened = false;
}
export class TdLayoutManageListComponentMock implements ILayoutTogglable {
get sidenav(): MatSidenav {
return <any>this.mockSidenav;
}
readonly mockSidenav = new MatSidenavMock();
@jotatoledo
jotatoledo / cov-contra.cs
Created May 23, 2018 15:40
Explanation of covariance and contravariance in C#
// Assignment compatibility.
string str = "test";
// An object of a more derived type is assigned to an object of a less derived type.
object obj = str;
// Covariance.
IEnumerable<string> strings = new List<string>();
// An object that is instantiated with a more derived type argument
// is assigned to an object instantiated with a less derived type argument.
// Assignment compatibility is preserved.
import { Injectable, ClassProvider } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpErrorResponse, HTTP_INTERCEPTORS } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { _throw } from 'rxjs/observable/throw';
import 'rxjs/add/operator/catch';
/**
* Intercepts the HTTP responses, and in case that an error/exception is thrown, handles it
* and extract the relevant information of it.
*/