Skip to content

Instantly share code, notes, and snippets.

View aboqasem's full-sized avatar
🇵🇸

Mohammad Al Zouabi aboqasem

🇵🇸
View GitHub Profile
@aboqasem
aboqasem / gitgraph.utils.test.ts
Created April 1, 2024 04:52
Gitgraph.js utils
import { describe, expect, test } from "bun:test";
import { m } from "./utils";
describe("utils", () => {
describe("m", () => {
test("message", () => {
const commit = m`Hello, world!`;
expect(commit.subject).toBe("Hello, world!");
expect(commit.body).toBeUndefined();
});
@aboqasem
aboqasem / can_sum_test.go
Last active March 30, 2024 14:21
Go dynamic programming
package main
import (
"fmt"
"testing"
)
type memo = map[int]bool
func mCanSum(target int, numbers []int, m memo) bool {
@aboqasem
aboqasem / bun-random-available-port.ts
Last active March 30, 2024 04:14
Get a random available port in Bun
function randomAvailablePort(): number {
const server = Bun.serve({ fetch: () => new Response(), port: 0 });
const port = server.port;
server.stop(true);
return port;
}
@aboqasem
aboqasem / starter.sh
Created March 18, 2024 04:42
Bash script starter
#!/usr/bin/env bash
# https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425
set -euo pipefail
DEBUG=${DEBUG:-}
PWD=$(pwd)
SCRIPT_DIR=$(dirname "$0")
if [ -n "$DEBUG" ]; then
@aboqasem
aboqasem / dev-journal.md
Last active March 9, 2024 15:15
Dev Journal

Dev Journal

Git

  • Log all commits that add/delete the search_string in the repo

    git log -S search_string
@aboqasem
aboqasem / biome.jsonc
Last active March 20, 2024 07:00
Biome Config
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"organizeImports": {
"enabled": true
},
"vcs": {
"enabled": true,
"root": ".",
"clientKind": "git",
"useIgnoreFile": true
Java 6 hrs 38 mins ███████▍░░░░░░░░░░░░░ 35.6%
sh 5 hrs 52 mins ██████▌░░░░░░░░░░░░░░ 31.5%
YAML 3 hrs 27 mins ███▉░░░░░░░░░░░░░░░░░ 18.5%
TypeScript 47 mins ▉░░░░░░░░░░░░░░░░░░░░ 4.2%
.env file 28 mins ▌░░░░░░░░░░░░░░░░░░░░ 2.5%
@aboqasem
aboqasem / class-names.ts
Created June 14, 2022 02:07
Simple styling utilites
/**
* Join string class names and ignore falsy values.
*
* ### Example
*
* ```tsx
* <div className={`class1 class2 class3 ${condition ? 'class4' : ''} ${data ? 'class5' : ''}`} />
* // becomes
* <div
* className={classNames(
@aboqasem
aboqasem / vercel.skip.js
Created June 5, 2022 07:18
Vercel Ignore Build Step Script
// @ts-check
const build = () => process.exit(1);
const noBuild = () => process.exit(0);
const {
VERCEL, // An indicator that the app is deployed and running on Vercel. Example: 1.
CI, // An indicator that the code is running in a Continuous Integration environment. Example: 1. NOTE: This Variable is only exposed during Build Step.
VERCEL_ENV, // The Environment that the app is deployed an running on. The value can be either production, preview, or development.
VERCEL_URL, // The URL of the deployment. Example: my-site-7q03y4pi5.vercel.app
@aboqasem
aboqasem / use-array.js
Last active April 16, 2022 00:35
useArray - React hook for managing the state of an array
import { useCallback, useRef, useState } from 'react';
export function useArray(initialState = []) {
const { current: originalState } = useRef(initialState);
const [array, setArray] = useState(initialState);
const setAt = useCallback(
(index, value) => {
const newArray = array.slice();
newArray[index] = value;