Skip to content

Instantly share code, notes, and snippets.

View wulymammoth's full-sized avatar
processing unit

David W wulymammoth

processing unit
View GitHub Profile
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
@wulymammoth
wulymammoth / data-binding.js
Created July 2, 2014 21:21
One-way data-binding
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){
<!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">
@wulymammoth
wulymammoth / [email protected]
Last active August 29, 2015 13:57
Angular Isolate Scope with @
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<title>Isolate Scope @</title>
<style type="text/css">
.inline {
display: inline-block;
}
</style>
@wulymammoth
wulymammoth / cors.js
Last active August 29, 2015 13:56
CORS playing nice with AngularJS + Express
// 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");