Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian Beck exogen

View GitHub Profile
@exogen
exogen / parse-icu.js
Created Oct 26, 2020
Tiny ICU message syntax parser
View parse-icu.js
/**
* Parses ICU message syntax into an AST.
* Supports these features:
* - Apostrophe escapes (uses DOUBLE_OPTIONAL mode).
* - {simple} substitution.
* - {var, type} substitution.
* - {var, type, format} substitution, where format can contain complex nesting
* of additional ICU messages, for example:
* “I’ve invited {n, plural, offset:1
* =0 {nobody!}
View ProblemComponent.js
// This is based on some transpiled Babel code causing the `default` export
// to be undefined. If you look at the ultimate code that ends up in the Next.js
// bundle, `Object` method references are changed to strange `@babel/runtime`
// references, which seems to potentially cause a circular import (?) resulting
// in it being undefined.
exports.__esModule = true;
exports.default = DebugProvider;
exports.DebugContext = void 0;
var _react = _interopRequireWildcard(require("react"));
@exogen
exogen / diff-create-react-app.sh
Last active Nov 22, 2017
Show divergence from create-react-app as a diff.
View diff-create-react-app.sh
#!/usr/bin/env bash
#
# Determine divergence from create-react-app!
# Use this if you've ejected from create-react-app and want to see how its
# latest output would differ in key areas (package.json, config, scripts).
#
# - Assumes you can run create-react-app, so make sure it's installed.
# - Only shows files you've modified or removed from create-react-app.
# - Runs $FORMAT_COMMAND below on the create-react-app directory so formatting
# differences don't show up. Use something like Prettier, eslint --fix, etc.
@exogen
exogen / graphql-server.js
Last active Oct 26, 2017
Simple GraphQL server
View graphql-server.js
const express = require('express')
const graphqlHTTP = require('express-graphql')
const makeExecutableSchema = require('graphql-tools').makeExecutableSchema
const schema = makeExecutableSchema({
typeDefs: `
type Query {
user: User
}
@exogen
exogen / uber.py
Last active Mar 3, 2017
Tally your Uber trips from a Gmail export
View uber.py
#!/usr/bin/env python3
#
# Usage: python3 uber.py ~/Downloads/Takeout/Mail/Uber.mbox
#
# Dependencies: Python 3.4+
#
# How to get the .mbox export:
#
# In Gmail, create a filter that applies the label "Uber" to emails matching:
#
View fix-svg-height.js
/*
* WebKit (possibly others; Firefox looks fine) does a bad job of scaling an
* SVG's aspect ratio such that its contents fill the extent of the space
* horizontally. If you're letting the browser determine the dimensions of your
* SVG, including the aspect ratio (e.g. by setting a percentage width and using
* `height: auto`), then you probably want to use `preserveAspectRatio="none"`
* in your SVG for the best results. But if you can't do that, you can at least
* bump up the SVG's height just enough for it to fill the `img` horizontally,
* letting the browser add the leftover padding to the top and bottom rather
* than the sides.
View bus_schedule.py
from datetime import datetime
from dateutil.parser import parse
from dateutil.rrule import MO, TU, WE, TH, FR, SA, SU
from dateutil.rrule import rrule, rruleset, WEEKLY
rs = rruleset()
WEEKDAY_TIMES = [
{ "byhour": 5, "byminute": 0 },
{ "byhour": 5, "byminute": 15 },
View 47206291.html
<!doctype html>
<html lang="en-US" itemscope itemtype="http://schema.org/WebPage">
<head>
<script>
var t_page_start=new Date().getTime();
var _boomr=_boomr||[];
(function(d){var b=d.createElement('script');b.src='http://i2.walmartimages.com/js/rollups/rum.jsp';b.setAttribute('async','true');b.setAttribute('defer','defer');var s=d.getElementsByTagName('script')[0];s.parentNode.insertBefore(b, s);})(document);
</script>
<!-- Fix for iPad issue: item page isn't centered; large white right margin instead (OSO Site team, CASE00576055) -->
View lodash grep
_.chain
_.compact
_.difference
_.each
_.every
_.filter
_.findIndex
_.flatten
_.flattenDeep
_.includes
@exogen
exogen / chart-new.jsx
Created Oct 22, 2015
New per-datum style
View chart-new.jsx
<VictoryChart
interpolation="basis"
axisLabels={{x: "x axis", y: "y axis"}}
x={[
[1, 2, 3, 4],
[-2, -1, 0, 1, 3],
[3, 4, 6]
]}
y={[
[1, 2, 10, 4],
You can’t perform that action at this time.