Skip to content

Instantly share code, notes, and snippets.

View konstantindenerz's full-sized avatar

Konstantin Denerz konstantindenerz

View GitHub Profile
@konstantindenerz
konstantindenerz / nullto.pipe.ts
Last active April 12, 2024 07:58
Angular - NullTo-Pipe ✨
@Pipe({
name: 'nullTo',
standalone: true
})
export class NullToPipe implements PipeTransform {
transform<T>(value: T | null, defaultValue: T): T {
return value === null ? defaultValue : value;
}
}
@konstantindenerz
konstantindenerz / angular-pri-live-template.ts
Last active March 14, 2023 23:29
PRI live template for angular projects to inject something.
private readonly $name$ = inject($TOKEN$); $END$
{"title":"Aerodynamic","nodes":{"118":{"type":"MonoSeq","name":"MonoSeq","x":389,"y":91,"ins":[["129",0],["153",0]],"params":{},"scaleRoot":"C2","scaleName":"chromatic","patterns":[[[0,0,1,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,1,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,1,0],[0,0,0,0,0,0,1,0,0,0,0,0,0],[0,0,1,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,1,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,1,0],[0,0,0,0,0,0,1,0,0,0,0,0,0],[0,0,1,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,1,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,1,0],[0,0,0,0,0,0,1,0,0,0,0,0,0],[0,0,1,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,1,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,1,0],[0,0,0,0,0,0,1,0,0,0,0,0,0],[0,0,0,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,0,1,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,1,0],[0,0,0,0,0,0,0,0,1,0,0,0,0],[0,0,0,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,0,1,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,1,0],[0,0,0,0,0,0,0,0,1,0,0,0,0],[0,0,0,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,0,1,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,1,0],[0,0,0,0,0,0,0,0,1,0,0,0,0],[0,0,0,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,0,1,0,0,0,0],[0
@konstantindenerz
konstantindenerz / null-to.pipe.ts
Last active April 4, 2022 10:14
Use this pipe to provide default values for null values of async pipe. `foo$ | async | nullTo:false`
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'nullTo',
})
export class NullToPipe implements PipeTransform {
/**
* Returns {@link value} or {@link newNullValue} if {@link value} is null.
*/
transform<T>(value: T | null, newNullValue: T): T {
@konstantindenerz
konstantindenerz / pr-test-service.ts
Last active October 17, 2022 08:26
webstorm-live-template-pr
private readonly $name$: $CLASS$, $END$
@konstantindenerz
konstantindenerz / recursive-keyof.ts
Last active September 22, 2021 11:19
ts: Recursive keyof
export type KeyOf<T> = {
[K in keyof T & (string | number)]: T[K] extends object ? `${K}` | `${K}.${KeyOf<T[K]>}`: `${K}`;
}[keyof T & (string | number)];
@konstantindenerz
konstantindenerz / webstorm-live-template-hsla-color.css
Last active March 18, 2021 10:33
A WebStorm live template to generate CSS variables for a color definition with hsla() function
--color-$name$-h: $h$;
--color-$name$-s: $s$;
--color-$name$-l: $l$;
--color-$name$-hsl: var(--color-$name$-h), var(--color-$name$-s), var(--color-$name$-l);
--color-$name$: hsl(var(--color-$name$-hsl));
$END$
@konstantindenerz
konstantindenerz / webstorm-live-template-a-story.ts
Last active March 13, 2024 16:30
A WebStorm live template to generate a Storybook's stories file for a specific Angular component. Component Story Format V2
import {Meta, moduleMetadata, StoryObj} from '@storybook/angular';
import {$ComponentName$Component} from './$componentName$.component';
const meta: Meta<$ComponentName$Component> = {
title: '$StoryName$',
component: $ComponentName$Component,
};
export default meta;
type Story = StoryObj<$ComponentName$Component>;
@konstantindenerz
konstantindenerz / angular.json
Created May 20, 2020 05:22
Sample storybook angular project configuration
"storybook": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
@konstantindenerz
konstantindenerz / prepare-commit-msg
Last active May 14, 2020 05:02
Use git hook to assign issue from branch name to commit message
#!/bin/sh
BRANCH_NAME=$(git symbolic-ref --short HEAD)
ISSUE_ID=$(echo $BRANCH_NAME | grep -o '[M|m][F\|f]-[0-9]*')
if [ -n "$ISSUE_ID" ]; then
sed -i.bak -e "1s/$/ [$ISSUE_ID]/" $1
fi