-
These are not to be blindly followed; strive to understand these and ask
when in doubt. Sometimes standards are a bad idea. -
Don't duplicate the functionality of a built-in library.
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
export const chaosTestStrings = (): void => { | |
const textNodes = getAllTextNodes(document.body); | |
for (const node of textNodes) { | |
const textNodeLength = node.textContent ? node.textContent.length : 0; | |
if (node.textContent === null) { | |
return; | |
} | |
if (node.parentElement instanceof Element) { | |
if (node.parentElement.dataset.originalText === undefined) { |
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 React from "react"; | |
import { Link } from "react-router-dom"; | |
export function createResource(getPromise) { | |
let cache = {}; | |
let inflight = {}; | |
let errors = {}; | |
function load(key) { | |
inflight[key] = getPromise(key) |
I've been deceiving you all. I had you believe that Svelte was a UI framework — unlike React and Vue etc, because it shifts work out of the client and into the compiler, but a framework nonetheless.
But that's not exactly accurate. In my defense, I didn't realise it myself until very recently. But with Svelte 3 around the corner, it's time to come clean about what Svelte really is.
Svelte is a language.
Specifically, Svelte is an attempt to answer a question that many people have asked, and a few have answered: what would it look like if we had a language for describing reactive user interfaces?
A few projects that have answered this question:
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
// Adds a .catch to the express callback to handle errors that happen in async/await functions | |
// you should wrap every route with this handler | |
// ie: errorHandler((req, res) => res.send(JSON.stringify(res.locals.user))) | |
const errorHandler = fn => (req, res, next) => { | |
Promise.resolve(fn(req, res, next)) | |
.catch(error => { | |
if (process.NODE_ENV === 'development') console.log(require('util').inspect(error)) | |
next(error) | |
}) | |
} |
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
// In a Firestore standard example, we quickly create a 'xmas tree' of nested stuff | |
// We use Promises directly: get().then(callback) and use snapshot.forEach() to iterate | |
let campaignsRef = db.collection('campaigns'); | |
let activeCampaigns = campaignsRef.where('active', '==', true).select().get() | |
.then(snapshot => { | |
snapshot.forEach(campaign => { | |
console.log(campaign.id); | |
let allTasks = campaignsRef.doc(campaign.id).collection('tasks').get().then( | |
snapshot => { | |
snapshot.forEach(task => { |
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
/* | |
Using Cloud Functions, here's what I've come up with for anyone who wants to | |
add a timestamp field in a Firestore document. You need to have the Firebase Admin SDK installed in | |
addition to the general setup for Cloud Functions as detailed in the Firebase documentation. | |
*/ | |
const functions = require('firebase-functions'); | |
// The Firebase Admin SDK to access the Firebase Realtime Database. | |
const admin = require('firebase-admin'); |
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
from collections import OrderedDict | |
import graphene | |
import rx | |
subject = rx.subjects.Subject() | |
class Author(graphene.ObjectType): |
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
alias gits='git status -s' | |
alias gitl='git log --oneline' | |
alias gitc='git commit -m' | |
alias gita='git add --all' | |
alias gitp='git push -u origin master' | |
alias gitd='git diff' | |
alias gitpl='git pull' | |
alias gitpb='git push origin' |
NewerOlder