Skip to content

Instantly share code, notes, and snippets.

View riscie's full-sized avatar
🤖
coding

Matthias Langhard riscie

🤖
coding
  • DXC Technology Switzerland
  • Zurich
View GitHub Profile
@riscie
riscie / localstorage.service.ts
Created July 15, 2022 18:32
Generic Angular Typescript Localstorage Service
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class LocalstorageService {
constructor() {}
set(key: string, value: any) {
localStorage.setItem(key, JSON.stringify(value));
@riscie
riscie / angular_ngclass.md
Created June 2, 2020 13:37
angular [ngClass] #angular

Angular version 2,...,9 provides several ways to add classes conditionally:

type one

[class.my-class]="step === 'step1'"

type two

[ngClass]="{'my-class': step === 'step1'}"

and multiple option:

@riscie
riscie / ngOnChanges.ts
Last active May 20, 2020 18:07
ngOnChanges with SimpleChanges hook #angular #typescript
ngOnChanges(changes: SimpleChanges): void {
for (const property in changes) {
if (changes.hasOwnProperty(property)) {
switch (property) {
case 'someInputName': {
// do something
}
}
}
}
@riscie
riscie / is-this-password-pwned.sh
Last active June 12, 2021 20:13
script to locally check if your password has been breached using haveibeenpwned.com hashes #bash
#!/bin/bash
# description script to locally check if your password has been breached using haveibeenpwned.com hashes
# usage bash mkscript.sh
# dependencies bash, 7z, grep, wget
#==============================================================================
# checking prerequirements
sha1HashFile="pwned-passwords-sha1-ordered-by-hash-v5"
if ! test -f "$sha1HashFile.txt"; then
read -p "Password hashes not found. Download the file now? (y/n)" -n 1 -r
@riscie
riscie / Dockerfile
Last active August 12, 2020 09:09
Expands from the existing dotnet core aspnet 3.1 docker image (based on debian) and installs msttcorefonts #docker
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
# adding debian contrib package sources (https://www.debian.org/doc/debian-policy/ch-archive.html)
RUN apt-get update
RUN apt-get install -y --no-install-recommends software-properties-common
RUN apt-add-repository contrib
RUN apt-get update
# installing mscorefonts
RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections
@riscie
riscie / .zshrc
Last active March 28, 2023 10:55
automatically start tmux when ssh into a box #zsh #shell
# inside your .bashrc or .zshrc (on the server side) add:
# start tmux if we ssh into the box
if [[ -n "$PS1" ]] && [[ -z "$TMUX" ]] && [[ -n "$SSH_CONNECTION" ]]; then
tmux attach-session -t $USER || tmux new-session -s $USER
fi
# this will attach to an ongoing tmux session or start a new one
# the session name will be the name of the user ($USER)
@riscie
riscie / rxjs_6_pipe.ts
Last active May 20, 2020 15:31
rxjs 6 (using .pipe) #angular #typescript
import { tap, debounceTime, map, filter } from 'rxjs/operators';
this.$someSubject
.pipe(
tap(console.log),
debounceTime(this.inputDebounceTime),
map(value => parseFloat(value)),
filter(value => !isNaN(value)),
).subscribe(result => {
// ...
@riscie
riscie / rxjs_5_before_pipe.ts
Last active May 20, 2020 15:31
rxjs 5 (before pipe) #angular #typescript
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/debounceTime'; 
import 'rxjs/add/operator/distinctUntilChanged'; 
//import …
this.$someSubject 
.do(console.log)
.debounceTime(800) 
.map(value => parseFloat(value)) 
  .filter(value => !isNaN(value))