Skip to content

Instantly share code, notes, and snippets.

View guillaumegarcia13's full-sized avatar
💭
Building awesome things 🚀

GARCIA Guillaume guillaumegarcia13

💭
Building awesome things 🚀
View GitHub Profile
@guillaumegarcia13
guillaumegarcia13 / yield.ts
Last active July 31, 2018 10:43
Yield example
// Run it live on: https://goo.gl/dgwE2D
class Example {
public getCountries(fields: string[] = ['name', 'alpha2Code', 'translations', 'flag']): Observable<any[]> {
const sep = (function* () {
let call = 0;
while (true) {
yield (call++ === 0) ? '?' : '&';
}
})();
@guillaumegarcia13
guillaumegarcia13 / regex_split_path.js
Last active July 22, 2018 13:33 — forked from nopjia/splitPath.js
The ultimate split path, with a single regex
/**
* The ultimate split path.
* Extracts dirname, filename, extension, and trailing URL params.
* Correct handles:
* empty dirname,
* empty extension,
* random input (extracts as filename),
* multiple extensions (only extracts the last one),
* dotfiles (however, will extract extension if there is one)
* @param {string} path
@guillaumegarcia13
guillaumegarcia13 / myresponsive.decorator.ts
Last active July 17, 2018 14:38
Angular Responsive Decorator
/* Disclaimer:
* This snippet is provided “AS IS” and could contain technical inaccuracies, typographical errors and out-of-date information.
* Use of the information is therefore at your (very) own risk.
*/
/*_____________________________________________________________________________________________________________________
* Aim
* Provide some solution in case of complex constructs to manage layout from an Angular point-of-view (ex: ngx-datatable)
* See: https://github.com/swimlane/ngx-datatable/issues/423
*
@guillaumegarcia13
guillaumegarcia13 / promises.ts
Last active June 25, 2018 08:06
Promises.all
// Play it on Typescript Playground: https://www.typescriptlang.org/play/
class Test {
static process(): Promise<any> {
let promises = [
Promise.resolve(1),
Promise.resolve(2),
Promise.reject(3),
Promise.resolve(4),
new Promise((res, rej) => { throw new Error('Boum'); }),
Promise.resolve(6),
@guillaumegarcia13
guillaumegarcia13 / GitCommitEmoji.md
Created April 3, 2018 13:20 — forked from parmentf/GitCommitEmoji.md
Git Commit message Emoji
@guillaumegarcia13
guillaumegarcia13 / hotjar_debug.js
Last active March 19, 2018 09:46
Hojar: advanced recording manipulation in DevTools
angular.reloadWithDebugInfo(); // https://github.com/angular/angular.js/issues/9515
// Check whether the tagged recordings are set to favourite
var dbg_hj = angular.element($(".recordings-table-container table")).scope().pageResponses()
.map(elt => {
return {
"index" : elt.index,
"id" : elt.id,
"duration" : moment.duration(elt.duration).minutes() + ':' + ('0' + moment.duration(elt.duration).seconds()).slice(-2),
"favourite": elt.favourite,
@guillaumegarcia13
guillaumegarcia13 / clone.js
Created February 20, 2018 16:36 — forked from sstur/clone.js
Deep-copy an object, similar to calling JSON.parse(JSON.stringify(obj)) but preserves dates and undefined
function clone(obj) {
if (Object(obj) !== obj) return obj;
if (typeof obj.toJSON == 'function') {
return obj.toJSON();
}
var type = toString.call(obj).slice(8, -1);
if (type in CLONE) {
return CLONE[type].call(obj, clone);
}
var copy = {};
@guillaumegarcia13
guillaumegarcia13 / groupBy.ts
Created January 12, 2018 23:39
groupBy in Typescript (for use in Angular)
declare global {
interface Array<T> {
groupBy(prop: T): Array<T>;
}
}
if (!Array.prototype.groupBy) {
Array.prototype.groupBy = (prop: string) => {
return this.reduce(function(groups, item) {
const val = item[prop];
@guillaumegarcia13
guillaumegarcia13 / Promise.delay.ts
Created October 24, 2017 13:53
Promise.delay using Declaration Merging in TypeScript
/* On TypeScript Playground: https://goo.gl/EQVVUk */
// Interface merging: https://www.typescriptlang.org/docs/handbook/declaration-merging.html
// declare global {
interface Promise<T> {
delay(duration?: number): Promise<T>;
}
// }
// Allow some sugar syntax
@guillaumegarcia13
guillaumegarcia13 / formatFileSize.js
Last active October 17, 2017 08:03
Format File Size (0,98 KB, 1,5 GB, ...)
let formatFileSize = (bytes) => {
if (bytes === 0) {
return '0 B';
}
const k = 1024,
dm = 3,
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));