Skip to content

Instantly share code, notes, and snippets.

@sibelius
sibelius / FeatureFlag.tsx
Created May 6, 2020 12:33
Basic Feature Flag implementation using React.Context
import React, { useContext, useCallback } from 'react';
export const FeatureFlagContext = React.createContext<string[]>([]);
export const useFeatureFlag = () => {
const features = useContext<string[]>(FeatureFlagContext);
const hasFeature = useCallback(
(feature: string) => {
return features.includes(feature);
@sibelius
sibelius / useFastField.tsx
Last active May 10, 2023 04:07
useFastField that uses local state `onChange` and sync back to formik only `onBlur`
import React, { useState, useEffect } from 'react';
import { useField, FieldHookConfig, FieldInputProps, FieldMetaProps, FieldHelperProps } from 'formik';
import { useDebouncedCallback } from 'use-debounce';
const DEBOUNCE_DELAY = 300;
export function useFastField<Val = any>(
propsOrFieldName: string | FieldHookConfig<Val>,
): [FieldInputProps<Val>, FieldMetaProps<Val>, FieldHelperProps<Val>] {
const [field, meta, helpers] = useField<Val>(propsOrFieldName);
// copy this massive script in your console on the github page where the calendar is shown
// copy this massive script in your console on the github page where the calendar is shown
// copy this massive script in your console on the github page where the calendar is shown
// threejs.org/license
(function(k,ua){"object"===typeof exports&&"undefined"!==typeof module?ua(exports):"function"===typeof define&&define.amd?define(["exports"],ua):(k=k||self,ua(k.THREE={}))})(this,function(k){function ua(){}function v(a,b){this.x=a||0;this.y=b||0}function ya(){this.elements=[1,0,0,0,1,0,0,0,1];0<arguments.length&&console.error("THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.")}function W(a,b,c,d,e,f,g,h,l,m){Object.defineProperty(this,"id",{value:ej++});this.uuid=O.generateUUID();
this.name="";this.image=void 0!==a?a:W.DEFAULT_IMAGE;this.mipmaps=[];this.mapping=void 0!==b?b:W.DEFAULT_MAPPING;this.wrapS=void 0!==c?c:1001;this.wrapT=void 0!==d?d:1001;this.magFilter=void 0!==e?e:1006;this.mi
@AndrewIngram
AndrewIngram / schema.graphql
Last active January 7, 2021 11:05
Derived Dribbble Scema
# Not everything is defined here, just what was mentioned in the article
type User {
id: ID!
name: String!
avatar: Image!
isPro: Boolean!
viewerHasFollowed: Boolean!
shots(exclude: ID): ShotConnection!
}
@marcospassos
marcospassos / tailwindui-toast-animation.html
Last active July 8, 2020 02:52
Tailwind Toast annimation
<!--
Smoothie sliding up toast animation
Entering: "ease-out duration-300 transition transform"
From: "opacity-0 translate-y-2 sm:translate-y-0 sm:translate-x-2"
To: "opacity-100 translate-y-0 sm:translate-x-0"
Leaving: "ease-in-out duration-300 transition-all transform"
onExit: node => node.style.maxHeight = node.getBoundingClientRect().height
From: "opacity-100 opacity-100 mb-5 translate-y-0 sm:translate-x-0"
onExiting={node => node.style.maxHeight = ''}
@jthoms1
jthoms1 / styles.d.ts
Created July 21, 2020 03:01
Much better way of using tokens in Styled Components
import { ThemeType } from 'some/path/to/my/tokens';
import 'styled-components';
declare module 'styled-components' {
export interface DefaultTheme extends ThemeType {}
}
@sibelius
sibelius / filterAsync.ts
Created July 29, 2020 12:31
Simple filter async
function mapAsync<T, U>(array: T[], callbackfn: (value: T, index: number, array: T[]) => Promise<U>): Promise<U[]> {
return Promise.all(array.map(callbackfn));
}
async function filterAsync<T>(array: T[], callbackfn: (value: T, index: number, array: T[]) => Promise<boolean>): Promise<T[]> {
const filterMap = await mapAsync(array, callbackfn);
return array.filter((value, index) => filterMap[index]);
}
@kentcdodds
kentcdodds / add-discord-role.js
Last active August 21, 2021 16:29
An example of how you can add a role to a user with discord.js
const Discord = require('discord.js')
// your bot token
const token = 'NzM4MDk2NjA4NDQwNDgzODcw.XyG8CA.RbwIBFnAbrRDYOlTdLYgG_T4CMk'
const discordUsername = 'example#1234'
const roleToAdd = 'Cool Person'
const guildName = 'Your Guild Name'
function deferred() {
let resolve, reject
@victor3r
victor3r / startup.sh
Last active October 14, 2020 17:34
sudo apt-get update
echo 'installing curl'
sudo apt install curl -y
echo 'installing git'
sudo apt-get install git -y
echo "What name do you want to use in GIT user.name?"
read git_config_user_name