Skip to content

Instantly share code, notes, and snippets.

@jozan
jozan / getEnv.ts
Created December 4, 2020 09:20
Get environment value by key
type Env<T> = T extends undefined ? string | undefined : T | string
export function getEnv<R = string | undefined>(
key: string,
defaultValue?: R
): Env<R> {
const envValue = process.env[key]
if (typeof envValue === 'undefined' && typeof defaultValue !== 'undefined') {
return defaultValue as Env<R>
}
@jozan
jozan / machine.js
Created December 2, 2019 08:04
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@jozan
jozan / machine.js
Last active December 2, 2019 09:32
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
@jozan
jozan / Customization.js
Created October 4, 2018 18:58
Gestures
import React from 'react';
import { View, Text, StyleSheet, Animated } from 'react-native';
import Draggable from './Draggable';
export default class Customization extends React.Component {
swags = [
{
content: '🕶',
position: { x: 0, y: 0 },
rotation: 0,
@jozan
jozan / index.js
Last active August 20, 2018 17:22
Sign in silently
class GoogleSigninSampleApp extends Component {
state = {
userInfo: undefined,
error: undefined
}
async componentDidMount() {
this.configureGoogleSignIn()
await this.signInSilently()
}
@jozan
jozan / index.js
Last active August 20, 2018 17:22
Handle sign out
class GoogleSigninSampleApp extends Component {
state = {
userInfo: undefined,
error: undefined
}
async componentDidMount() {
this.configureGoogleSignIn()
}
@jozan
jozan / index.js
Last active August 20, 2018 17:23
Show error message
class GoogleSigninSampleApp extends Component {
state = {
userInfo: undefined,
error: undefined
}
async componentDidMount() {
this.configureGoogleSignIn()
}
@jozan
jozan / index.js
Last active August 20, 2018 17:23
Show user details
class GoogleSigninSampleApp extends Component {
state = {
userInfo: undefined,
error: undefined
}
async componentDidMount() {
this.configureGoogleSignIn()
}
@jozan
jozan / index.js
Last active August 20, 2018 17:23
Handle errors
class GoogleSigninSampleApp extends Component {
state = {
userInfo: undefined,
error: undefined
}
async componentDidMount() {
this.configureGoogleSignIn()
}
@jozan
jozan / index.js
Last active August 20, 2018 17:23
Store sign in data
class GoogleSigninSampleApp extends Component {
state = {
userInfo: undefined
}
async componentDidMount() {
this.configureGoogleSignIn()
}
async configureGoogleSignIn() {