Skip to content

Instantly share code, notes, and snippets.

View kolpaja's full-sized avatar
💭
Happy Coding

Sokol Paja kolpaja

💭
Happy Coding
View GitHub Profile
@kolpaja
kolpaja / gist:407ec8091a1340529b5a932cb3545a18
Created September 16, 2023 12:24
Komuniteti Mysliman i Shqiperis | Kohet e Namazit | https://www.kmsh.al/namaz/
https://www.kmsh.al/namaz/
@kolpaja
kolpaja / tsconfig.json
Last active August 13, 2023 14:27
Typyscript config file for express js rest api
{
"compilerOptions": {
"outDir": "dist",
"sourceMap": true,
"target": "esnext",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"noImplicitAny": true,
"strict": true,
@kolpaja
kolpaja / [id].jsx
Created February 28, 2023 12:42 — forked from ivandoric/[id].jsx
Code used in video - [Next + Strapi - Internationalization](https://www.youtube.com/watch?v=iqi3ZSp1cpE)
import Link from "next/link";
import { useRouter } from "next/router";
function Page({ content }) {
const router = useRouter();
console.log(router);
return (
<div className="container">
@kolpaja
kolpaja / debounced search
Created February 17, 2023 09:32
debounced search
@kolpaja
kolpaja / useReadingTime.jsx
Created January 25, 2023 08:28
blog article reading time
import { useState, useEffect } from 'react'
export default function useReadingTime(ref, wordsPerMinute = 260) {
const [wordsCount, setWordsCount] = useState(1)
useEffect(() => {
const elem = ref.current
const words = elem.innerText.match(/\w+/g).length
setWordsCount(words)
}, [ref])
import { useState, useEffect } from "react";
const useMediaQuery = (query: string) => {
const [matches, setMatches] = useState(false);
useEffect(() => {
const media = window.matchMedia(query);
if (media.matches !== matches) {
setMatches(media.matches);
}
@kolpaja
kolpaja / useLocalStorage .ts
Last active July 18, 2022 12:49
useLocalStorage hook
import { useEffect, useState } from 'react';
export function useLocalStorage<T>(key: string, initialValue: T | (() => T[])) {
const [value, setValue] = useState<T>(() => {
const jsonValue = localStorage.getItem(key);
if (jsonValue != null) return JSON.parse(jsonValue);
if (typeof initialValue === 'function') {
return (initialValue as () => T)();
// Thanks @twholman!
export default function GitHubCorner() {
return (
<a
href="https://github.com/sanity-io/example-frontend-next-js"
className="github-corner"
aria-label="View source on Github"
title="View source on Github"
>