Skip to content

Instantly share code, notes, and snippets.

View ErfanEbrahimnia's full-sized avatar
🎯
Focusing

Erfan Ebrahimnia ErfanEbrahimnia

🎯
Focusing
  • Salzburg, Austria
View GitHub Profile
// Javascript
var $form = $('#form-id'),
error;
$form.submit(function()
{
error = 0;
// check if radio groups are selected
@ErfanEbrahimnia
ErfanEbrahimnia / state-machine.js
Last active August 29, 2015 14:19
Simple state machine with transitions
'use strict';
var _ = require('lodash');
/**
* @class StateMachine
* @constructor
*/
function StateMachine(options) {
/**
@ErfanEbrahimnia
ErfanEbrahimnia / glowing-input.css
Last active August 12, 2024 15:59
Glowing Input Animation with CSS
@property --rotation {
syntax: "<angle>";
inherits: false;
initial-value: 0deg;
}
@property --pos-x {
syntax: "<percentage>";
inherits: false;
initial-value: 0%;
@ErfanEbrahimnia
ErfanEbrahimnia / basic_auth.ts
Created August 21, 2024 14:50
Simple Basic Auth password protection for Next.js
import { type NextRequest, NextResponse } from "next/server";
export function middleware(request: NextRequest) {
return basicAuth(request);
}
function basicAuth(request: NextRequest) {
const authHeader = request.headers.get("Authorization");
const validCredentials = process.env.BASIC_AUTH_CREDENTIALS; // e.g. admin:12345
@ErfanEbrahimnia
ErfanEbrahimnia / use_resize_scale.ts
Last active August 27, 2024 19:23
Adjust element size based on container using CSS transform
import { useLayoutEffect, useRef, useState } from "react";
import { flushSync } from "react-dom";
export function useResizeScale<
ContainerRef extends HTMLElement,
InnerRef extends HTMLElement,
>({ width }: { width: number }) {
const containerRef = useRef<ContainerRef | null>(null);
const innerRef = useRef<InnerRef | null>(null);
const [innerStyle, setInnerStyle] = useState<React.CSSProperties>({});
@ErfanEbrahimnia
ErfanEbrahimnia / react-dropzone-paste.tsx
Created September 3, 2024 18:13
Paste files from your clipboard with react-dropzone
import { useRef, type ClipboardEvent } from "react";
import { useDropzone } from "react-dropzone";
function Dropzone() {
const inputRef = useRef<HTMLInputElement>(null)
const {
getRootProps,
getInputProps,
} = useDropzone({...});