Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Zim_Ejin zimejin

🎯
Focusing
Block or report user

Report or block zimejin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:e489d864e2c89c6595ffdfaef29eb190
(focus)="myMethod()" // An element has received focus
(blur)="myMethod()" // An element has lost focus
(submit)="myMethod()" // A submit button has been pressed
(scroll)="myMethod()"
(cut)="myMethod()"
(copy)="myMethod()"
(paste)="myMethod()"
@zimejin
zimejin / rxjs.js
Created May 30, 2019
RxJS snippets
View rxjs.js
//emit value every 1s
const source = interval(1000);
const example = source.pipe(
map(val => {
if (val > 5) {
//error will be picked up by retryWhen
throw val;
}
return val;
}),
@zimejin
zimejin / utils.js
Created May 28, 2019
algorithmic utilities
View utils.js
// Using slice() to Remove value from beginning and end of string.
sliceString = function (value) {
let result = value.slice(1, -1);
return result;
}
// Using splice() method to changes the contents of an array by removing
// or replacing existing elements and/or adding new elements
var months = ['Jan', 'March', 'April', 'June'];
@zimejin
zimejin / factory.js
Last active May 26, 2019
Factory design pattern
View factory.js
// Animal factory
const Animal = function(name){
const animal = {};
animal.name = name;
animal.walk = function(){
console.log(this.name + " walks");
}
return animal;
};
View excerpt.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'excerpt' })
export class ExcerptPipe implements PipeTransform {
transform(text: string, limit: number = 5) {
if (text.length <= limit) {
return text;
}
return text.substring(0, limit) + '...';
}
View user-async.component.ts
import { Component, OnInit } from '@angular/core';
import { UserAsyncService } from './user-async.service';
import { Observable } from 'rxjs';
@Component({
selector: 'app-user-async',
templateUrl: './user-async.component.html',
styleUrls: ['./user-async.component.scss'],
providers: [UserAsyncService]
})
View googleData.ts
export interface GoogleData {
id: number;
country: string;
zipCode: string;
}
View user.component.spec.ts
import { async, TestBed } from '@angular/core/testing';
import { UserComponent } from './user.component';
import { UserService } from './user.service';
describe('UserComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [UserComponent]
View user-async.service.ts
import { Observable, Observer } from 'rxjs';
export class UserAsyncService {
user = { name: 'Mannie' };
getUserDetails() {
// Create an observables.
const userObservables = Observable.create(
(observer: Observer<{ name: string }>) => {
setTimeout(() => {
observer.next(this.user);
View user-async.component.spec.ts
import { TestBed, tick, fakeAsync } from '@angular/core/testing';
import { UserAsyncComponent } from './user-async.component';
import { UserAsyncService } from './user-async.service';
import { Observable, Observer } from 'rxjs';
describe('User Async Component:', () => {
beforeEach(async () => {
TestBed.configureTestingModule({
declarations: [UserAsyncComponent]
});
You can’t perform that action at this time.