Skip to content

Instantly share code, notes, and snippets.

View mannyyang's full-sized avatar

Manuel Yang mannyyang

View GitHub Profile
@mannyyang
mannyyang / tailwind-to-scss.js
Created October 25, 2018 23:59
Generating a SCSS color variable file from a Tailwind config file.
const fs = require('fs');
const path = require('path');
const TailwindConfig = require('./tailwind.config');
const colors = TailwindConfig.colors;
const outPath = path.join(__dirname, 'theme-variables.scss');
// If the file exists, delete it.
fs.unlink(outPath, err => {
if (err && err.code !== 'ENOENT') return console.error(err);
@mannyyang
mannyyang / .txt
Last active December 29, 2018 03:24
JS Comment Categories
When developing, it's always a good idea to create comments so future you and other developers can better understand the logic that was thought of at that moment in time. Since comments can be used for different reasons and be formatted differently as well, I figured it would be a good idea to use specific formats for different types of comments.
1. Function Declarations
The typical way of commenting function declarations with slash stars.
Example:
/**
* Map array items to work with select options.
*
* @param {Array} arr Array of items that have properties id and name
@mannyyang
mannyyang / theme.css
Created November 11, 2019 22:22
Generated CSS from Tailwinds
/**
* This injects Tailwind's base styles, which is a combination of
* Normalize.css and some additional base styles.
*
* You can see the styles here:
* https://github.com/tailwindcss/tailwindcss/blob/master/css/preflight.css
*
* If using `postcss-import`, use this import instead:
*
* @import "tailwindcss/preflight";
/**
* Feature Flags
*
* Settings to turn on a feature. Currently, Flags can be set through either a
* query param or from local storage.
*/
import env from '@beam-australia/react-env';
import UrlParse from 'url-parse';
import React, { useState } from 'react';
import {
ActionButton,
Text,
Toggle,
} from '@open-raven/react-styleguide';
import { Flex } from 'reflexbox';
import {
LOCAL_STORAGE_KEY,
getFlagsFromLocalStorage,
@mannyyang
mannyyang / firebase-token.js
Last active March 14, 2022 07:42
firebase cloudflare
import { getTokenFromGCPServiceAccount } from '@sagi.io/workers-jwt'
/**
* Getting the access token to use in the header.
*/
// For example's sake, the file contents (modified) from the private key has been
// listed below, but the recommended way would be to use environment variables.
export async function getAccessToken() {
const jwtToken = await getTokenFromGCPServiceAccount({
/**
* Update an existing document in a collection.
*/
export async function updateDocumentInCollection({ docID, title, published, modified }) {
const accessToken = await getAccessToken()
const response = await (
await fetch(
'https://firestore.googleapis.com/v1/projects/<PROJECTIDHERE>/databases/(default)/documents/<COLLECTIONNAME>/<DOCID>?updateMask.fieldPaths=title&updateMask.fieldPaths=published&updateMask.fieldPaths=modified',
{