Skip to content

Instantly share code, notes, and snippets.

@Ebrahim-Ramadan
Ebrahim-Ramadan / index.html
Created February 13, 2025 16:56
OTP input with css only
<input type="text" maxlength="6">
<style>
input[type=text] {
--w: 1ch; /* control the width for each letter */
--g: .15em; /* the gap between letters */
--b: 2px; /* the border thickness */
--c: #888;
--_n: attr(maxlength type(<integer>));
@Ebrahim-Ramadan
Ebrahim-Ramadan / Microsoft.PowerShell_profile.ps1
Created February 7, 2025 04:09
A simple $PROFILE function to create a push alias for Git that combines git add ., git commit -m "$1", and git push into one command. Add this to your Microsoft Powershell PROFILE for a faster Git workflow.
function push {
param (
[string]$message
)
git add .
git commit -m $message
git push
}
@Ebrahim-Ramadan
Ebrahim-Ramadan / extension.ts
Created January 30, 2025 16:32
Seamlessly chat with DeepSeek LLMs inside VS Code using Ollama. Real-time AI responses, locally executed!
import * as vscode from 'vscode';
import { Ollama } from 'ollama';
let panel: vscode.WebviewPanel | undefined = undefined;
// Initialize Ollama client
const ollama = new Ollama({
host: 'http://localhost:11434' // default Ollama host
});
@Ebrahim-Ramadan
Ebrahim-Ramadan / page.ts
Created September 21, 2024 16:26
control a React component with the URL
export default function Home() {
let searchParams = useSearchParams();
let [search, setSearch] = useState(searchParams.get('search') ?? '');
let { data, isPlaceholderData } = useQuery({
queryKey: ['people', search],
queryFn: async () => {
let res = await fetch(`/api/people?search=${search}`);
let data = await res.json();
@Ebrahim-Ramadan
Ebrahim-Ramadan / route.ts
Last active September 20, 2024 11:46
Server-Sent Events (SSE) endpoint to stream data every 500 ms (nextjs api endpoint)
import { NextRequest, NextResponse } from 'next/server';
import { words } from './words';
export const dynamic = 'force-dynamic';
const getRandomWord = () => {
const randomIndex = Math.floor(Math.random() * words.length);
return words[randomIndex];
};
@Ebrahim-Ramadan
Ebrahim-Ramadan / geolocation.js
Created September 13, 2024 11:14
Geolocation helper function for nextjs server components
import { headers } from "next/headers";
export function geoLocation() {
const headersList = headers();
return {
ip: headersList.get("x-real-ip"),
country: headersList.get("x-vercel-ip-country"),
city: headersList.get("x-vercel-ip-city"),
};
}
@Ebrahim-Ramadan
Ebrahim-Ramadan / util-copy.ts
Created September 9, 2024 04:06
Clipboard API's limited support for image formats. As of now, it primarily supports PNG and JPEG formats, so we make sure you properly handle the canvas.toBlob() method to update the pngBlob. Ensure that the clipboard write operation supports PNG format after conversion
export const copyToClipboard = async (dataUrl: string) => {
try {
// Convert the Data URL to a Blob
const response = await fetch(dataUrl);
const blob = await response.blob();
// Check if the image is in a supported format, convert if necessary
let pngBlob = blob;
if (blob.type !== 'image/png') {
@Ebrahim-Ramadan
Ebrahim-Ramadan / utils.js
Created August 26, 2024 19:23
partial text search in firebase (the impossible task lol)
export const updateDocumentsWithVinyls = async () => {
try {
const collectionRef = collection(db, 'frames');
const querySnapshot = await getDocs(collectionRef);
for (const docSnapshot of querySnapshot.docs) {
const documentData = docSnapshot.data();
// Check if the document has a 'keywords' field and it's a comma-separated string
// components/TopLoadingIndicator.js
import { useEffect, useState } from 'react';
import { useRouter } from 'next/router';
const TopLoadingIndicator = () => {
const router = useRouter();
const [loading, setLoading] = useState(false);
useEffect(() => {
const handleStart = () => {
@Ebrahim-Ramadan
Ebrahim-Ramadan / use-debounce.js
Created August 11, 2024 21:17
simple use debounce hook in react
import * as React from "react"
export function useDebounce(
value
delay
callback
) {
const [debouncedValue, setDebouncedValue] = React.useState(value)
React.useEffect(() => {