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 { useEffect, useRef } from "react"; | |
const useClickAwayListener = <T extends HTMLElement = HTMLDivElement>(callback: VoidFunction) => { | |
const ref = useRef<T>(null); | |
useEffect(() => { | |
const handleClick = (event: MouseEvent) => { | |
const target = event.target as T; | |
if (event.target !== ref.current) { |
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
// @ts-check | |
import { completeAuth, initiateAuth } from "./server.mjs"; | |
import { getClientKeyAndHash, getHMAC, getRandomBytes, hashPassword, xorBuffer } from "./utils.mjs"; | |
/** | |
* @param {string} username | |
* @param {string} password | |
*/ | |
export async function clientAuthentication(username, password) { |
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
/** | |
* Fancy ID generator that creates 20-character string identifiers with the following properties: | |
* | |
* 1. They're based on timestamp so that they sort *after* any existing ids. | |
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs. | |
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly). | |
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the | |
* latter ones will sort after the former ones. We do this by using the previous random bits | |
* but "incrementing" them by 1 (only in the case of a timestamp collision). | |
*/ |
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
use futures::StreamExt; | |
use std::error::Error; | |
use tokio; | |
use tokio::macros::support::Pin; | |
use tokio::prelude::*; | |
use tokio::time::{Duration, Instant}; | |
pub fn main() -> Result<(), Box<dyn std::error::Error>> { | |
let mut multi_threaded_runtime = tokio::runtime::Builder::new() | |
.threaded_scheduler() |
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
const express = require("express"); | |
const cluster = require("cluster"); | |
const totalCPUs = require("os").cpus().length; | |
const port = 3000; | |
if (cluster.isMaster) { | |
console.log(`Number of CPUs is ${totalCPUs}`); | |
console.log(`Master ${process.pid} is running`); |
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
/** Continuous windows as in carousel */ | |
export const getWindows = <T>(data: T[], size = 5) => ({ | |
acc: 0, | |
*[Symbol.iterator]() { | |
const length = data.length; | |
const array: T[] = []; | |
for (let i = 0; i < size; ++i) { | |
array.push(data[this.acc + i >= length ? this.acc + i - length : this.acc + i]); | |
} | |
if (this.acc >= length) this.acc = 1; |
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 type { Reducer } from 'react' | |
import { Fragment, useReducer } from 'react' | |
interface IReducerState { | |
name: string | |
age: number | |
} | |
type IReducerAction = | |
| { |
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 { useEffect, useRef, useState } from 'react' | |
import { minPanelWidth } from '@/constants' | |
import style from './styles.module.less' | |
interface ISplitViewProps { | |
leftChild: React.ReactNode | |
rightChild: React.ReactNode | |
} | |
const SplitView: React.FC<ISplitViewProps> = ({ leftChild, rightChild }) => { |
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.4; | |
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | |
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; | |
import "@openzeppelin/contracts/security/Pausable.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
contract MyToken is ERC20, ERC20Burnable, Pausable, Ownable { | |
constructor() ERC20("MyToken", "MTK") {} |
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
const INT_MAX = ~(1 << (32 - 1)) | |
const ITSAKINDOFMAGIC = [ | |
0x3, | |
0x6, | |
0x9, | |
0x1d, | |
0x36, | |
0x69, | |
0xa6, // 2 to 8 |
NewerOlder