This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useSyncExternalStore } from "react"; | |
// For more on the useSyncExternalStore hook, see https://react.dev/reference/react/useSyncExternalStore | |
// The code is almost identical to the source code of zustand, without types and some features stripped out. | |
// Check the links to see the references in the source code. | |
// The links are referencing the v5 of the library. If you plan on reading the source code yourself v5 is the best way to start. | |
// The current v4 version contains lot of deprecated code and extra stuff that makes it hard to reason about if you're new to this. | |
// https://github.com/pmndrs/zustand/blob/fe47d3e6c6671dbfb9856fda52cb5a3a855d97a6/src/vanilla.ts#L57-L94 | |
function createStore(createState) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function countShips(B) { | |
const result = [0, 0, 0]; | |
const map = B.map(row=>row.split('')); | |
const n = map.length; | |
const m = map[0].length; | |
for (let row = 0; row < n; row++) { | |
for (let col = 0; col < m; col++) { | |
if (map[row][col] === '#') { | |
map[row][col] = '.'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Service-worker demo</title> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<script> | |
if ( "serviceWorker" in navigator ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"name": "Sport", | |
"logo": "https://i.imgur.com/LTdCdqy.png", | |
"version": 1, | |
"searchable": False, | |
"sites": [ | |
{ | |
"name": "90p.live", | |
"logo": "https://i.imgur.com/jyM3inb.png", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
method1(p1, p2) { | |
this.p1 = p1; | |
this.p2 = p2; | |
} | |
method2(p3) { | |
this.p3 = p3; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @ts-ignore | |
import { v4 as uuid, validate as validateUUID } from "uuid"; | |
type Topic = string; | |
type Message = Record<string, unknown>; | |
type ID = string; | |
type OnMessageFn = (message: Message) => void; | |
export type Subscribe = (topic: Topic, onMessage: OnMessageFn) => ID; | |
export type Publish = (topic: Topic, message: Record<string, unknown>) => void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"prettier.printWidth": 100, | |
"prettier.singleQuote": true, | |
"emmet.includeLanguages": { | |
"postcss": "css", | |
"javascript": "javascriptreact" | |
}, | |
"emmet.syntaxProfiles": { | |
"postcss": "css" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://marketplace.visualstudio.com/items?itemName=dozerg.tsimportsorter | |
{ | |
"tsImportSorter.configuration.groupRules": [ | |
[ | |
"^react-*", | |
{} | |
], | |
"^[@]", | |
"^pages", | |
"^components", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Implements React Routing in Plain React, without reliance | |
on React-Router or any other libraries. | |
To use: | |
In your top-level React Component (e.g. App or Index.js): | |
- Import Router (e.g.: import Router from './Router') | |
- Create a const with your routes and their associated component | |
- Create a const with the component to show on urls not routed (i.e. 404 page) | |
- Return a Router component as the top-level component of your App | |
Example: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const invariant = (condition, format, ...args) => { | |
if (!condition) { | |
if (!format) { | |
throw new Error('General error occured.'); | |
} | |
let i = 0; | |
throw new Error(format.replace(/%s/g, () => args[i++])); | |
} |
NewerOlder