Skip to content

Instantly share code, notes, and snippets.

View samcorcos's full-sized avatar

Sam Corcos samcorcos

View GitHub Profile
const generateCalendar = (today: Date) => {
const daysInMonth = getDaysInMonth(today)
const firstDay = new Date(today.getFullYear(), today.getMonth()).getDay()
// in order to calculate how many calendar weeks there are (starting on Sunday), we can take
// days in the month and add first day + 1 to include the first week offset. returns an array
// that looks something like this:
// [undefined, undefined, undefined, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
const daysWithOffset = new Array(daysInMonth + firstDay).fill(undefined).map((v, i) => {
if (i < firstDay) {
{
"data": {
"metrics": [
{
"time": 1577905826702,
"value": 62
},
{
"time": 1577905886702,
"value": 62
import React from 'react'
import {SafeAreaView, View, Text} from 'react-native'
import Amplify from 'aws-amplify'
import awsconfig from './aws-exports'
import {withAuthenticator} from 'aws-amplify-react-native'
Amplify.configure(awsconfig)
const App = props => {
return (
@samcorcos
samcorcos / App.js
Last active December 15, 2019 00:46
import React from 'react'
import {SafeAreaView, View, Text} from 'react-native'
const App = props => {
return (
<SafeAreaView>
<View>
<Text>Home screen!</Text>
</View>
</SafeAreaView>
import React from 'react'
import { Context } from '../lib/context'
import { firebase, db } from '../lib/firebase'
import Data from '../components/Data'
export default class Home extends React.Component {
constructor (props) {
super(props)
this.state = {
import React from 'react'
/**
* The goal of this component is to wrap another component and give it some data from the
* database while maintaining state and bindings and significantly cutting down on
* boilerplate.
*
* This component expects a function
* See [this article](https://medium.com/merrickchristensen/function-as-child-components-5f3920a9ace9)
* for more information on why function-as-child components are awesome for this use case
import React from 'react'
import { Context } from '../lib/context'
import { firebase } from '../lib/firebase'
export default class Home extends React.Component {
constructor (props) {
super(props)
this.state = {
email: '',
...
import AuthBindings from '../components/AuthBindings
...
<>
<AuthBindings firebase={firebase} store={store} />
<Component store={store} {...pageProps} />
</>
...
import React from 'react'
/**
* A component that is used to bind the current user the store using Firebase
*
* @param {function} store.set - must receive a `store` prop that has a `set` function
* @param {Object} firebase - must receive an initialized `firebase` as a prop
*
* Render this alongside the top-level component of your app. Should only be rendered once.
*/
import React from 'react'
import App, { Container } from 'next/app'
import { firebase } from '../lib/firebase'
import { Context, Provider } from '../lib/context'
// Use this additional container to bind firebase auth listener to store
class _App extends App {
render () {
const { Component, pageProps } = this.props