Skip to content

Instantly share code, notes, and snippets.

View Mulperi's full-sized avatar
🎯
Focusing

Mika Mulperi Lakanen Mulperi

🎯
Focusing
View GitHub Profile
@Mulperi
Mulperi / observable.js
Created May 22, 2018 09:30
Simple Observable Test
const { from } = require("rxjs");
const fetchData = () => {
return from(new Promise((resolve, reject) => {
setTimeout(() => {
resolve({ id: "abc123", name: "John Rambo" });
}, 2000);
})
);
}
@Mulperi
Mulperi / observable2.js
Created October 13, 2018 09:44
Observable concatMap
const { from } = require('rxjs');
const { concatMap } = require('rxjs/operators');
const getUserId = () => {
return from(['1337']);
};
const getUserById = id => {
return from([
{
@Mulperi
Mulperi / item.effects.ts
Last active November 9, 2018 07:47
NGRX Effect and withLatestFrom example
@Effect()
selectItem$ = this.actions$.pipe(
ofType(itemAction.ITEM_SELECT),
concatMap(() =>
this.store.select(fromItems.getItemsSelected)
),
withLatestFrom(
this.store.select(fromUi.getItemsSideviewVisible)
),
filter(
@Mulperi
Mulperi / reduce.ts
Last active November 19, 2018 12:21
JavaScript Array.reduce example
// Return array containing unique item names.
return items.reduce(
(filteredArray: any, currentItem: Item) => {
if (!filteredArray.includes(currentItem.name)) {
filteredArray.push(currentItem.name);
}
return filteredArray;
},
[]
@Mulperi
Mulperi / feature.component.ts
Created December 11, 2018 12:07
Handling dynamic component stream
this.dynamicComponentService
.getLatestComponentStream()
.subscribe((component: any) => {
if (component) {
this.componentStack.push(component);
this.createComponent();
} else {
this.dynamicComponentsContainerRef.remove(
this.componentStack.length - 1
);
@Mulperi
Mulperi / dynamic-component.service.ts
Created December 11, 2018 12:11
Dynamic component service
export class DynamicComponentService {
latestComponent = new BehaviorSubject<any>(null);
getLatestComponentStream(): Observable<any> {
return this.latestComponent.asObservable();
}
pushComponent(component: any): void {
this.latestComponent.next(component);
}
@Mulperi
Mulperi / package.json
Created December 27, 2018 08:38
Simple npm scripts for CloudFormation deployment
{
"name": "MyProject",
"version": "1.0.0",
"description": "",
"main": "index.js",
"config": {
"AWSS3BUCKET": "MyBucket",
"AWSPROFILE": "personal",
"AWSREGION": "eu-north-1",
"AWSSTACK": "MyStack"
@Mulperi
Mulperi / template_minimal_lambda.yaml
Created December 27, 2018 09:04
Minimal Lambda SAM template
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: 'My test serverless API'
Parameters:
BucketName:
Type: String
CodeKey:
Type: String
StackName:
Type: String
@Mulperi
Mulperi / paginator.component.ts
Last active January 8, 2019 12:34
Probably the world's simplest paginator with Angular.
import { Component } from '@angular/core';
@Component({
selector: 'app-paginator',
template: `
<div *ngFor="let item of items | slice:(page*itemsPerPage):(page*itemsPerPage+itemsPerPage)">
{{ item.title }}
</div>
<button [disabled]="page == 0" (click)="onPreviousClick()">previous page</button>