This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Shortcut function to create and return a DOM element | |
*/ | |
function domEl(tag: string, attributes: { [key: string]: any } = {}, children: any[] = []) { | |
const el = document.createElement(tag); | |
for (const attr in attributes) { | |
if (attr === 'text') { | |
el.appendChild(document.createTextNode(attributes[attr])); | |
continue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { GetServerSidePropsContext } from 'next'; | |
import React from 'react'; | |
import AuthLayout from 'src/layouts/AuthLayout'; | |
import AlertErrors from 'src/components/AlertErrors'; | |
import { addRequestBody } from 'src/server/bodyParser'; | |
import { userLogin, userSessionInsert } from 'src/server/queries'; | |
import { redirectUserToApp, setUserAuthCookie } from 'src/server/auth'; | |
import Link from 'next/link'; | |
// Types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { FormEvent } from 'react'; | |
export type onFormSubmit = (e: FormEvent, data: { [key: string]: any}) => void | |
export type ApiFormProps = { | |
children: any, | |
onSubmit: onFormSubmit, | |
[key: string]: any, // Allows any other props to be passed through to element | |
} | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sheetQuery() | |
.from('Transactions') | |
.insertRows([ | |
{ | |
Amount: -554.23, | |
Name: 'BigBox, inc.' | |
}, | |
{ | |
Amount: -29.74, | |
Name: 'Fast-n-greasy Food Spot' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Delete specific matching rows | |
sheetQuery() | |
.from('Transactions') | |
.where(row => row.Category === 'DELETEME') | |
.deleteRows(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Update rows with criteria | |
sheetQuery() | |
.from('Transactions') | |
.where(row => row.Business.toLowerCase().includes('starbucks')) | |
.updateRows(row => { | |
row.Category = 'Coffee Shops' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const query = sheetQuery() | |
.from('Transactions') | |
.where(row => row.Category === 'Shops'); | |
const data = query.getRows(); // Array of objects, i.e. [ { Name: "Somestore", Amount: 45.29, Category: "Shops" } ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
let pathToRegexp = require('path-to-regexp'); | |
let defaultRoute; | |
let routes = []; | |
/** | |
* GET route | |
* | |
* @param {String} pattern - Express.js style route pattern or bare URL string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ES5 way | |
t: function () { | |
let key = _.first(arguments); | |
let replacements = _.rest(arguments); | |
let translation = translations[key]; | |
if (translation && replacements.length) { | |
translation = format.apply(null, [translation].concat(replacements)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// stuff | |
function slug (title) { | |
// do something | |
} | |
slug('Some Post'); | |
class Post { | |
slug () { |
NewerOlder