Skip to content

Instantly share code, notes, and snippets.

View tsaiDavid's full-sized avatar
⌨️
:imap kj <Esc>

David Tsai tsaiDavid

⌨️
:imap kj <Esc>
View GitHub Profile
@jaredpalmer
jaredpalmer / forwardRefWithAs.tsx
Created February 26, 2020 14:56
forwardRefWithAs
import * as React from 'react';
/**
* React.Ref uses the readonly type `React.RefObject` instead of
* `React.MutableRefObject`, We pretty much always assume ref objects are
* mutable (at least when we create them), so this type is a workaround so some
* of the weird mechanics of using refs with TS.
*/
export type AssignableRef<ValueType> =
| {
@swyxio
swyxio / createCtx-noNullCheck.tsx
Last active May 4, 2023 02:15
better createContext APIs with setters, and no default values, in Typescript. this is documented in https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/blob/master/README.md#context
// create context with no upfront defaultValue
// without having to do undefined check all the time
function createCtx<A>() {
const ctx = React.createContext<A | undefined>(undefined)
function useCtx() {
const c = React.useContext(ctx)
if (!c) throw new Error("useCtx must be inside a Provider with a value")
return c
}
return [useCtx, ctx.Provider] as const
@developit
developit / *valoo.md
Last active November 13, 2023 08:39
🐻 Valoo: just the bare necessities of state management. 150b / 120b. https://npm.im/valoo

🐻 valoo

just the bare necessities of state management.

Usage

Hotlink it from https://unpkg.com/valoo.

See Interactive Codepen Demo.

@stolinski
stolinski / mockMang.js
Created April 9, 2018 17:27
Level Up Tutorials MockMang
import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools';
import { graphql } from 'graphql';
import GraphQLMock from 'graphql-mock';
import typeDefs from 'imports/startup/both/typeDefs';
// Make a GraphQL schema with no resolvers
const schema = makeExecutableSchema({ typeDefs });
// Creates random id
const revisedRandId = () =>
anonymous
anonymous / HelloWorld.sol
Created February 2, 2018 05:04
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.19+commit.c4cbbb05.js&optimize=false&gist=
pragma solidity ^0.4.19;
contract HelloWorld {
string defaultResponse = "Hello to a decentralized world!";
function getResponse(string here) public returns (string) {
return here;
}
}
@carlosgruiz-dev
carlosgruiz-dev / Bookmarks.markdown
Last active February 19, 2023 22:36
Bookmarks

A

  • A bit of Vim - a book which aims to help you to learn how to use the Vim editor.
  • A.W.E.S.O.M. O - The really big list of really interesting open source projects.
  • AMP Project - The project enables the creation of websites and ads that are consistently fast, beautiful and high-performing across devices and distribution platforms.
  • APE - Angular JS REST Client.
  • ASCII Art - Real-Time ASCII Art Rendering Library
  • AST Explorer - A web tool to explore the ASTs generated by various parsers.
  • Advanced Bash-Scripting Guide - An in-depth exploration of the art of shell scripting by Mendel Cooper.
  • Advent of Code - is a series of small programming puzzles for a variety of skill levels.
@romainl
romainl / epictetus.adoc
Created November 23, 2015 22:25 — forked from dahu/epictetus.adoc
Epictetus quotes

Epictetus

Philosophy is a way of life and not just a theoretical discipline.

Epictetus (55 — 135 AD) was a Greek slave of Rome. He became a great Stoic philosopher and teacher, and was eventually freed.

Although he was a fatalist, he believed that individuals are responsible for their own actions, which they can examine and control through rigorous self-discipline.

@paulirish
paulirish / what-forces-layout.md
Last active July 22, 2024 06:32
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@jbergler
jbergler / .gitignore
Last active April 9, 2024 19:49
Acestream on Mac
.vagrant
@bsweger
bsweger / useful_pandas_snippets.md
Last active April 19, 2024 18:04
Useful Pandas Snippets

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)