Skip to content

Instantly share code, notes, and snippets.

View settings.json
{
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[scss]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.suggest.insertMode": "replace"
View keybindings.json
[
{
"key": "alt+r",
"command": "workbench.action.reloadWindow",
"when": "editorFocus"
},
{
"key": "ctrl+tab",
"command": "workbench.action.nextEditor"
},
@riivanov
riivanov / addToImage.js
Created March 7, 2023 13:36
Sets alt of all images to random word; Watches for image additions, adds input box, changes alt to input value, sets border color
View addToImage.js
(async function addRandomWordToImgs() {
async function getRandomWord() {
const word = await fetch("https://random-word-api.herokuapp.com/word");
const ary = await word.json();
return ary.shift();
}
async function getAllImgElements() {
return document.querySelectorAll("img");
}
@riivanov
riivanov / deep-read-only
Created February 7, 2023 22:51
Recursive Type Example
View deep-read-only
type DeepReadonlyObject<T> = { readonly [K in keyof T]: DeepReadonly<T[K]> };
type DeepReadonly<T> = T extends (infer E)[] ?
ReadonlyArray<ReadonlyArray<DeepReadonlyObject<E>>> :
T extends object ? DeepReadonlyObject<T> :
T;
@riivanov
riivanov / TypesvsInterfaces.md
Last active February 5, 2023 19:20
Types vs Interfaces
View TypesvsInterfaces.md

Most of the times, type aliases in TypeScript are used to alias a more complex type, like a union of other types, to a reusable name. On the other hand, interfaces are used for more traditional object-oriented purposes, where you define the shape of an object and then use that as a contract for function parameters or for a class to implement.

fundamental.ts

type Pet = IDog | ICat;

interface IAnimal {
  age: number;
  eat(): void;
@riivanov
riivanov / config
Last active February 5, 2023 18:18
~/.ssh/config - How to create alias for ssh connection: End Result - `ssh aws-eu-north-1` to connect
View config
Host aws-eu-north-1
HostName ec2-16-170-180-221.eu-north-1.compute.amazonaws.com
User ubuntu
IdentityFile /home/rivanov/.ssh/aws_ed25519-eu-north-1
@riivanov
riivanov / 30-touchpad.conf
Created February 4, 2023 20:32
/etc/X11/xorg.conf.d - Enable tapping on Lenovo Thinkpad E15 Gen2
View 30-touchpad.conf
Section "InputClass"
Identifier "touchpad"
Driver "libinput"
MatchIsTouchpad "on"
Option "Tapping" "on"
EndSection
@riivanov
riivanov / .etc.profile
Created February 4, 2023 20:30
/etc/profile with startup root apps modifications at the bottom
View .etc.profile
# /etc/profile
# Set our umask
umask 022
# Append "$1" to $PATH when not already in.
# This function API is accessible to scripts in /etc/profile.d
append_path () {
case ":$PATH:" in
*:"$1":*)
@riivanov
riivanov / todo.entity.ts
Created February 1, 2023 16:36
Todo entity that is both an ORM entity, and part of a GQL schema definition
View todo.entity.ts
import { Field, ID, InputType, ObjectType } from "type-graphql";
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
@ObjectType()
@Entity()
export class Todo {
@Field()
@PrimaryGeneratedColumn()
id: number;