Skip to content

Instantly share code, notes, and snippets.

View publicJorn's full-sized avatar

Jorn Luiten publicJorn

  • frontrain
  • Netherlands
View GitHub Profile

Automatically add issue number to git commit message

When working with issues/tickets in gitlab, -hub, Jira, etc. It's a good practise to add the issue number to the branch name and commit message.
This way you basically generate a documented history.

But adding the issue number manually to a git message is tedious. This git hook manages it for you.

prepare-commit-msg hook

Let's say your team has agreed on the branch name format: review/123_short-description

@publicJorn
publicJorn / MyComponent.test.tsx
Created November 24, 2021 10:19
jest mockImplementation for react component
// When you have a complex child component which you need to have different implemenations of
// in order to properly test your parent component
import React from 'react'
import { render, screen } from '@testing-library/react'
import '@testing-library/jest-dom'
import ParentComponent from './ParentComponent'
// Workaround so we can add a spy
import * as childComponent from './ChildComponent'
@publicJorn
publicJorn / jest-window-resizeTo.ts
Created March 28, 2022 10:15
Snippet to test different window sizes in jest
window.resizeTo = function resizeTo(width:number, height: number) {
Object.assign(this, {
innerWidth: width,
innerHeight: height,
outerWidth: width,
outerHeight: height,
}).dispatchEvent(new this.Event('resize'))
}
@publicJorn
publicJorn / custom-typefilter.ts
Created June 16, 2024 09:37
Custom utility type to filter or remove types
// Playground: https://www.typescriptlang.org/play/?#code/PTAEBUE8AcFNWgJwPYHNEEMC2WCWA7VAKBFAHFkMAbALlADNcqAXWRUDUACgGdZnQyegEpQzGLB4MUWDvmTMAFmzESSYRc2bQeNEACMqaAHQBrXEmQ9FxgMbIswWwFcezBwFpnzJrnEfxOB4PAgCJHltEC2ZgIiJA+AAFNh5kfABJfHpkUABeUABvIlBQfGxYOjcowgBuYo5UCtLnLH02OpLoRTSm-Ba2xA7QAEdnBSaqglQhgHdkRFM6LlFcgD5QADdkXAATIgBfOviJUAAlWCxkDdgAaVhIHgB5eig4AB5X2AAaUDvIdfyRRKAG1TPdQARQGDIEIICcMFJPqD7gBdUCwAAerHwOykf1AAH5SrBruw6NCUXQkRS6oc4glQAAxJisRB-J4vCQfCQ-P4Awr1ZGQCH4KH3WGfDiIiRCtGY7G437gonQ0B0fAktiUuFwWW0o7HOCgADqfm63gAcv0Unkzhcrrd7hzPm9kohUhkssgfn1WmxVkcGY98FRIFa-e7bcyWGx2c8XW6PZlsj7rYgA-STsHQ+GBjwAII4gDKzGqqCk+WjrLjnPeibSye9zQjoAAPqBJoRVkQgA
// Type programming
// Goal: filter a (set of) types from another type
// https://blog.kiprosh.com/custom-utility-types-in-typescript/
type PersonInfo = {
name: string;
age: number;
phone: number;