Skip to content

Instantly share code, notes, and snippets.

@o-az
o-az / _ansi-color-codes.md
Last active November 26, 2023 01:41
ANSI color codes in various file formats (.sh, .json, .ts)
ansi colors demo
@o-az
o-az / reset-to-initial-commit.sh
Created November 16, 2023 00:06
Reset the current branch to the initial commit, keeping the working directory as it is
git reset --soft `git rev-list --max-parents=0 HEAD`
@o-az
o-az / hide-scrollbar.js
Created November 2, 2023 11:54
Hide ugly default browser scrollbar without affecting functionality
// ==UserScript==
// @name Hide Scrollbar
// @namespace http://example.com
// @version 1
// @grant GM_addStyle
// @include https://twitter.com/*
// @include https://x.com/*
// @include https://warpcast.com/*
// ==/UserScript==
@o-az
o-az / discord-bot-send-message.sh
Created October 21, 2023 06:37
Sends a message to a Discord channel via a Discord bot using cURL cli command
# replace CHANNEL_ID and BOT_SECRET with your values
curl --include \
--request POST "https://discord.com/api/channels/CHANNEL_ID/messages" \
--header "Content-Type: application/json" \
--header "Authorization: Bot BOT_SECRET" \
--data '{ "content": "lorem ipsum" }'
@o-az
o-az / suppress-warnings.cjs
Last active October 6, 2023 04:17
Suppress all Node.js warnings (including deprecation warnings)
const { emit: originalEmit } = process;
/**
* @param {string} event
* @param {{ name: string; }} error
*/
function suppresser(event, error) {
return event === "warning" && error.name === "ExperimentalWarning"
? false
: originalEmit.apply(process, arguments);
@o-az
o-az / curl-performance.sh
Created September 2, 2023 07:35
I have this in my ~/.zshrc and can run 'perf <url>' to get request performance
function perf {:
curl --silent \
--url "$1" \
--output /dev/null \
--write-out "\n%{time_total} sec\n%{size_download} bytes\n"
}
@o-az
o-az / graphql-introspect-via-curl.md
Last active July 28, 2023 05:38
Introspect GraphQL Schema via curl command
curl --silent --location \
  --request POST \
  --url 'https://spacex-production.up.railway.app' \
  --header 'Content-Type: application/json' \
  --data '{"query":"query IntrospectionQuery { __schema { queryType { name } mutationType { name } subscriptionType { name } types { ...FullType } directives { name description locations args { ...InputValue } } } } fragment FullType on __Type { kind name description fields(includeDeprecated: true) { name description args { ...InputValue } type { ...TypeRef } isDeprecated deprecationReason } inputFields { ...InputValue } interfaces { ...TypeRef } enumValues(includeDeprecated: true) { name description isDeprecated deprecationReason } possibleTypes { ...TypeRef } } fragment InputValue on __InputValue { name description type { ...TypeRef } defaultValue } fragment TypeRef on __Type { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } } } }","variable":{}}'
  • T
@o-az
o-az / sleep.ts
Last active June 23, 2023 23:58
Actual JavaScript 'sleep' function
/**
* @param ms milliseconds to sleep
* @returns void
*/
export function sleep(ms: number): void {
/**
* In some environments such as Cloudflare Workers, Atomics is not defined
* setTimeout is used as a fallback
*/
if (typeof Atomics === 'undefined') {

Generate gpg key and add it to your GitHub account for commit signing & verification

Step 1 (Skip this if you already have GitHub CLI and GnuPG installed)

Install GnuPG and GitHub official CLI tool. Instructions:

// Usage
console.log("\x1b[32m", "color colorr colorrrrr")
const colors = {
reset: "\x1b[0m",
bright: "\x1b[1m",
dim: "\x1b[2m",
underscore: "\x1b[4m",
blink: "\x1b[5m",
reverse: "\x1b[7m",