Skip to content

Instantly share code, notes, and snippets.

Kabir Sarin sarink

Block or report user

Report or block sarink

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View private.js
// Sample demo of how to gain access to "private" variables in JavaScript,
// even if they'd normally be inaccessible due to the closure.
var Table = function () {
var _array = ["super", "secret", "message"];
return {
get: function (i) { return _array[i]; },
store: function (i,v) { _array[i] = v; },
append: function (v) { _array.push(v); }
};
};
View backbone.parentview.js
(function(root, factory) {
if (typeof define === "function" && define.amd) {
define(["underscore", "backbone", "backboneBabySitter"], function(_, Backbone, ChildViewContainer) {
return factory(_, Backbone, ChildViewContainer);
});
}
else if (typeof exports !== "undefined") {
var _ = require("underscore");
var Backbone = require("backbone");
var ChildViewContainer = require("backboneBabySitter");
@sarink
sarink / backbone.subiews.js
Last active Aug 29, 2015
backbone.subviews
View backbone.subiews.js
// I wrote this when Backbone was like v0.2 - now there are many many tools like Marionette,
// and even things native to Backbone (like `stopListening`) that invalidate a lot of this
var SubView = Backbone.View.extend({
// tagName: must be implemented
// className: must be implemented
// template: must be implemented
initialize: function() {
this.model.on("change", this.render, this);
this.model.on("close", this.close, this);
View backbone.overrides.js
// Adds an `append` option to the Backbone Router
Backbone.Router.prototype.navigate = (function(origNavigate) {
return function(fragment, options) {
if (options && options.append) {
fragment = Backbone.history.fragment + fragment;
delete options.append;
}
return origNavigate.call(this, fragment, options);
};
})(Backbone.Router.prototype.navigate);
View backbone._super.js
// Forked/modified from: https://gist.github.com/maxbrunsfeld/1542120
// This method gives you an easier way of calling super when you're using Backbone in plain javascript.
// It lets you avoid writing the constructor's name multiple times.
// You still have to specify the name of the method.
//
// So, instead of having to write:
//
// var Animal = Backbone.Model.extend({
// word: "",
// say: function() {
View underscore-mixins.js
(function(root, factory) {
if (typeof define === "function" && define.amd) {
define(["underscore"], function(_) {
return factory(_);
});
}
else if (typeof exports !== "undefined") {
var _ = require("underscore");
module.exports = factory(_);
}
View jquery-mixins.js
(function(root, factory) {
if (typeof define === "function" && define.amd) {
define(["jquery"], function($) {
return factory($);
});
}
else if (typeof exports !== "undefined") {
var $ = require("jquery");
module.exports = factory($);
}
View angular-directives.js
// Adds `ng-context-menu` for right click support
app.directive("ngContextMenu", function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngContextMenu);
element.bind("contextmenu", function(event) {
scope.$apply(function() {
event.preventDefault();
fn(scope, {$event:event});
});
});
View SampleComponent.jsx
// use like:
// var sample1 = new SampleModel();
// React.render(<SampleComponent model={sample1} />);
define(["underscore", "backbone", "react"],
function(_, Backbone, React) {
"use strict";
var SampleComponent = React.createClass({
// Give us those sweet react console warnings if we don't pass the right props
View bb-underscore-alphabetizer.js
javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.10.2",function($,L){$(".toc_section").each(function() { var $section = $(this); var listitems = $section.children('li').get(); listitems.sort(function(a, b) { return $(a).text().toUpperCase().localeCompare($(b).text().toUpperCase()); }); $.each(listitems, function(idx, itm) { $section.append(itm); });});});
You can’t perform that action at this time.