Skip to content

Instantly share code, notes, and snippets.

View LironHazan's full-sized avatar
🎸
666 -> 🦀

LironH LironHazan

🎸
666 -> 🦀
View GitHub Profile
const gulp = require('gulp');
const paths = gulp.paths;
const gulpIf = require('gulp-if');
const $ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'del']
});
/**
const Rx = require('rxjs');
class AnimalsService {
constructor(data){
this._source = data;
}
// lazy loading, client will ask for x items (limit) it will be the length of the returned array,
simplePager(pageIndex=0, limit=10, data) {
const deleteCount = pageIndex*limit;
@LironHazan
LironHazan / zip_folder_example.js
Last active December 18, 2017 19:49
zip a folder code snippet I refactored based on tarzg function I used in a node backend project few years ago
const zipit = (dest, name) => {
const filePath = path.join(dest, name + '.zip');
const output = fs.createWriteStream(filePath);
const archive = archiver('zip', { zlib: { level: 9 } });
archive.pipe(output);
// callback
output.on('close', () => {
console.log('callback when everything is finished');
});
archive.directory('deploy/', false);
@LironHazan
LironHazan / forkJoin.ts
Created January 10, 2018 12:26
I needed to do something similar to the promise.all just with observables and came up with forkJoin, here's an example
geSomethingById(id: number): Observable<any[]> {
return this.http.get<any[]>(
`api/something?id=${id}`);
}
getSomething(ids) {
const ids = this.getListOfVersionIds(selectedArtifacts)
const requests = ids.reduce((acc, id) => {
acc.push(this.geSomethingById(id));
@LironHazan
LironHazan / MyDialogService.ts
Last active October 4, 2018 11:16
test paste
import {Injectable, TemplateRef} from '@angular/core';
import {MatDialog} from '@angular/material';
import {ComponentType} from '@angular/cdk/typings/portal';
import {MyDialogComponent} from './my-dialog.component';
@Injectable({
providedIn: 'root'
})
export class MyDialogService {
constructor(public dialog: MatDialog) { }
@LironHazan
LironHazan / my-dialog.component.ts
Created September 17, 2018 18:43
my-dialog.component.ts
import {Component, ComponentFactoryResolver, ComponentRef, Inject, OnDestroy, OnInit, ViewChild, ViewContainerRef} from '@angular/core';
import {MAT_DIALOG_DATA} from '@angular/material';
@Component({
selector: 'app-my-dialog',
templateUrl: './my-dialog.component.html',
styleUrls: ['./my-dialog.component.scss']
})
export class MyDialogComponent implements OnInit, OnDestroy {
@ViewChild('target', { read: ViewContainerRef }) viewContainerRef: ViewContainerRef;
<header>
<button mat-icon-button mat-dialog-close="true">
<i class="material-icons">clear</i>
</button>
</header>
<mat-dialog-content>
<ng-template #target></ng-template>
</mat-dialog-content>
import { Injectable } from '@angular/core';
import {
HttpRequest,
HttpHandler,
HttpEvent,
HttpInterceptor,
HttpErrorResponse
} from '@angular/common/http';
import { Observable } from 'rxjs';
import {tap} from 'rxjs/operators';
<div (click)="isAdvancedOpen = !isAdvancedOpen">
<i [ngClass]="[isAdvancedOpen ? 'fas fa-arrow-circle-down' : 'fas fa-arrow-circle-right']"> Advanced </i>
</div>
<app-tabs-advanced *ngIf="isAdvancedOpen" [somedatatobind]="somedatatobind"></app-tabs-advanced>
// global style file
.alert-panel .mat-dialog-container {
border: 1px solid red;
}
// alert component
import {Component, Inject} from '@angular/core';
import {MAT_DIALOG_DATA} from '@angular/material';