Skip to content

Instantly share code, notes, and snippets.

View davidecavaliere's full-sized avatar
🏠
Working from home

Davide Cavaliere davidecavaliere

🏠
Working from home
View GitHub Profile
[…]
 third subscriber 3 sec later, ttl expired. shoult hit the endpoint
 arguments are
 [1]
 argsNotChanged
 true
 this actually hit the endpoint
 starting subscribed
 {page: 1, per_page: 6, total: 12, total_pages: 2…}
 first subscribed
setTimeout(() => {
this.$log.d('starting subscriber');
this.userService.findAll(1).subscribe((data) => {
this.$log.d('starting subscribed');
this.$log.d(data);
this.users = data;
})
}, 0);
setTimeout(() => {
export function Cache(options: CacheOptions) {
let lastCallArguments: any[] = [];
return (target, propertyKey: string, descriptor) => {
Reflect.metadata(CacheMetadata, options)(target);
@Injectable()
export class UserService {
constructor(private _client: HttpClient) {}
@Cache({
ttl: 2500
})
public findAll(id): Observable<any> {
return this._client.get(`https://reqres.in/api/users?page=${id}`)
}
export interface CacheOptions {
ttl: number;
}
export function Cache(options: CacheOptions) {
return (target: any, propertyKey: string, descriptor) => {
const originalFunction = descriptor.value;
target[`${propertyKey}_cached`] = new ReplaySubject(1, options.ttl);
descriptor.value = function(…args) {
const req = originalFunction.apply(this, args).pipe(
@Injectable()
export class UserService {
private cached$: ReplaySubject<any> = new ReplaySubject(1, 2500);
constructor(private _client: HttpClient) {}
public findAll(id): Observable<any> {
const req = this._client.get(`https://reqres.in/api/users?page=${id}`).pipe(
tap((data) => {
this.cached$.next(data);
@Injectable()
export class UserService {
constructor(private _client: HttpClient) {}
public findAll(id: number) {
return this._client.get(`https://reqres.in/api/users?page=${id}`);
}
}
/*
For more info please head to https://github.com/davidecavaliere/flatten
*/
function* flatten([head, ...tail]) {
if (Array.isArray(head)) {
yield* flatten(head);
} else {
yield head;
import itertools;
permutations = itertools.permutations([100,250,1000, 1200]);
times = []
for it in permutations :
print it
presum = 0;
roundTrip = []
var start = process.hrtime();
// you can use console.log for debugging purposes, i.e.
// console.log('this is a debug message');
function solution(X, A) {
// write your code in JavaScript (Node.js 0.12)
var isEven = A.length % 2 === 0;