Skip to content

Instantly share code, notes, and snippets.

View caroso1222's full-sized avatar

Carlos Roso caroso1222

View GitHub Profile
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
@caroso1222
caroso1222 / dom.service.ts
Last active August 18, 2023 13:34
Service to dynamically append Angular components to the body
import {
Injectable,
Injector,
ComponentFactoryResolver,
EmbeddedViewRef,
ApplicationRef
} from '@angular/core';
@Injectable()
export class DomService {
@caroso1222
caroso1222 / loading-spinner.service.ts
Created July 16, 2017 01:02
Angular CDK - Portal and PortalHost
import {
Injectable,
ComponentFactoryResolver,
ApplicationRef,
Injector
} from '@angular/core';
import {
ComponentType,
Portal,
ComponentPortal,
@caroso1222
caroso1222 / animations.css
Created August 12, 2017 03:06
Animations
@keyframes fade-in-right {
from {
opacity: 0;
transform: translateX(-15px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
@caroso1222
caroso1222 / style.css
Created August 12, 2017 03:06
styles
.agent-1, .agent-3 {
opacity: 0;
animation: fade-in-right ease 0.4s forwards;
}
.agent-2 {
transform: scaleX(0);
transform-origin: left;
animation: grow-left cubic-bezier(0.785, 0.135, 0.15, 0.86) 0.5s forwards;
animation-delay: 0.4s;
@caroso1222
caroso1222 / pipeline.sh
Created October 9, 2018 03:29
Jenkins pipeline sample
#!/usr/bin/env groovy
node {
def app
stage("Clone") {
git 'https://github.com/caroso1222/ast-viewer.git'
}
stage("Build") {
@caroso1222
caroso1222 / switchMap-approach.ts
Last active December 15, 2018 17:16
pausable observable RxJS
import { Subject, NEVER, interval } from 'rxjs';
import { switchMap, materialize, dematerialize } from 'rxjs/operators';
const source = interval(1000);
const pauser = new Subject();
// switch between source and 'NEVER' depending on our 'control' pauser
pauser
.pipe(
switchMap(paused => paused ? NEVER : source.pipe(materialize())),
@caroso1222
caroso1222 / rxjs-pausify.ts
Last active December 15, 2018 17:18
RxJS Pausify
import { Subject, Observable, never, BehaviorSubject } from 'rxjs';
import { switchMap, takeUntil, tap, materialize, dematerialize } from 'rxjs/operators';
export type PauseableObservable<T> = Observable<T> & Pauser<T>;
export function pausify<T>(obs: Observable<T>): PauseableObservable<T> {
return new Pauser<T>(obs) as PauseableObservable<T>;
}
class Pauser<T> {
@caroso1222
caroso1222 / rxjs-pausify-example.ts
Last active November 29, 2018 05:08
rxjs-pausify-example
// THIS PACKAGE DOES NOT EXIST! IT'S ONLY FOR THE DEMO!
import { PauseableObservable, pausify } from 'rxjs-pausify';
export class MyClass {
pausable$: PauseableObservable<number>;
constructor() {
this.pausable$ = pausify(interval(500));
this.pausable$.subscribe(console.log);
}
@caroso1222
caroso1222 / rxjs-pausable-operator.ts
Last active December 15, 2018 17:31
rxjs-pausable-operator
class PausableObservable<T> extends Observable<T> {
private pauser: BehaviorSubject<boolean>;
pause(){
this.pauser.next(true);
}
resume(){
this.pauser.next(false);
}