Skip to content

Instantly share code, notes, and snippets.

View Alimjanov-Ibragim's full-sized avatar
🎯
Focusing

Ibragim Alimjanov-Ibragim

🎯
Focusing
View GitHub Profile
@Alimjanov-Ibragim
Alimjanov-Ibragim / react-use-throttle-hook-usage.tsx
Created September 5, 2023 08:19 — forked from loonywizard/react-use-throttle-hook-usage.tsx
Example of usage of React useThrottle hook
import React, { useEffect, useState } from 'react'
import { useThrottle } from './useThrottle'
export default function App() {
const [value, setValue] = useState('hello')
const throttledValue = useThrottle(value)
useEffect(() => console.log(`throttledValue changed: ${throttledValue}`), [
throttledValue,
import { useEffect, useRef, useState } from 'react'
function useThrottle<T>(value: T, interval = 500): T {
const [throttledValue, setThrottledValue] = useState<T>(value)
const lastExecuted = useRef<number>(Date.now())
useEffect(() => {
if (Date.now() >= lastExecuted.current + interval) {
lastExecuted.current = Date.now()
setThrottledValue(value)
@Alimjanov-Ibragim
Alimjanov-Ibragim / day_hours.json
Created May 17, 2023 07:22 — forked from wching/day_hours.json
JSON file with all hours in the day
[
{
"military_format": "0000",
"twenty_four_hour_format": "00:00",
"standard_format": "00:00",
"time_of_day":"md"
},
{
"military_format": "0030",
"twenty_four_hour_format": "00:30",
@Alimjanov-Ibragim
Alimjanov-Ibragim / useDebounce.js
Created March 27, 2023 08:49 — forked from ali-sabry/useDebounce.js
This hook will allow me to debounce any function that I want to run after a certain delay. For example, if I have an input field that triggers a search function on every keystroke, this hook will prevent unnecessary API calls by delaying the search function until the user stops typing for a certain period.
import { useState, useEffect } from 'react';
export const useDebounce = (value, delay) => {
const [debouncedValue, setDebouncedValue] = useState(value);
useEffect(() => {
const timer = setTimeout(() => {
setDebouncedValue(value);
}, delay);
@Alimjanov-Ibragim
Alimjanov-Ibragim / useMediaQuery.js
Created March 27, 2023 08:39 — forked from ali-sabry/useMediaQuery.js
This custom hook will allow me to easily check if the current screen size matches a specific media query (e.g., desktop or mobile). By using this hook, I can conditionally render components based on the screen size and optimize my app for different devices.
//=== Custom Hook useMediaQuery
import { useState, useEffect } from 'react';
export const useMediaQuery = (query) => {
const [matches, setMatches] = useState(false);
useEffect(() => {
const mediaQuery = window.matchMedia(query);
/* window.matchMedia() match if the media query you passed
is match with current media query and return boolean value

How to force a page to reload from server at browser launch with JavaScript

I spent weeks finding a way to refresh a page or a tab from the server once a user starts or restarts the browser. I was very surprised to find nothing about this topic.

Let's dig into the context, tries and the solution I came up with.

Context

Typically, once a user opens a browser and gets to a page, it directly provides the page in cache without refreshing any data from the server. Obviously, this only applies if the user is not in a private navigation.

In this case, as a user, I always need to open the browser and then manually reload the page to get the last updated data. What? Am I too lazy? Sure I am a developer!

@Alimjanov-Ibragim
Alimjanov-Ibragim / UA parser
Created June 24, 2022 05:37 — forked from KamaMakh/UA parser
Detect Browser, Engine, OS, CPU, and Device
export const isSafari = () => {
const ua = window.navigator.userAgent.toLowerCase();
return (
ua.includes('safari') &&
!ua.includes('crios') &&
!ua.includes('fxios') &&
!ua.includes('android')
);
};
@Alimjanov-Ibragim
Alimjanov-Ibragim / gist:b85929010fdef811ce5071f877949afd
Created December 21, 2021 07:10 — forked from borismus/gist:1032746
Convert a base64 string into a binary Uint8 Array
var BASE64_MARKER = ';base64,';
function convertDataURIToBinary(dataURI) {
var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
var base64 = dataURI.substring(base64Index);
var raw = window.atob(base64);
var rawLength = raw.length;
var array = new Uint8Array(new ArrayBuffer(rawLength));
for(i = 0; i < rawLength; i++) {
@Alimjanov-Ibragim
Alimjanov-Ibragim / netlify.toml
Created July 30, 2020 16:32 — forked from rickyhaswifi/netlify.toml
React Router Netlify - Fix for not found page
#https://stackoverflow.com/questions/58065603/netlify-renders-404-on-page-refresh-using-react-and-react-router
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
@Alimjanov-Ibragim
Alimjanov-Ibragim / sketch-never-ending.md
Created June 17, 2020 13:37 — forked from Bhavdip/sketch-never-ending.md
Modify Sketch to never ending trial

###Sketch trial non stop

Open hosts files:

$ open /private/etc/hosts

Edit the file adding:

127.0.0.1 backend.bohemiancoding.com

127.0.0.1 bohemiancoding.sketch.analytics.s3-website-us-east-1.amazonaws.com