This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in AngularJS (client) | |
myApp.config(['$httpProvider', function($httpProvider) { | |
$httpProvider.defaults.useXDomain = true; | |
delete $httpProvider.defaults.headers.common['X-Requested-With']; | |
}]); | |
// in NodeJS/Express (server) | |
app.all('/*', function(req, res, next) { | |
res.header("Access-Control-Allow-Origin", "*"); | |
res.header("Access-Control-Allow-Headers", "X-Requested-With"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="utf-8"> | |
<title>Isolate Scope @</title> | |
<style type="text/css"> | |
.inline { | |
display: inline-block; | |
} | |
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="utf-8"> | |
<title>Directives Talking to Controllers</title> | |
</head> | |
<div ng-app="twitterApp"> | |
<div ng-controller="AppController"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bind(expr, data, el){ | |
el.render = render.bind(null, expr, data, el); | |
return on('squirt.els.render', function(){ | |
el.render(); | |
}); | |
}; | |
function render(expr, data, el){ | |
var match, rendered = expr; | |
expr.match(/{{[^}]+}}/g).map(function(match){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (var i = 0; i < 5; i++) { | |
setTimeout(function() { | |
console.log(i); | |
}, 1000); | |
} | |
// How do we fix the above to log what we want it to log? | |
for (var j = 0; j < 5; j++) { | |
// With an IIFE (immediately-invoked function expression) | |
// Closures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Write a simple join function in the various styles: | |
* 1. Imperative | |
* 2. Object-oriented | |
* 3. Functional language | |
*/ | |
// Imperative | |
function simpleJoin( stringArray ) { | |
var accumulator = ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MakeSingleton = function(){ | |
var obj; | |
return function() { | |
if( obj ){ | |
return obj; | |
} else{ | |
obj = this; | |
} | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app="myApp"> | |
<head> | |
<meta name="AngularJS Isolate Scope Bindings" content="Binding to Isolate Scope" /> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script> | |
<meta charset="utf-8"> | |
<title>AngularJS Isolate Scope Bindings</title> | |
</head> | |
<body ng-controller="MainCtrl as main"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Right-click on the bookmarks toolbar | |
// 2. Click Add Page... | |
// 3. Name: <enter whatever you'd like> (Mine is Genius Annotate) | |
// 4. Paste the following into the URL field (including the keyword javascript and the colon): | |
javascript: window.location.replace('http://genius.it/' + window.location.href) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using native JS | |
function filter(list, predicate) { | |
list.reduce(function(prev, curr, i, arr) { | |
if (!predicate(curr)) arr.splice(i, 1); | |
}, []); | |
return list; | |
} | |
// using Underscore |
OlderNewer