This file contains hidden or 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
[…] | |
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 |
This file contains hidden or 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
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(() => { |
This file contains hidden or 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
export function Cache(options: CacheOptions) { | |
let lastCallArguments: any[] = []; | |
return (target, propertyKey: string, descriptor) => { | |
Reflect.metadata(CacheMetadata, options)(target); |
This file contains hidden or 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
@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}`) | |
} |
This file contains hidden or 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
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( |
This file contains hidden or 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
@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); |
This file contains hidden or 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
@Injectable() | |
export class UserService { | |
constructor(private _client: HttpClient) {} | |
public findAll(id: number) { | |
return this._client.get(`https://reqres.in/api/users?page=${id}`); | |
} | |
} |
This file contains hidden or 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
/* | |
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; |
This file contains hidden or 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
import itertools; | |
permutations = itertools.permutations([100,250,1000, 1200]); | |
times = [] | |
for it in permutations : | |
print it | |
presum = 0; | |
roundTrip = [] |
This file contains hidden or 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
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; |
NewerOlder