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 ID = () => (Date.now() + Math.random().toString(36) | |
.substr(2, 9)) | |
.split('') | |
.sort(() => (0.5 > Math.random() ? -1 : 1)) | |
.join(''); | |
const createFixedLengthID = (length) => ID().padStart(length, ID()) |
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 { useState, useEffect, useRef, EffectCallback } from 'react'; | |
import throttle from 'lodash/throttle'; | |
import debounce from 'lodash/debounce'; | |
// Ties two states together, and tracks only if a specific case occur. | |
export const transitionTracker = <A, B>(from: A, to: B) => { | |
let marker = 0; | |
return (state1: A, state2: B) => { | |
if (from === state1 && to === state2) { |
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
// These are some nice-to-have utilies which js doesn't provide by default | |
// creates an array of numbers as [m..n] | |
const range = (m: number, n: number): number[] => Array.from(Array(n - m + 1).keys()).map(n => n + m) | |
// combines functions from right to left (opposite of pipe) | |
const compose = <R>(fn1: (a: R) => R, ...fns: Array<(a: R) => R>) => | |
fns.reduce((prevFn, nextFn) => value => prevFn(nextFn(value)), fn1); | |
// if `value` is anything other than a number this is an identity, and modulus otherwise |
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
module Main where | |
import Prelude (bind, mod, pure, (<$>), (<<<), (==)) | |
import Data.List (List, (..)) | |
import Data.Either (Either(..)) | |
isDivisibleBy :: Int -> String -> Either String Int -> Either String Int | |
isDivisibleBy divider replacer value = do | |
v <- value | |
if mod v divider == 0 |
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
// How many steps a Knight takes on an infinite chessboard from O(0,0) to P (x,y) | |
// With O(1) time complexity | |
const knightsMetric = (x, y) => { | |
let normalizedX = Math.abs(x); | |
let normalizedY = Math.abs(y); | |
// Normailze coordinates, so that 0 <= y <= x | |
if(normalizedX < normalizedY) { | |
[normalizedY, normalizedX] = [normalizedX, normalizedY] |
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
// Simple implementation of [].reduce | |
Array.prototype.myReduce = function (reducer, initialValue) { | |
let result = initialValue | |
this.forEach(item => { | |
result = reducer(result, item) | |
}) | |
return result |
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
.hamburger { | |
display: flex; | |
flex-direction: column; | |
cursor: pointer; | |
} | |
.bar { | |
margin: 2px; | |
width: 24px; | |
height: 4px; |
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 range = (m: number, n: number): number[] => Array.from(Array(n - m + 1).keys()).map(n => n + m) | |
const isEvil = (n: number): boolean => ( | |
n.toString(2).split('').filter((x) => x === '1').length % 2 == 0 | |
) | |
range(0, 50).filter(isEvil) | |
console.log(range(0,50).filter(isEvil).join('\n')) |
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
from functools import reduce | |
def compose2(f, g): | |
return lambda *a, **kw: f(g(*a, **kw)) | |
def compose(*fs): | |
return reduce(compose2, fs) | |
def safeMod(input, divider): | |
return input % divider if type(input) == int else input |
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.17; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
import "@openzeppelin/contracts/utils/math/Math.sol"; | |
import "@openzeppelin/contracts/utils/Strings.sol"; | |
import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol"; | |
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol"; | |
import "./interfaces/IMetaData.sol"; |
OlderNewer