This file contains hidden or 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 { ethers } from 'ethers'; | |
| const WEBSOCKET_PING_INTERVAL = 10000 | |
| const WEBSOCKET_PONG_TIMEOUT = 5000 | |
| const WEBSOCKET_RECONNECT_DELAY = 100 | |
| const WebSocketProviderClass = () => class {} | |
| export class WebSocketProvider extends WebSocketProviderClass() { | |
| events = [] |
This file contains hidden or 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 WebsocketStream { | |
| static EXPECTED_PONG_BACK = 10000; | |
| static KEEP_ALIVE_CHECK_INTERVAL = 5000; | |
| pingTimeout = null; | |
| keepAliveInterval = null; | |
| provider; | |
| providerWss; | |
| constructor() { | |
| this.provider = new ethers.providers.JsonRpcProvider( |
This file contains hidden or 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
| person.index({ firstName: 1, lastName: 1}, { unique: true }); |
This file contains hidden or 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
| db.table.aggregate([ | |
| { | |
| "$group": { | |
| _id: {slug: "$slug"}, | |
| slugs: { $addToSet: "$_id" } , | |
| count: { $sum : 1 } | |
| } | |
| }, | |
| { | |
| "$match": { |
This file contains hidden or 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
| async function fetchUserResources() { | |
| const [posts, photos, todos] = await Promise.allSettled([ | |
| fetch('https://jsonplaceholder.typicode.com/posts/1'), | |
| fetch('https://jsonplaceholder.typicode.com/photos/1'), | |
| fetch('https://jsonplaceholder.typicode.com/todos/1') | |
| ]); | |
| console.log(posts); | |
| // {status: "fulfilled", value: {"holds_the_posts_object"}} | |
This file contains hidden or 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 almostIncreasingSequence(sequence) { | |
| var found = false; | |
| for (var i=0;i<sequence.length;i++) { | |
| if(sequence[i] <= sequence[i-1]) { | |
| if(found) { | |
| return false; | |
| } | |
| found = true; | |
| if(i === 1 || i + 1 === sequence.length) { |
This file contains hidden or 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 functions from the package | |
| import { SitemapStream, streamToPromise } from "sitemap"; | |
| // A custom function I use to fetch data from a backend. I will keep the import to make it more clear why "graphlqlFetch" is used in the code | |
| import graphlqlFetch from "lib/apollo" | |
| export default async (req, res) => { | |
| // Fetch data from a source which will be used to render the sitemap. | |
| const { posts } = await graphlqlFetch(` | |
| query getSitemapData { |
This file contains hidden or 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 { useRef, useEffect, useState } from 'react' | |
| import { createPortal } from 'react-dom' | |
| export default function ClientOnlyPortal({ children, selector }) { | |
| const ref = useRef() | |
| const [mounted, setMounted] = useState(false) | |
| useEffect(() => { | |
| ref.current = document.querySelector(selector) | |
| setMounted(true) |
This file contains hidden or 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 { | |
| ADD_INGREDIENT, | |
| INGREDIENTS_REDUCER, | |
| PREPARING_REDUCER, | |
| REMOVE_INGREDIENT, | |
| SET_INGREDIENT_INPUT_VALUE, SET_INPUT_VALUE, SET_OPTIONAL, | |
| SET_SELECTED_INGREDIENT, | |
| } from "Store/add-new-dish/types"; | |
| const useAddNewDishActions = dispatch => { |
This file contains hidden or 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
| // Node | |
| headers.set('Authorization', 'Basic ' + Buffer.from(username + ":" + password).toString('base64')); | |
| // Browser | |
| headers.set('Authorization', 'Basic ' + btoa(username + ":" + password)); |
NewerOlder