Skip to content

Instantly share code, notes, and snippets.

(function() {
"use strict";
function loadJSAsync() {
var js = document.createElement("script");
js.type = "text/javascript";
js.src = "script.js";
js.async = true;
// insert the "js" script tag to the DOM here ...
}
if (window.attachEvent) {
var promise = $q.all(null);
angular.forEach(urls, function(url){
promise = promise.then(function(){
return $http({
method: 'GET',
url:url
}).then(function(res){
$scope.responses.push(res.data);
});
// 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
});
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 / app.coffee
Created April 19, 2014 14:45
AngularJS + Coffeescript Constructor Class with Inheritance http://jsfiddle.net/g/bXFdM/5/
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'
@0xBADC0FFEE
0xBADC0FFEE / extend.js
Created April 19, 2014 15:20
Backbone's extend method
// 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.
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 April 24, 2014 18:35
Lazy loading expensive DOM
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 April 24, 2014 18:47
$.live() like function in pure 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;
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>