Skip to content

Instantly share code, notes, and snippets.

View contacts.js
// Don't care much about inheritance at this point, but I'll probably attempt it at
// some point via cloning ancestor schema's
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var Contact = new Schema({
_type: String,
name: String
});
View should.be.undefined.js
var should = require('chai').should();
db.get(1234, function (err, doc) {
should.not.exist(err);
should.exist(doc);
doc.should.be.an('object');
});
@0xBADC0FFEE
0xBADC0FFEE / extend.js
Created Apr 19, 2014
Backbone's extend method
View extend.js
// Helper function to correctly set up the prototype chain, for subclasses.
// Similar to `goog.inherits`, but uses a hash of prototype properties and
// class properties to be extended.
var extend = function(protoProps, staticProps) {
var parent = this;
var child;
// The constructor function for the new subclass is either defined by you
// (the "constructor" property in your `extend` definition), or defaulted
// by us to simply call the parent's constructor.
@0xBADC0FFEE
0xBADC0FFEE / app.coffee
Created Apr 19, 2014
AngularJS + Coffeescript Constructor Class with Inheritance http://jsfiddle.net/g/bXFdM/5/
View app.coffee
app = angular.module 'myapp', []
# simple class exemple - minification safe
class MySimpleCtrl
@$inject: ['$scope']
constructor: (@scope) ->
# attach viewmodel data to the scope:
@scope.demo = 'Simple class demo'
View crossbrowser-xhr.js
function getXmlHttp(){
var xmlhttp;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
@0xBADC0FFEE
0xBADC0FFEE / lazy-html.js
Created Apr 24, 2014
Lazy loading expensive DOM
View lazy-html.js
directive('lazyHtml', function() {
return {
transclude: 'element',
priority: 1200,
terminal: true,
restrict: 'A',
compile: function(element, attr, linker) {
return function ($scope, $element, $attr) {
var visible = false;
var stopWatching = $scope.$watch($attr.lazyHtml, function(value){
@0xBADC0FFEE
0xBADC0FFEE / jquery-live.js
Created Apr 24, 2014
$.live() like function in pure js
View jquery-live.js
var live = (function () {
var eventRegistry = {};
function dispatchEvent(event) {
var targetElement = event.target;
eventRegistry[event.type].forEach(function (entry) {
var potentialElements = document.querySelectorAll(entry.selector);
var hasMatch = Array.prototype.indexOf.call(potentialElements, targetElement) >= 0;
View ngd.js
directive('$directiveName$', function factory($injectables$) {
return {
// priority: 0,
// restrict: 'A', // Attribute (default): <div my-directive="exp"></div>
// restrict: 'E', // Element name: <my-directive></my-directive>
// restrict: 'C', // Class: <div class="my-directive: exp;"></div>
View approve-unidefined-app.sh
spctl --add /Path/To/Application.app
You can’t perform that action at this time.