Skip to content

Instantly share code, notes, and snippets.

@tiffwu
tiffwu / tiffany.js
Created October 18, 2019 18:48
event aggregator
const VALID_EVENTS = ["searchChanged", "jobViewed", "applicationSubmitted"];
async function process(api) {
try {
const events = await api("GET", "/events");
const { invalid, counts } = categorizeEvents(events);
await Promise.all([
api("POST", "/counts", counts),
api("POST", "/invalid", invalid)
@tiffwu
tiffwu / cloudSettings
Last active August 20, 2020 18:56
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-08-20T18:56:23.589Z","extensionVersion":"v3.4.3"}
@tiffwu
tiffwu / react-form-with-react-select.jsx
Created November 20, 2017 21:40
react-form wrapper for async react-select component
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { FormField } from 'react-form';
import Select from 'react-select';
import 'react-select/dist/react-select.css';
// WIP custom message component
const Message = ({ color, message }) => (
<div style={{ color }}>
<small>{JSON.stringify(message)}</small>
<div id="tl_ad"></div>
<script>
try {
var inv_code = "";
var settings = { domain: "%%PATTERN:domain%%", ctype: "%%PATTERN:ctype%%", plat: "%%PATTERN:plat%%", id: "%%PATTERN:id%%", ch: "%%PATTERN:ch%%", ptype: "%%PATTERN:ptype%%"};
var pos_map = [
{ pos: { domain: "www.cookinglight.com", ctype: "homepage", plat: "desktop"}, inv_code: "cookinglight_main_feed" },
{ pos: { domain: "www.cookinglight.com", ctype: "channel", plat: "desktop"}, inv_code: "cookinglight_sectionfront_feed" },
{ pos: { domain: "www.cookinglight.com", ctype: "gallery"}, inv_code: "cookinglight_gallery_relatedlinks" },
{ pos: { domain: "www.cookinglight.com", ctype: "homepage", plat: "mobile"}, inv_code: "cookinglight_main_feed_mobile" },
@tiffwu
tiffwu / beasts02.js
Created December 21, 2016 01:29
solution to Watch and Code challenge #1: 'Improving runWithDebugger'
function runWithDebugger(fn, argArray) {
debugger;
fn.apply(null, argArray);
}
@tiffwu
tiffwu / beasts01.js
Last active December 20, 2016 21:28
solution to Watch and Code challenge #1: 'librarySystem with dependencies'
// v1 attempt
// This version passes all tests. However, it's missing a couple of key features:
// (1) it only takes one 'level' of dependencies (no nested dependencies), and
// (2) dependencies must have already been loaded in order for a library to be loaded.
(function() {
var libraryStorage = {};
function librarySystem(libraryName, dependencyArray, callback) {
if (arguments.length > 1) {
<div id="tl_ad"></div>
<script>
try {
var inv_code = "";
var pos = "%%PATTERN:domain%%" + "-" + "%%PATTERN:ctype%%" + "-" + "%%PATTERN:plat%%" + "-" + "%%PATTERN:id%%";
var pos_map = [
{ pos: "www.ew.com-homepage-desktop-enw_9", inv_code: "EW_main_feed" },
{ pos: "www.ew.com-channel-desktop", inv_code: "EW_category_feed" },
{ pos: "www.ew.com-article-desktop", inv_code: "EW_article_sub" },
{ pos: "www.ew.com-homepage-desktop-enw_10", inv_code: "EW_homepage_photo_gallery" },