Skip to content

Instantly share code, notes, and snippets.

View aykutyaman's full-sized avatar

Aykut Yaman aykutyaman

View GitHub Profile
@aykutyaman
aykutyaman / complexFormProps.jsx
Created August 23, 2016 10:00
if complexFormProps and items come from the same store, typing in the ComplexForm might lead to store updates, and each store update leads to re-rendering the entire <ul>.
<div>
<ComplexForm props={this.props.complexFormProps} />
<ul>
<li prop={this.props.items[0]}>item A</li>
...1000 items...
</ul>
</div>
@aykutyaman
aykutyaman / array_literals.js
Created August 23, 2016 09:54
Array literals comparision
> ['important', 'starred'] === ['important', 'starred']
false
@aykutyaman
aykutyaman / todo_item.jsx
Created August 23, 2016 09:49
pass the unbound function and the desired args to the child component, and have the child use an instance method
const TodoItem = React.createClass({
deleteItem() {
this.props.deleteItem(this.props.index);
},
});
@aykutyaman
aykutyaman / new_function.js
Last active August 23, 2016 09:46
each call to Function.bind produces a new function
> console.log.bind(null, 'hi') === console.log.bind(null, 'hi')
false
> function(){console.log(‘hi');} === function(){console.log(‘hi');}
false
// New function each time
render() {
return <MyComponent onClick={() => this.setState(...)} />
}
@aykutyaman
aykutyaman / deep_comparison.js
Created August 23, 2016 09:33
Create deep-equal props that are not shallow-equal
export class SampleComponent extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
return !_.isEqual(this.props, nextProps) ||
!_.isEqual(this.state, nextState);
}
render() {
return <div className={this.props.className}>foo</div>;
}
}
a["{\"msg\":\"added\",\"collection\":\"meteor_autoupdate_clientVersions\",\"id\":\"BHx6NPxiMDaJP84rN\",\"fields\":{\"current\":true}}"]
a["{\"msg\":\"added\",\"collection\":\"roles\",\"id\":\"B2ge3K5n7zbCtdDjj\",\"fields\":{\"name\":\"teacher\"}}"]
a["{\"msg\":\"added\",\"collection\":\"roles\",\"id\":\"Hg9a5ZJY2W45nTK32\",\"fields\":{\"name\":\"root\"}}"]
a["{\"msg\":\"added\",\"collection\":\"meteor_autoupdate_clientVersions\",\"id\":\"version\",\"fields\":{\"version\":\"a5bcf426e9c41894daf2061c9020c3d\"}}"]
a["{\"msg\":\"added\",\"collection\":\"meteor_autoupdate_clientVersions\",\"id\":\"version-cordova\",\"fields\":{\"version\":\"none\",\"refreshable\":false}}"]
a["{\"msg\":\"added\",\"collection\":\"meteor_autoupdate_clientVersions\",\"id\":\"version-refreshable\",\"fields\":{\"version\":\"ffc60b4f3427064574e698ced2533f82859b0494\",\"assets\":{\"allCss\":[{\"url\":\"/eccb300949f1901eca2ce08af04afb4e448cdf5b.css?meteor_css_resource=true\"}]}}}"]
["{\"msg\":\"method\",\"method\":\"login\",\"params
Template.workspaceBroadcast.workspace = function() {
return Workspaces.findOne(Session.get("selectedWorkspaceId"));
};
Template.workspaceBroadcast.rendered = function() {
console.log('rendered');
};
Template.messages.messages = function(){
return Messages.find({workspaceId: Session.get("selectedWorkspaceId")}, { sort: { submitted: -1 }});
curl https://api.efatura.com/ \
...
-d "receiver[name]=Foo" \
-d "receiver[surname]=Bar" \
-d "total=30.08"
...
@aykutyaman
aykutyaman / gist:5957621
Created July 9, 2013 14:06
jitsu deploy error output
╰─$ jitsu deploy 1 ↵
info: Welcome to Nodejitsu aykutyaman
info: jitsu v0.12.11, node v0.8.21
info: It worked if it ends with Nodejitsu ok
info: Executing command deploy
info: Analyzing application dependencies in server/server.js
info: Creating snapshot 0.1.1-18
info Uploading: [=============================] 100%
error: Error running command deploy
error: Nodejitsu Error (500): Internal Server Error
@aykutyaman
aykutyaman / gist:5388797
Created April 15, 2013 15:09
backbone validate
Backbone.Validate = function(model, changedAttributes) {
return (function(patterns) {
var isNumeric = function(value){
return _.isNumber(value) ||
(_.isString(value) && value.match(patterns.number));
};
var hasValue = function(value) {
return !(_.isNull(value) || _.isUndefined(value) || (_.isString(value) && value === ''));