Skip to content

Instantly share code, notes, and snippets.

View parshap's full-sized avatar

Parsha Pourkhomami parshap

View GitHub Profile
@parshap
parshap / comma.js
Created July 22, 2014 22:38
js trailing comma
var a = [
1,
2,
3, // <-- Trailing comma for easier future edits
];
// No trailing comma, adding a 4th element will require editing two lines
var b = [
1,
2,
@parshap
parshap / react-container.js
Last active August 29, 2015 14:04
React container pattern
var React = require("react");
var TabbedComponent = React.createClass({
render: function() {
return TabsContainer({
tabs: [
// Pass instantiated component?
this.renderTab1(),
// Or pass function to create component?
this.renderTab1,
"use strict";
// A function that wraps a given `React.DOM.input`-like component to
// apply formatting to the value for display purposes.
//
// Example:
//
// var RoundedInput = createFormattedInput(React.DOM.input, {
// set: Math.round,
// });
function myCallback() {
console.log(foo); // undefined
}
function dothing(callback) {
var foo = "hello";
callback();
}
@parshap
parshap / jetblue-horrible-checkin.md
Last active August 29, 2015 13:57
Why JetBlue's Web Check In Experience Is Horrible
  • "Print boarding pass" button does not work
  • Uses Flash
    • Non-native experience (weird scrolling, input fields, etc)
    • Doesn't work on my phone
  • Have to identify myself even though I'm already logged in on your website
  • Too many steps, show my boarding pass on first screen
@parshap
parshap / formatted-input.jsx
Last active August 29, 2015 13:57
React input formatting
/** @jsx React.DOM */
"use strict";
// An <input /> component that applies a format function to the value
// on initial render and when the element loses focus.
//
// Usage:
//
// <FormattedInput format={Math.round} valueLink={this.linkState("value")} />
//
@parshap
parshap / validated-input.jsx
Last active September 15, 2016 08:56
React input validation
/** @jsx React.DOM */
"use strict";
var React = require("react");
// Usage:
// <ValidatedInput validateValue={myValidationFunction}
// onValidationError={handleError}
// valueLink={...} />
@parshap
parshap / classes.js
Created March 5, 2014 20:30
node inline tests
"use strict";
var type = require("core-util-is");
var slice = Array.prototype.slice;
// Return a className string from the given arguments
//
// Example:
//
// classes("foo", "bar") -> "foo bar"
@parshap
parshap / jsx-html-differences.md
Last active May 11, 2020 16:40
Difference between JSX and HTML
  • className attribute instead of class
  • htmlFor attribute instead of for
  • <textarea value="something"> instead of <textarea>something</textarea> (see Why Textarea Value)
  • <select value="something"><option value="something"></select> instead of <select><option selected value="something"></select> (see Why Select Value)
  • Whitespace (see discussion)
  • [Tags must be closed and all tags can be self-closing][closing tags]
var user = new User();
user.set("name", "parshap");
user.age("age", 5);
// Only save "name" to Mongo - leave "age" as a modified path in the docuemnt
user.save(["name"], function(err) {
// ...
})