Skip to content

Instantly share code, notes, and snippets.

View ahamed's full-sized avatar
🎯
Focusing on open source.

Sajeeb Ahamed ahamed

🎯
Focusing on open source.
View GitHub Profile
@ahamed
ahamed / iterm2-solarized.md
Created June 30, 2021 10:12 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

@ahamed
ahamed / neon-button.css
Created July 14, 2021 14:05
Make neon glowing button with CSS only.
/* <button class="neon-button">Neon Button</button> */
:root {
--clr-neon: hsl(317 100% 54%);
--clr-bg: hsl(323 21% 16%);
}
*::before,
*::after {
box-sizing:border-box;
@ahamed
ahamed / getRange.js
Created July 26, 2021 06:34
Get a range within two given numbers (inclusive).
const range = (min, max) => {
// If max value is smaller than the min value then swap it.
if (max < min) [min, max] = [max, min];
const _range = (max + 1) - min;
return Array.from({length: _range}, (_, i) => min + i);
}
console.log(range(1, 5)); // 1, 2, 3, 4, 5
console.log(range(10, 5)); // 5, 6, 7, 8, 9, 10
[
{
"id": 1,
"name": "Putin FM",
"frequency": "66,6",
"image": "./assets/images/stations.planet-01.jpeg"
},
{
"id": 2,
"name": "Dribble FM",
@ahamed
ahamed / trie.js
Created October 31, 2021 07:15
Implement the Trie data structure for storing worlds in an efficient way.
function Node(character) {
this.value = character;
this.endOfWord = false;
this.children = {};
}
class Trie {
constructor() {
this.root = new Node(null);
}
@ahamed
ahamed / leap-year.js
Last active August 11, 2022 14:02
Check if a year is a Leap Year or not.
/**
* Find a year is a leap year or not.
* The logic is simple, create an instance of a date
* with the date 29 of the february of the given year.
* If the date 29 exists in that year that means the
* year is a leap year, otherwise it's not.
* What a brilliant idea.
*
* @author 📩 Sajeeb Ahamed <sajeeb07ahamed@gmail.com>
@ahamed
ahamed / is-same-array.js
Last active July 17, 2022 15:09
Check if two arrays are same i.e. same elements but in different order.
const arr1 = [1, 2, 3, 4, 6, 5, 2];
const arr2 = [2, 3, 1, 4, 2, 5, 6];
const isSameArray = (arr1, arr2) => {
if (arr1.length !== arr2.length) {
return false;
}
// Create object like {1: 1, 2: 2, 3: 1 ...} , the number of frequency of an element in the array.
@ahamed
ahamed / extract-promise.ts
Created July 19, 2022 17:13
Extract [response, error] from a promise function.
export const extractPromise = async <
// eslint-disable-next-line @typescript-eslint/no-explicit-any
F extends (...args: any) => Promise<any>,
A extends Parameters<F>,
R extends ReturnType<F>,
>(
promiseFn: F,
...args: A
): Promise<[Awaited<R> | undefined, unknown | undefined]> => {
try {
@ahamed
ahamed / indexOf.ts
Created July 21, 2022 16:47
Find an item's index from a tuple.
type IncrementByOne<N extends number, T extends unknown[] = []> =
T['length'] extends N
? [...T, unknown]['length']
: IncrementByOne<N, [...T, unknown]>;
type IndexOf<T extends unknown[], U extends unknown, I extends number = 0> =
I extends T['length']
? -1
: T[I] extends U
? I
/**
* Remove some properties from an object,
* and work with other properties.
*
* You can use destructuring and ...rest operator for gaining this result.
*
* @author Sajeeb Ahamed <sajeeb07ahamed@gmail.com>
*/
const store = {
id: '123',