Skip to content

Instantly share code, notes, and snippets.

@webbower
webbower / 01-handle-application-response-codes.js
Last active September 24, 2021 21:23
Complex Promise handling examples
zhuLiDoTheThing(args)
// Application status codes can come from HTTP 2xx, 4xx, and 5xx responses. This `.then()` will attempt to resolve
// to Promise<codeString> or reject with an error if the code is missing from the response body.
.then(
response => {
if (response.code) {
// Forward the code from the response
return response.code;
}
@webbower
webbower / CSS for <sup> and <sub>
Created July 9, 2021 17:03 — forked from unruthless/CSS for <sup> and <sub>
CSS for <sub> and <sup>
sub, sup {
/* Specified in % so that the sup/sup is the
right size relative to the surrounding text */
font-size: 75%;
/* Zero out the line-height so that it doesn't
interfere with the positioning that follows */
line-height: 0;
/* Where the magic happens: makes all browsers position
@webbower
webbower / multi-var-set.js
Created July 2, 2021 17:16
HTML/CSS/JS Patterns
// Option 1
let var1, var2, var3;
if (someCondition) {
var1 = 'value1';
var2 = 'value2';
var3 = 'value3';
} else {
var1 = "other1";
var2 = "other2";
var3 = "other3";
@webbower
webbower / useConstant.js
Last active April 5, 2025 16:51
Custom hooks
import { useState, useRef } from 'react';
// Can't use React State because setting the constant to a function will execute that function in `useState`
// const useConstant = value => useState(value)[0];
const useConstant = value => useRef(value).current;
const myConst = useConstant('foo');
@webbower
webbower / rally-btree-serialize-post-interview.js
Last active July 9, 2020 00:00
Rally Binary tree question
//// POST INTERVIEW VERSION
// NOTE Rado, Yi: I took the code where I left off and got it working in this second Gist file. It's probably not
// the most elegant solution, but it works. The code as of the end of the interview is in the other Gist.
// Given a binary tree, how would you serialize it into a string?
//Example input
var input = {
value: "a",
left: {
@webbower
webbower / interview-coderpad.js
Last active June 20, 2024 21:28
Interviewing utilities
// START: DENO STD colors
// https://jsr.io/@std/fmt/doc
/**
* Builds color code
* @param open
* @param close
*/
const code = (open, close) => ({
open: `\x1b[${open.join(';')}m`,
close: `\x1b[${close}m`,
@webbower
webbower / ducks-module-tmpl.js
Last active May 4, 2020 19:16
Template for a Redux Ducks module
const prop = key => obj => obj[key];
// Action Types
const MY_ACTION = '{my}-app/{module}/MY_ACTION';
// Action Creators
export const myAction = (value) => ({
type: MY_ACTION,
payload: value,
});
<html lang="en">
<head>
<meta charset="UTF-8">
<title>a11y for HTML</title>
<style>
/**
* Visually hide an element, but leave it available for screen readers
* @link https://github.com/h5bp/html5-boilerplate/blob/master/dist/css/main.css
* @link http://snook.ca/archives/html_and_css/hiding-content-for-accessibility
@webbower
webbower / package.json
Last active May 1, 2020 19:32
Simple, composable, instanced-enabled model factories
{
"name": "simple-model",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {},
"scripts": {
"start": "watch 'yarn run test' src",
"test": "tape -r esm src/*.test.js"
},
@webbower
webbower / extract-error-data.js
Created November 9, 2019 02:06
Extract data from error objects for serialization since Error instances are weirdly finicky and not straightforward to pull data from
const builtInErrorTypes = [
Error,
EvalError,
RangeError,
ReferenceError,
SyntaxError,
TypeError,
URIError,
];