Skip to content

Instantly share code, notes, and snippets.

@hassam7
hassam7 / iterm2.md
Created July 5, 2025 12:11 — forked from squarism/iterm2.md
An iTerm2 Cheatsheet

Tabs and Windows

Function Shortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)
@hassam7
hassam7 / iterm2.md
Created July 5, 2025 12:11 — forked from squarism/iterm2.md
An iTerm2 Cheatsheet

Tabs and Windows

Function Shortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)
@hassam7
hassam7 / typeof.js
Created February 27, 2025 14:38
typeof js
function getType(obj) {
const lowerCaseTheFirstLetter = (str) => str[0].toLowerCase() + str.slice(1);
const type = typeof obj;
if (type !== 'object') {
return type;
}
return lowerCaseTheFirstLetter(
Object.prototype.toString.call(obj).replace(/^\[object (\S+)\]$/, '$1')
);
(() => {
"use strict";
const fileElem = document.querySelector("article input[type='file']");
const rootElem = document.querySelector("article #file-dissection");
fileElem?.addEventListener("change", handleFileChange);
async function handleFileChange() {
if (!fileElem.files?.length) return;
@hassam7
hassam7 / mod.js
Created December 22, 2024 15:40
negative mod
/**
* Computes the modulus of two numbers, ensuring a non-negative result.
*
* @param {number} a - The dividend.
* @param {number} b - The divisor.
* @returns {number} The modulus, always non-negative.
*/
function mod(a, b) {
if (b === 0) {
throw new Error("Divisor must not be zero.");
@hassam7
hassam7 / labeled statement.js
Created December 1, 2024 00:36
javascript labeled statement
let seats = [
[1, 1, 0, 1, 0],
[0, 1, 1, 1, 0],
[1, 0, 1, 0, 0],
];
function reserveFirstAvailableSeat(seats) {
rows: for (let i = 0; i < seats.length; i++) {
columns: for (let j = 0; j < seats[i].length; j++) {
if (seats[i][j] === 0) {
@hassam7
hassam7 / README.md
Created November 13, 2024 20:00 — forked from abelcallejo/README.md
Creating bootable Linux USB using Mac

Creating bootable Linux USB using Mac

mac

CentOS, Ubuntu, Slackware, etc. Whatever Linux-based OS it is, you can create a bootable USB for it by using a Mac.

1. Prepare the .iso file

Download it, copy it, whatever it takes to prepare that Linux-based OS .iso file

2. Convert the .iso file into a .img.dmg

@hassam7
hassam7 / binary search.js
Created November 13, 2024 14:18
binary search.js
function countFairPairs(nums, lower, upper) {
let n = nums.length;
let count = 0;
nums.sort((a, b) => a - b)
for (let i = 0; i < n; i++) {
let lowerIndex = lowerBound(nums, lower - nums[i], i + 1, n - 1);
let upperIndex = upperBound(nums, upper - nums[i], i + 1, n - 1);
count += upperIndex - lowerIndex;
}
@hassam7
hassam7 / zustand-internals.jsx
Created November 2, 2024 12:36
How zustand works internally
import { useSyncExternalStore } from "react";
// For more on the useSyncExternalStore hook, see https://react.dev/reference/react/useSyncExternalStore
// The code is almost identical to the source code of zustand, without types and some features stripped out.
// Check the links to see the references in the source code.
// The links are referencing the v5 of the library. If you plan on reading the source code yourself v5 is the best way to start.
// The current v4 version contains lot of deprecated code and extra stuff that makes it hard to reason about if you're new to this.
// https://github.com/pmndrs/zustand/blob/fe47d3e6c6671dbfb9856fda52cb5a3a855d97a6/src/vanilla.ts#L57-L94
function createStore(createState) {
@hassam7
hassam7 / dequeArray.js
Created October 6, 2024 22:01
deque array
class DDeque {
constructor(items = []) {
this.items = items;
this.front = 0;
this.rear = items.length - 1;
this.size = items.length;
}
pushFront(item) {
if (this.isEmpty()) {