Skip to content

Instantly share code, notes, and snippets.

Avatar

Abhi Aiyer abhiaiyer91

  • Workpop
  • Los Angeles
View GitHub Profile
View gist:18b539c5858876e6476e
function Rectangle(h,w) {
var width=w; // Both the 'width' and 'w' is private
var heigth=h; // Both the 'height' and 'h' is private
this.setWidth= function(w){ width=w;}
this.setHeight= function(h){ heigth=h;}
this.getWidth= function(){ return width;}
this.getHeight= function(){ return heigth;}
this.constructor.prototype.getDiagonal=function() {
return Math.sqrt(heigth*heigth+width*width);
};
View gist:0b5b9e2adfe4c53067eb
//DOUBLE
console.log(99 == "99"); // true
console.log(0 == false); // true
//TRIPLE
console.log(99 === "99"); // false
console.log(0 === false); // false
console.log(' \n\n\n' === 0); // false
View gist:1018c36505c869694561
/**
* Created by abhiaiyer on 4/10/15.
*/
Wootric = {};
Meteor.startup(function () {
var key = Meteor.settings.public && Meteor.settings.public.wootric && Meteor.settings.public.wootric.key;
if (!key) {
return;
}
View BlazeACStep2.js
// register this group of functions with the ActionMixins
ZenMixins.registerMixin('CommentActions', {
fetchData(collection, query, options) {
// Do something here
},
submitComment(options, cb) {
return Meteor.call('submitComment', options, cb);
},
manipulateDOM(template) {
View Blaze AC Step 1.js
// Lets say we have some view called CommentSubmitComponent
// This view will make many things happen. Its job is to send off
// actions from the view and process something.
// Lets make an Action Creator
let CommentSubmitActions = new ZenAction();
// So yeah yeah this is just a plain object at this point. But even so, you have a
// logical place to attach functionality
_.extend(CommentSubmitActions, {
View Bad UI Code.js
'click .submit': function (event, template) {
var post = template.data.post;
// Lets do more presentational stuff //
$(template.find(‘button[type=submit])).addClass(‘loading’);
$(template.find(‘input,textarea’)).not(:disabled”).addClass(“disabled”).prop(“disabled”, true);
// Lets also check if you're logged in here
if (!Meteor.userId()) {
return ShowToast('Some Message', 'error')
}
// lets run some callbacks
View keyCodeMixin.js
var DEFAULT_SUBMISSION_KEYS = [13, 188];
/**
* Register a mixin for key events
*/
ZenMixins.registerMixin('keyEvents', {
/**
* Decides whether the given event is a keyup for the 'Enter' key.
*
* @param event
* @returns {boolean} - True if the event is keyup on enter key
View mixintest.js
describe('A Unit test for a test function', function () {
it('should do something when i say so :)', function () {
var actionCreator = new ZenAction(['testMixin']);
expect(actionCreator.getTest()).toEqual(undefined);
});
});
View fakefunc.js
var psuedoReusableFunction = function (param1, param2, param3, param4) {
// do something with params 1 and 2
DoSomething(param1);
DoSomething(param2);
// params 3 and 4 were added when your app changed but you didn't
// want to rewrite anything
if (param3) {
DoSomethingElse(param3);
}
// ya da ya da ...
View profilecomponent.jsx
const ProfileAvatarComponent = ({profilePhoto, role}) => {
return (
<div className="img-circle">
<div className="grey-outline">
<img src={profilePhoto} className="img-responsive"/>
</div>
</div>
)
}