This file contains 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
/** | |
* Generates a simple Calendar formatted as an array of arrays | |
* @param year Year for which calendar month is generated | |
* @param month Calendar month to be generated | |
* @param startWeekMonday Optional offset -- defaults to false (week starts on Sunday) | |
* @returns Main array (month) of arrays (weeks) of days | |
* @see Based on algorithm by github:lukeed/calendarize | |
*/ | |
private generateMonthCalendar(year: number, month: number, startWeekMonday = false) { | |
const res: number[][] = []; |
This file contains 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
// More info on locales and codes for names on MDN 'toLocaleString' | |
weekdaysArray(locale = 'en-us', startMonday = false) { | |
const initYear = 2006; // Year that started on the first day of week | |
return Array.from({ length: 7 }, (v, k) => k) | |
.map(weekday => new Date(initYear, 0, weekday + (startMonday ? 1 : 0) + 1) | |
.toLocaleString(locale, { weekday: 'narrow' })); | |
} |
This file contains 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 'dart:math' as math; | |
import 'package:flutter/foundation.dart'; | |
import 'package:flutter/rendering.dart'; | |
import 'package:flutter/widgets.dart'; | |
/// Signature for a function that creates a [TileSize] for a given index. | |
typedef TileSize IndexedTileSizeBuilder(int index); | |
/// Creates grid layouts with a fixed number of spans in the cross axis. |
This file contains 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
// Function with a promise | |
const doAsyncStuff = () => { | |
return new Promise((resolve, reject) => { | |
if (stuff) { | |
resolve('cool'); | |
} | |
reject('bad'); | |
}); | |
}; |
This file contains 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 { ActivatedRoute, Router, NavigationExtras } from '@angular/router'; | |
... | |
const extras: NavigationExtras = { | |
relativeTo: this.route, | |
queryParams: { name: value }, | |
queryParamsHandling: 'merge' | |
}; | |
this.router.navigate([], extras).then(() => { /* continue here */ }); |
This file contains 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
requestName(): Observable<Call> { | |
return new Observable(observer => { | |
const endpoint = 'endpoint'; | |
const data = {}; | |
// #region:multipart | |
// In case of multipart | |
const formData: FormData = new FormData(); | |
Object.keys(data).forEach((key) => { | |
formData.append(key, data[key]); |
This file contains 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
returnObservable(): Observable<any> { | |
return new Observable(observer => { | |
if (/* whatever */) { | |
return observer.next(body.data); | |
} else { | |
return observer.error(body.data); | |
} | |
return { unsubscribe() {} }; | |
}); |
This file contains 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
const cloned = JSON.parse(JSON.stringify(original)); |
This file contains 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 * as data from './example.json'; | |
... | |
const word = (<any>data).name; | |
console.log(word); // output 'testing' |
This file contains 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
getResultFromRemote(): Subject<string> { | |
const subs = new Subject<string>(); | |
this.http.get('http://localhost/service') | |
.subscribe((res) => { | |
subs.next(res); | |
}, (err) => { | |
subs.error(res); | |
}); | |
return subs; | |
} |