Skip to content

Instantly share code, notes, and snippets.

View CharlyJazz's full-sized avatar
🧭
I may be slow to respond.

Carlos Azuaje CharlyJazz

🧭
I may be slow to respond.
View GitHub Profile
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) {
@slorber
slorber / react-navigation-tree.jsx
Last active August 13, 2022 19:17
react-navigation-tree.jsx
const App = createAppContainer(
createStack({
LoggedSwitch: createSwitch({
// When user is authenticated
LoggedIn: createStack({
// The logged in root is generally a tab or drawer navigator
LoggedInRoot: createTabsOrDrawer({
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)
@Rich-Harris
Rich-Harris / what-is-svelte.md
Last active March 27, 2024 06:09
The truth about Svelte

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:

@lucas-janon
lucas-janon / asyncErrorHandler.js
Created June 12, 2018 01:10
Async/Await wrapper for express routes (to avoid try/catching every route)
// 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)
})
}
@vladfr
vladfr / 1-standard.js
Last active May 9, 2023 07:34
Use async/await and for..of in Cloud Firestore
// 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 => {
@rayfarer
rayfarer / script.js
Created April 1, 2018 15:47
Add Timestamp When Document Created Firestore
/*
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');
@dfee
dfee / graphene_subscription.py
Created November 25, 2017 03:17
Example of how subscriptions work with graphene
from collections import OrderedDict
import graphene
import rx
subject = rx.subjects.Subject()
class Author(graphene.ObjectType):
@rich-97
rich-97 / git_alias.sh
Last active March 3, 2018 12:09
Common alias for Git.
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'