Skip to content

Instantly share code, notes, and snippets.

View kerren's full-sized avatar

Kerren Ortlepp kerren

View GitHub Profile
@kerren
kerren / track-focus.directive.ts
Last active March 23, 2024 09:12
A directive that allows you to see if an input is in focus or not. See my blog article here https://blog.entrostat.com/angular-inputs-improved-error-ux/ and see StackOverflow article that inspired this here https://stackoverflow.com/questions/57536298/how-to-check-if-an-input-field-is-in-focus-in-angular-7/57536348#57536348
import { Directive, HostListener, signal } from '@angular/core';
@Directive({
selector: '[appTrackFocus]',
standalone: true,
exportAs: 'isFocused',
})
export class TrackFocusDirective {
isFocused = signal(false);
@kerren
kerren / install_byobu.sh
Last active October 28, 2023 16:18
Install byobu from source
# Full instructions
# https://blog.entrostat.com/install-byobu-on-any-linux-distro/
BYOBU_VERSION=5.133
set -e
echo "Please make sure you have the following dependencies installed:"
echo " [+] tar"
echo " [+] screen"
@kerren
kerren / partial-type.ts
Created March 25, 2021 10:14
[Partial types] An example where we don't need the whole item #types #partial #typescript
class Person {
name: string;
surname: string;
email: string;
age: number;
uuid: string;
};
async function confirmSurname(person: Partial<Person>) {
if (!person.email) {
@kerren
kerren / object-key-names.ts
Created March 22, 2021 19:26
[Object key names] Name your variables right! #object #names #typescript
const name = 'John';
const surname = 'Doe';
const someOtherVariableThatIsNotNamedCorrectly = 22;
const person = { name, surname };
const personWithAge = {
name,
surname,
age: someOtherVariableThatIsNotNamedCorrectly
@kerren
kerren / cool-maps.ts
Created March 22, 2021 19:18
[A map key] A map can take any type of key! #map #typescript
const map = new Map();
map.set(1, 'simple');
console.log(map.get(1));
// 'simple'
const person = {
name: 'John',
surname: 'Doe'
};
@kerren
kerren / spread-operator.ts
Last active March 22, 2021 19:21
[The spread operator] A simple example to show how it works #spread #operator #typescript
const a = {
character: 'a',
description: 'This is a',
level: 1,
aUnique: 123
};
const b = {
description: 'This is b',
bbb: 'b'
@kerren
kerren / main.ts
Created March 22, 2021 18:52
[TSConfig Paths Import Example] How to use these paths in code #tsconfig #paths #typescript
// Before the "@config" path
import * as config from '../../config';
import { Config } from '../../config';
// After the "@config" path
import * as config from '@config';
import { Config } from '@config';
@kerren
kerren / tsconfig.json
Last active March 22, 2021 18:45
[TSconfig paths example] A sample config #tsconfig #typescript
{
"compiler": {
"paths": {
"@config": ["src/config"],
"@logger": ["src/modules/shared/logger/logger.service"],
"@modules/*": ["src/modules/*"]
}
}
}
@kerren
kerren / database.ts
Created March 21, 2021 21:48
[An example of a feature config] How a database config would look #config #feature
export const database = {
type: 'postgres',
host: process.env.DB_HOST,
port: Number(process.env.DB_PORT || 5432),
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
name: 'default',
};
@kerren
kerren / use-config.ts
Created March 21, 2021 21:44
[Importing the config] A few ways to do it #config #import #nestjs
// 1. Import the full config object
import { Config } from '@config';
console.log(Config.database);
// 2. Import a single "feature"
import { database } from '@config';
// 3. Import the full config but as a namespace
import * as config from '@config';