Skip to content

Instantly share code, notes, and snippets.

View crashmax-dev's full-sized avatar
:octocat:
Meow

Vitalij Ryndin crashmax-dev

:octocat:
Meow
  • Russia
  • 05:48 (UTC +03:00)
View GitHub Profile
@epicbytes
epicbytes / example.api.ts
Last active January 20, 2025 20:45
NextJS Authorization Files
/*** function that used as middleware ***/
accessToken: async (name) => {
if (typeof document === "undefined") return "";
let token = document.cookie
.split(";")
.filter((cookie) => cookie.startsWith("token"))[0];
if (!token) {
const response = await fetch("/api/refresh", { method: "POST" });
{"version":2,"type":"full","values":{"exp-lock":1658571974582,"p:0:chat.filtering.highlight-mentions":true,"p:0:tooltip.badge-images":false,"p:0:player.vod.autoplay":false,"p:0:player.home.autoplay":false,"p:0:chat.badges.hidden":{"1":false,"2":true,"3":false},"profiles":[{"id":1,"name":"Moderation","i18n_key":"setting.profiles.moderation","description":"Settings that apply when you are a moderator of the current channel.","context":[{"type":"Moderator","data":true}],"uuid":"ffz_profile_moderation"},{"id":0,"name":"Default Profile","i18n_key":"setting.profiles.default","description":"Settings that apply everywhere on Twitch.","uuid":"ffz_profile_default"}],"p:0:chat.emote-menu.icon":false,"p:0:channel.auto-click-chat":true,"p:0:channel.auto-skip-trailer":true,"p:0:chat.delay":0,"p:0:chat.emote-menu.show-search":false,"p:0:addon.seventv_emotes.unlisted_emotes":true,"cfg-seen":["i18n.debug.capture","i18n.debug.transform","i18n.locale","i18n.format.date","i18n.format.time","i18n.format.datetime","data.use-stagin
@mmazzarolo
mmazzarolo / localstorage-error-handling.ts
Created June 29, 2022 16:49
Handling localStorage errors (such as quota exceeded errors)
/**
* Determines whether an error is a QuotaExceededError.
*
* Browsers love throwing slightly different variations of QuotaExceededError
* (this is especially true for old browsers/versions), so we need to check
* different fields and values to ensure we cover every edge-case.
*
* @param err - The error to check
* @return Is the error a QuotaExceededError?
*/
@mmazzarolo
mmazzarolo / fill-localstorage.ts
Last active April 2, 2023 14:00
Using JavaScript to fill localStorage to its maximum capacity
/**
* Fill localStorage to its maximum capacity.
*
* First, we find the highest order bit (the bit with the highest place value)
* that fits in localStorage by storing localStorage an increasingly big
* string of length 2, 4, 8, 16, etc. until it won't fill localStorage anymore.
*
* By working in iterations, starting with very long strings, and storing data
* in different items, we can keep a low memory profile and reduce the number of
* writes — making this process pretty fast.
@SergProduction
SergProduction / use-date.ts
Last active June 14, 2022 17:51
date react hook convertation string to Date object
import React, { useState } from 'react'
const Nothing = Symbol()
const normDoubleSymbol = (strOrNumber: string | number) => strOrNumber.toString().length === 1
? `0${strOrNumber}`
: strOrNumber.toString()

Что не так с enum в typescript

Вводная

Я никак не могу обойти тему того чем является тайпскрипт, и чем он должен был быть.

"TypeScript is JavaScript with syntax for types." www.typescriptlang.org

Это именно то что отличает тайпскрипт он кофескриптов, эльмов, ризонов и т.д. Все что нужно чтобы получить javascript - убрать аннотации типов. В вебе, где размер бандла одна из ключевых метрик, это - киллер фича.

@crashmax-dev
crashmax-dev / disable-antizapret.reg
Last active July 24, 2023 09:36
Antizapret (Windows)
Windows Registry Editor Version 5.00
;=== Disable ===
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"AutoConfigURL"=-
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap]
"ProxyBypass"=dword:00000001
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1]
@crashmax-dev
crashmax-dev / extensions.md
Last active November 5, 2022 10:34
VS Code Extensions

How to install

code --install-extension aaron-bond.better-comments
code --install-extension Angular.ng-template
code --install-extension bradlc.vscode-tailwindcss
code --install-extension csstools.postcss
code --install-extension dbaeumer.vscode-eslint
code --install-extension EditorConfig.EditorConfig
code --install-extension esbenp.prettier-vscode
/**
* GlobalsDebugger
*
* Inspect the stack when a global variable is being set on the window object.
* Given a global variable name, it proxies the variable name in the window
* object adding some custom code that will be invoked whenever the variable
* is set. The custom code will log the current stack trace and halt the code
* execution to allow inspecting the stack and context in your browser DevTools.
* You can use the "globalsToInspect" query-parameter to set a comma-separated
* list of names of the variables you want to inspect.
@mmazzarolo
mmazzarolo / runtime-globals-checker.js
Last active June 8, 2023 14:27
Find what JavaScript variables are leaking into the global `window` object at runtime (see: https://mmazzarolo.com/blog/2022-02-14-find-what-javascript-variables-are-leaking-into-the-global-scope/)
/**
* RuntimeGlobalsChecker
*
* You can use this utility to quickly check what variables have been added (or
* leaked) to the global window object at runtime (by JavaScript code).
* By running this code, the globals checker itself is attached as a singleton
* to the window object as "__runtimeGlobalsChecker__".
* You can check the runtime globals programmatically at any time by invoking
* "window.__runtimeGlobalsChecker__.getRuntimeGlobals()".
*