Skip to content

Instantly share code, notes, and snippets.

View oscarteg's full-sized avatar
🏠

Oscar te Giffel oscarteg

🏠
View GitHub Profile
@oscarteg
oscarteg / find_duplicate_dependencies.txt
Created February 20, 2025 11:48
This oneliner finds all the package.json and shows the duplicate dependencies
fd package.json -x jq -r '"\(.dependencies + .devDependencies | to_entries | .[] | "\(.key)@\(.value)")"' {} | sort | uniq -d
@oscarteg
oscarteg / conventional-commits-cheatsheet.md
Created October 17, 2024 11:56 — forked from qoomon/conventional-commits-cheatsheet.md
Conventional Commits Cheatsheet

Conventional Commit Messages

See how a minor change to your commit message style can make a difference.

Tip

Have a look at git-conventional-commits , a CLI util to ensure these conventions, determine version and generate changelogs

Commit Message Formats

Default

@oscarteg
oscarteg / ANSI.md
Created September 2, 2024 16:46 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@oscarteg
oscarteg / merge-objects.ts
Created June 11, 2024 18:59
Merge objects in Typescript.
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
function isObject(item: unknown): item is Record<string, unknown> {
return typeof item === 'object' && item !== null && !Array.isArray(item);
}
/**
* Merge objects, second objects overwrites the keys of the first objects
*/
function deepMerge<T extends Record<string, unknown>, U extends Record<string, unknown>>(target: T, source: U): T & U {
Command Description
git blame -L 28,43 path/to/file Shows who modified each line in a specific range of a file.
git blame -L :'class LocalFile' filepath Blames a block of code in a file matching a specific pattern.
git log -L28,43:filepath Lists commits that last touched a specified region of a file.
git blame -w Ignores whitespace changes in git blame.
git blame -C Follows code movement across files in git blame. Can be used up to three ti
@oscarteg
oscarteg / commands.sh
Created October 21, 2023 16:18
Usefull bash commands
# Delete node_modules using fd (github.com/sharkdp/fd)
fd -HI node_modules -X rm -rf
@oscarteg
oscarteg / fetch.ts
Last active July 13, 2024 12:48
Typescript tips and tricks. This is update whenever I come across something cool
// Credits to Matt Pocock
type CreateAPIMethod = <
TInput extends Record<string, string>, // The input
TOutput // The output
>(opts: {
url: string;
method: "GET" | "POST"
}) = (input: TInput) = Promise<TOutput>;
declare const createAPIMethod: CreateAPIMethod;
@oscarteg
oscarteg / scrollbar.css
Created September 14, 2023 10:31
The CSS property to prevent scrollbar pushing the layout
/* The scrollbar-gutter CSS property allows authors to reserve space for the scrollbar, preventing unwanted layout changes as the content grows while also avoiding unnecessary visuals when scrolling isn't needed. */
/* https://developer.mozilla.org/en-US/docs/Web/CSS/scrollbar-gutter */
.scrollbar {
scrollbar-gutter: stable;
}
@oscarteg
oscarteg / http.ts
Created September 6, 2023 11:04
A simple HTTP service to wrap fetch services with abstraction to handle errors
/**
* A strategy for fetching data from the server.
*
* @callback FetchStrategy
* @param {string} url - The URL to fetch data from.
* @param {RequestInit} [options] - Additional options for the fetch request.
* @returns {Promise<Response>} A promise that resolves to the fetch response.
*/
export type FetchStrategy = (
url: string,
@oscarteg
oscarteg / better_error_handling.ts
Last active August 18, 2023 16:13
A simple way for error handling in Typescript
enum ResultKind {
OK = "Ok",
ERR = "Err",
}
export type Result<T, E> = Ok<T> | Err<E>;
interface ResultBase<A, E> {
kind: ResultKind;
map<B>(fn: (_: A) => B): Result<B, E>;