Skip to content

Instantly share code, notes, and snippets.

View zeroxjackson's full-sized avatar

jackson ⁖ zeroxjackson

View GitHub Profile
@zeroxjackson
zeroxjackson / subscribe.ts
Last active February 1, 2025 18:27
Beehiiv x Next.js Typescript Integration
import { NextApiRequest, NextApiResponse } from 'next';
export type CustomField = {
name: string;
value: string;
};
export type SubscriptionTier = 'free' | 'premium';
export type SubscriptionInput = {
@zeroxjackson
zeroxjackson / index.tsx
Created January 2, 2025 00:22
React State Management Overview
"use client";
import React, { useState, useEffect } from "react";
import {
useQuery,
useMutation,
useQueryClient,
QueryClient,
QueryClientProvider,
} from "@tanstack/react-query";
@zeroxjackson
zeroxjackson / .zshrc
Last active October 14, 2024 19:10
Terminal Cat Image
# Path to the ASCII art file
moose="$HOME/moose.txt"
# Display the ASCII art at the top of the terminal
if [ -f "$moose" ]; then
cat "$moose"
fi
# Display the moose at will
alias moose="cat $HOME/moose.txt"
@zeroxjackson
zeroxjackson / Footer.tsx
Created October 13, 2024 16:11
MADEWITHLOVE Heartbeat Animation
@zeroxjackson
zeroxjackson / logger.js
Created September 17, 2024 18:28
Buffered Async Logging
import { createContext, useContext, useState, useEffect } from 'react';
const LogContext = createContext();
export const LogProvider = ({ children }) => {
const [logs, setLogs] = useState([]);
useEffect(() => {
const interval = setInterval(() => {
if (logs.length > 0) {
function rgbToHex(r, g, b) {
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).toUpperCase();
}
function getContrastRatio(color1, color2) {
const luminance1 = chroma(color1).luminance();
const luminance2 = chroma(color2).luminance();
return (Math.max(luminance1, luminance2) + 0.05) / (Math.min(luminance1, luminance2) + 0.05);
}
@zeroxjackson
zeroxjackson / demon.js
Created August 24, 2024 15:46
simple clone of nodemon
const fs = require('fs');
const path = require('path');
const childProcess = require('child_process');
const readline = require('readline');
const RESTART_DELAY = 1800; // dedup events
const MAIN_PROCESS_FILE = 'index.js';
function logts(date = new Date()) {
const year = date.getFullYear();
@zeroxjackson
zeroxjackson / pkill.sh
Created April 28, 2023 15:08
A shell script for macOS to kill all processes running on a port
#!bin/zsh
# Example Usage: pkill 3000
# Kills all processes listening on the specified port
pkill () {
sudo lsof -i :$1 | # get a list of all processes listening on the specified port
xargs -I % echo % | # convert the list into a string
awk '{print $2}' | # select only the PID column (2)
awk 'NR%2==0' | # remove the header PID
sort | # sort the PID list
@zeroxjackson
zeroxjackson / get_current_prices.py
Last active April 11, 2023 16:14
a python function to fetch current stock market or crypto data
import pandas
from pandas_datareader import data as pdr
from datetime import datetime, timedelta
import yfinance as yfin
def get_current_prices(symbols: list[str], padding=2):
yfin.pdr_override()
def fmt(date: datetime) -> str:
return date.strftime('%Y-%m-%d')
@zeroxjackson
zeroxjackson / sendTextMessage.ts
Last active April 11, 2023 16:24
Send text with twilio firebase function
import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
type TwilioRequest = {
to: string;
body: string;
}
/**
* Validates if the phone number is in e.164 format. Learn more: https://en.wikipedia.org/wiki/E.164.
* @param {string} phone The phone number you are validating.