Skip to content

Instantly share code, notes, and snippets.

View app.coffee
Bacon = require('baconjs')
Imm = require('immutable')
React = require('react')
window.Actions =
changeFirstName: new Bacon.Bus()
changeLastName: new Bacon.Bus()
changeCountry: new Bacon.Bus()
addCountryBird: new Bacon.Bus()
addFriend: new Bacon.Bus()
@rattrayalex
rattrayalex / recursive_multiplication.coffee
Last active Aug 29, 2015
recursive multiplication without (-)
View recursive_multiplication.coffee
# Finds product of two positive int's
# using only if, (+), and (===).
# Usage: mult(x, y)
mult = (n1, n2, top=null, orig=null) ->
# sanity check (still assuming positive int's)
if (n1 is 0) or (n2 is 0)
return 0
# on first call
@rattrayalex
rattrayalex / DataProvider.js
Last active Aug 29, 2015
Nuclearjs React DataProvider component
View DataProvider.js
import React from "react"
import Reactor from "./reactor"
function _toJS(x) {
if (x && x.toJS && typeof x.toJS === 'function') {
return x.toJS()
}
return x
}
View AwesomePrint Example.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View toggleColumns.js
const getIndex = (th) => Array.from(th.parentElement.children).indexOf(th)
const getChildren = (i) => Array.from(document.querySelectorAll(`td:nth-child(${i + 1})`))
const setHiddenStyle = (node) => {
node.style.width = '1px'
node.style.overflow = 'hidden'
node.style.overflowWrap = 'normal'
}
const toggleHidden = (node) => {
if (node.style.length) {
node.style = {}
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')
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.
@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 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 / 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 =