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
#! /usr/bin/env python | |
import json | |
import sys | |
j = json.load(sys.stdin) | |
print json.dumps(j, sort_keys=True, indent=2) |
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
[alias] | |
today = log --since=midnight --author='Davide Cavaliere' --oneline | |
history = log --graph --pretty=format:'%Cred%h%Creset %d -%Cblue %s%Creset %Cgreen(%ar) %Cblue<%an>%Creset' --abbrev-commit --date=relative | |
ci = commit | |
st = status |
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
$urls = ['www.amazon.com',...]; | |
foreach ($url as $ip => $url) { | |
// create a stream that returns immediately | |
// STREAM_CLIENT_CONNECT _MUST_ be passed | |
// STREAM_CLIENT_ASYNC_CONNECT says create connection | |
// asyncrhronously | |
$socket = stream_socket_client("tcp://$ip:80", $errno, $errstr, 0, | |
STREAM_CLIENT_CONNECT, STREAM_CLIENT_ASYNC_CONNECT); |
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; |
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
/* | |
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
@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
@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
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 { | |
constructor(private _client: HttpClient) {} | |
@Cache({ | |
ttl: 2500 | |
}) | |
public findAll(id): Observable<any> { | |
return this._client.get(`https://reqres.in/api/users?page=${id}`) | |
} |