Skip to content

Instantly share code, notes, and snippets.

View parshap's full-sized avatar

Parsha Pourkhomami parshap

View GitHub Profile
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) {
// ...
})
@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 / 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 / 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
function myCallback() {
console.log(foo); // undefined
}
function dothing(callback) {
var foo = "hello";
callback();
}
"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,
// });
@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,
@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 / mongoose-schema.js
Created July 24, 2014 21:22
Mongoose nested object unexpectd value
var mongoose = require("mongoose");
var schema = new mongoose.Schema({
nestedProp: {
bar: String,
baz: String,
},
});
var MyModel = mongoose.model("MyModel", schema);
@parshap
parshap / naming-tips.md
Created September 18, 2014 22:06
Naming Tips

Taken from Naming Tips.

  • Do not name methods ProcessData(). You only get to use this method name once per career, because you should have been fired immediately afterwards. Be specific about what it's doing inside; call it ValidateUserCredentials or EliminateDuplicateRequests or ComputeAverageAge, etc.

  • Use naming to help you design the program. Pretend there's a rule saying "you can never write a void function", then think about all the steps your program makes to transform input into output, then chose names for those steps so you could make a written sentence with them. These are now your function names and the sentence is your program's structure.