Skip to content

Instantly share code, notes, and snippets.

@rattrayalex
rattrayalex / query.gql
Last active Apr 21, 2021
Postgraphile Pagila gql to sql demo
View query.gql
query MyQuery {
actor(actorId: 10) {
firstName
lastName
filmActors {
nodes {
film {
title
description
}
@rattrayalex
rattrayalex / ideas.md
Last active Apr 14, 2021
PostGraphile Framework Sketches
View ideas.md

I want something that I can share with a development team that's just focused on features and doesn't want to think about the tools at hand very much (but can deeply fine-tune where needed).

Postgraphile seems like an amazing place to start for this.

Here's what I might want to build on top of it (though ideally it'd be baked-in):

Each "table" (think pg_class) should have a single file where ~all logic around that table is contained in as declarative a format as possible.

@rattrayalex
rattrayalex / play-html5-video-on-scroll-into-view-or-click.js
Created Nov 22, 2020
Vanilla JS ES6 snippet to play html5 video on scroll into view or click (and pause when out of view or clicked while playing)
View play-html5-video-on-scroll-into-view-or-click.js
function debounce(callback) {
let timeout = null;
return function() {
const next = () => callback.apply(this, arguments);
cancelAnimationFrame(timeout);
timeout = requestAnimationFrame(next);
}
}
const observerOptions = {
@rattrayalex
rattrayalex / index.html
Last active Nov 17, 2020
Fall back to twitter's twemoji emoji when there is inadequate native emoji support (eg; on Windows)
View index.html
<html>
<body>
<div class="has-emoji">Hello world! I'm a unicorn: 🦄</div>
<script>
// Stolen from Modernizr: https://github.com/Modernizr/Modernizr/blob/v3.5.0/feature-detects/emoji.js
const hasEmojiSupport = () => {
var pixelRatio = window.devicePixelRatio || 1;
var offset = 12 * pixelRatio;
var node = document.createElement('canvas');
@rattrayalex
rattrayalex / my-styles.js
Created Nov 4, 2020
Loose sketch of css-in-js root variables
View my-styles.js
const rootCSSVars = {
colorPrimary: {name: '--color-primary', value: 'red'},
colorSecondary: {name: '--color-secondary', value: 'orange'},
}
writeCSSToDOM(`
:root {
${_.mapValues(rootCSSVars, (v) => `${v.name}: ${v.value};\n`)}
}
`)
@rattrayalex
rattrayalex / hacked_prettier_snippet.js
Created Dec 18, 2017
Hacking "check ast" into node_modules/prettier/bin/prettier.js at the bottom of `function format(argv, input, opt) {`
View hacked_prettier_snippet.js
//
// at the bottom of `function format(argv, input, opt) {`, near line 20367
const pp = prettier$3.format(input, opt);
const ast = cleanAST(prettier$3.__debug.parse(input, opt));
const past = cleanAST(prettier$3.__debug.parse(pp, opt));
if (ast !== past) {
const MAX_AST_SIZE = 2097152; // 2MB
const astDiff =
View Original rattrayalex private keyword proposal.md

Use a keyword (not necessarily private) as a "private this", such that private. is identical to the currently proposed #, but is used similarly to this.

class Point {
  
    private.x;
    private.y;

    constructor(x = 0, y = 0) {
@rattrayalex
rattrayalex / match_polyfill.js
Created Sep 6, 2017
Example Match Polyfill with "tests"
View match_polyfill.js
if (!Symbol.matches) {
const DEFINE_PROPERTY = "defineProperty";
// define Symbol.matches
Object[DEFINE_PROPERTY](Symbol, "matches", {
configurable: false,
writable: false,
value: Symbol("matches"),
});
View gist:c8a62f2b7d9a41bb0a5b191131c31475
diff --git a/tests/prettier/__snapshots__/jsfmt.spec.js.snap b/tests/prettier/__snapshots__/jsfmt.spec.js.snap
index 826b40c..5d5ca84 100644
--- a/tests/prettier/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/prettier/__snapshots__/jsfmt.spec.js.snap
@@ -49,19 +49,19 @@ const comp5 = <div>Keep it on one line.</div>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const comp1 = (
<div style={styles} key=\"something\">
- Keep the wrapping parens.
+ Keep the wrapping parens.
View add_import_export_scope_types.patch
diff --git a/src/grammar.coffee b/src/grammar.coffee
index 4ff9a1c..7229664 100644
--- a/src/grammar.coffee
+++ b/src/grammar.coffee
@@ -365,7 +365,7 @@ grammar =
Export: [
o 'EXPORT Class', -> new Export $2
- o 'EXPORT Identifier = Expression', -> new Export new Assign($2, $4)
+ o 'EXPORT Identifier = Expression', -> new Export new Assign($2, $4, 'export')