Skip to content

Instantly share code, notes, and snippets.

View motss's full-sized avatar
🥑
Life is like a prototype, just like JavaScript. So, keep betting on JavaScript!

The web walker motss

🥑
Life is like a prototype, just like JavaScript. So, keep betting on JavaScript!
View GitHub Profile
@motss
motss / option-some-none-match.ts
Last active July 31, 2024 14:27
Simple implementation of Option, Some, None, and match() in TypeScript
type Some<T> = { some: T, none: false };
type None = { some: undefined, none: true };
type Option<T = unknown> = Some<T> | None;
type InferredSome<T extends Option> = T extends Some<infer R> ?
R :
never;
type OptionResult<T = unknown> = T extends null | undefined ? None : Some<T>;
@motss
motss / get-merged-prs-from-last-release-tag-then-format-for-changelog-using-github-cli.sh
Last active May 24, 2024 04:20
How to get a list of merged PRs after the last release tag then format for changelog using Github CLI
#!/bin/sh
# Ensure a reelase tag is provided
if [ -z "$1" ]; then
printf "Please provide a release tag!\n"
exit 1
fi
RELEASES=$(gh release list --limit 1)
@motss
motss / mru-using-doubly-linked-list.js
Last active April 18, 2024 17:48
MRU in JavaScript using Doubly linked list
class Node {
constructor(value) {
this.prev = null;
this.next = null;
this.value = value;
}
}
class MRU {
constructor(size) {
@motss
motss / expression-parser-multi-line.js
Last active October 19, 2023 11:50
Expression parser
// a = 1; b = a - 1; b = b - 100; b * a - 100
// split('; ');
// a=1
// b=a-1
// b=b-100
// b*a-100
// a=1
// a 1 =
@motss
motss / get-bundlejs-badge-url.js
Last active April 27, 2023 17:51
Generate custom badge URL using shields.io and deno.bundlejs.com
function tryParseUrl(url) {
try {
const u = new URL(url);
return u;
} catch (error) {
console.error(error);
return '';
}
}
@motss
motss / switch-to-zsh-in-bash.md
Last active August 6, 2021 13:49
Switch to ZSH Shell in Bash
@motss
motss / find-sum-of-2-smallest-numbers.js
Last active October 22, 2020 05:31
Find the sum of 2 smallest numbers
function findSmallestSum(arr) {
const len = arr.length;
if (!len) return 0;
if (len === 1) return arr[0];
if (len === 2) return arr[0] + arr[1];
// f - first, s - second
let [f, s] = arr;
let sum = f + s;
@motss
motss / vscode-ff-custom-settings.json
Created November 19, 2019 03:22
VSCode Firefox Quantum Theme custom settings.json
{
"workbench.colorCustomizations": {
"editor.selectionBackground": "#2179775c",
"editor.background": "#0a0a0a"
},
"workbench.colorTheme": "Firefox Quantum Dark"
}
@motss
motss / create-social-media-share-button-by-customizable-link.js
Created September 11, 2019 04:19
Create social media share button by customizable link
@motss
motss / alternating-characters.js
Created September 3, 2019 05:58
Alternating characters
// Time complexity: O(n) where n is the number of characters.
// Space complexity: O(1) for a few variables.
function alternatingCharacters(x) {
const len = x.length;
if (len < 2) return 0;
let lastChar = x[0];
let count = 0;
let countA = lastChar === 'a' ? 1 : 0;