Skip to content

Instantly share code, notes, and snippets.

View webcat12345's full-sized avatar
🤓
Enjoying new things...

man Q webcat12345

🤓
Enjoying new things...
View GitHub Profile
constructor(
private router: Router,
private activatedRoute: ActivatedRoute,
private titleService: Title
) {}
ngOnInit(): void {
this.router.events
.filter(event => event instanceof NavigationEnd)
.map(() => this.activatedRoute)
@webcat12345
webcat12345 / Image src placeholder
Last active November 10, 2017 08:20
Display placeholder image if url is invalid
This is way is very simple and nice way to display images in Angular.
<img [src]="imageUrl" class="img-responsive" onError="this.src='assets/images/no-image.png';">
@webcat12345
webcat12345 / Media Stream via BrowserAPI&Twilio&Vidyo
Created May 20, 2018 04:07
Expect to get media stream from the Vidyo Client like Twilio does. Right now, I can not find a way to resolve this, so I am using native API. Need help on this.
// angular component init lifecycle
ngOnInit() {
// setup vidyo client
this.vidyoService.loadVidyoClientLibrary();
// as a seperate process, calling browser API to get media
navigator.getUserMedia({audio: true},
(stream) => {
@webcat12345
webcat12345 / Basic Component Unit test with Fake DB
Created July 9, 2018 15:07
TDD - Unit test for components
/***
Fake backend router looks like this.
static router(url: string): DBConnection {
if (url === environment.apiUrl + 'users') {
return {db: annotators, searchField: '', type: RequestType.Pagination};
} else if (url.includes(environment.apiUrl + 'corpora')) {
if (url === environment.apiUrl + 'corpora') {
return {db: corpora, searchField: 'name', type: RequestType.Pagination};
} else {
@webcat12345
webcat12345 / Rxjs 6 Usage
Created July 9, 2018 15:11
Simple usage of Rxjs 6 operators and functions with Typescript
this.signUpForm.get('email').valueChanges
.pipe(
tap(() => this.isInvalidEmail = false),
debounceTime(500),
filter(value => CommonService.validateEmail(value)),
tap((x) => {
this.isCheckingEmail = true;
this.isInvalidEmail = false;
}),
switchMap(x => this.authService.checkEmail(x)),
@webcat12345
webcat12345 / file-size.pipe.ts
Created December 24, 2018 03:04 — forked from JonCatmull/file-size.pipe.ts
Angular2 + TypeScript file size Pipe/Filter. Convert bytes into largest possible unit. e.g. 1024 => 1 KB
import { Pipe, PipeTransform } from '@angular/core';
/*
* Convert bytes into largest possible unit.
* Takes an precision argument that defaults to 2.
* Usage:
* bytes | fileSize:precision
* Example:
* {{ 1024 | fileSize}}
* formats to: 1 KB
@webcat12345
webcat12345 / group-objects-by-property.md
Created April 28, 2020 02:25 — forked from JamieMason/group-objects-by-property.md
Group Array of JavaScript Objects by Key or Property Value

Group Array of JavaScript Objects by Key or Property Value

Implementation

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;
wget -O /tmp/YaHei.Consolas.1.12.zip https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/uigroupcode/YaHei.Consolas.1.12.zip
unzip /tmp/YaHei.Consolas.1.12.zip
sudo mkdir -p /usr/share/fonts/consolas
sudo mv YaHei.Consolas.1.12.ttf /usr/share/fonts/consolas/
sudo chmod 644 /usr/share/fonts/consolas/YaHei.Consolas.1.12.ttf
cd /usr/share/fonts/consolas
sudo mkfontscale && sudo mkfontdir && sudo fc-cache -fv
@webcat12345
webcat12345 / delete_git_submodule.md
Created September 14, 2021 08:41 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule