Skip to content

Instantly share code, notes, and snippets.

View xiaoyunyang's full-sized avatar
🎯
Focusing

Xiaoyun Yang xiaoyunyang

🎯
Focusing
View GitHub Profile
@xiaoyunyang
xiaoyunyang / dev-secret-best-practice.md
Last active July 18, 2023 20:25
How to keep dev secrets

Instead of always running source .env before running yarn, you can add your dev secrets like NPM_TOKEN or OPEN_AI_API_KEY to a global dev environmental variable file on your machine (e.g. dev.env) then add this to your .bashrc to source it on startup:

# dev.env
export NPM_TOKEN=<create one in npm settings>
# bashrc
source ~/dev.env
@xiaoyunyang
xiaoyunyang / install-nvm-on-a-mac.md
Last active July 11, 2023 22:25
How to install and use `nvm` on a Mac

What is nvm?

nvm is a version manager for node.js which lets you easily switch between different node versions. You can define an .nvmrc file in your node project which enforces the node version standardization with your codebase collaborators.

Install NVM

Install

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
import React, { useState } from "react";
const UiState = {
LOADING: "LOADING",
ONLINE: "ONLINE",
OFFLINE: "OFFLINE",
};
const UiStateMessageMap = {
[UiState.LOADING]: "Loading...",
import React, { useState } from "react";
function FriendStatus(props) {
const [isOnline, setIsOnline] = useState(null);
useEffect(() => {
function handleStatusChange(status) {
setIsOnline(status.isOnline);
}
ChatAPI.subscribeToFriendStatus(props.friend.id, handleStatusChange);
function foo() {
let res = ''
let j = 10
for(let i=0; i<j; i++) {
// uncommenting ... the following line causes error
// var j = 5
res += `${j}, `
j -= 1
}
@xiaoyunyang
xiaoyunyang / ts-v-js.md
Created July 25, 2019 02:59
TypeScript vs JavaScript example

The example is taken from TypeScript's quick start tutorial

In JavaScript

const greeter = (person) => "hello "+person;
greeter([1,2,3]) // "hello 1,2,3"

In TypeScript

@xiaoyunyang
xiaoyunyang / TypeScriptMigration.md
Last active April 16, 2022 14:02
A guide for how to migrate your project from Flow to TypeScript
@xiaoyunyang
xiaoyunyang / testingJest.md
Created July 3, 2019 17:28
Testing With Jest

What to Test

Testing interfaces

  • Child component with the right props
import EditProfileForm from "../feedbackForm";
import Checkbox from "../checkbox";
import EmailInput from "../EmailInput";