Skip to content

Instantly share code, notes, and snippets.

// Delete all data in elasticsearch
curl -X DELETE 'http://localhost:9200/_all'
// Backup data to data.json
elasticdump --input=data.json --output=http://localhost:9200 --type=data
// Import data.json to elasticsearch
elasticdump --input=http://localhost:9200/ --output=data.json --type=data --limit 50000
const observable = of('response')
observable.subscribe(result => {
// Do the logic with the result emited by the observable
// .................
// .................
// .................
});
const observable = of('response')
observable.pipe(first()).subscribe(result => {
// Do the logic with the result emited by the observable
// .................
// .................
// .................
});
const observable = of('response')
const result = await getValue(observable)
// Do the logic with the result
// .................
// .................
// .................
const observable = of('response')
function hasValue(value: any) {
return value !== null && value !== undefined;
}
function getValue<T>(observable: Observable<T>): Promise<T> {
return observable
.pipe(
filter(hasValue),
const iAmAwesome = true;
iAmAwesome = false; // Cannot assign to 'iAmAwesome' because it is a constant
interface User {
id: number;
name: string;
}
const user: User = {
id: 1,
name: "Keerati"
};
interface User {
readonly id: number;
name: string;
}
const user: User = {
id: 1,
name: "Keerati"
};
const numbers: number[] = [1, 2, 3, 4, 5];
numbers.push(6); // There is nothing wrong with this
const numbers: ReadonlyArray<number> = [1, 2, 3, 4, 5];
numbers.push(6); // Property 'push' does not exist on type 'ReadonlyArray<number>'