Mapping an array of objects to key/value pairs in CoffeeScript

var arr = [{name: ‘a’, value: ‘b’, other: ‘c’}, {name: ‘d’, value: ‘e’, other: ‘f’}]; var obj = arr.reduce(function ( total, current ) { total[ current.name ] = current.value; return total; }, {}); Pure javascript. It’s practically a one liner, and it looks hawt. Array.prototype.reduce is ES5, but isn’t difficult to shim. Here’s an example … Read more

BackboneJS Rendering Problems

Partial rendering of views In order to minimize the full rendering of your DOM hierarchy, you can set up special nodes in your DOM that will reflect updates on a given property. Let’s use this simple Underscore template, a list of names: <ul> <% _(children).each(function(model) { %> <li> <span class=”model-<%= model.cid %>-name”><%= model.name %></span> : … Read more

ipython equivalent for javascript/coffeescript for node.js? [closed]

I’ve recently started a project to provide an enhanced, extensible, embeddable interactive interpreter for multiple languages running on Node (including built-in support for CoffeeScript) here: http://danielgtaylor.github.com/nesh/ It’s pretty basic at the moment but it already provides a nice base with multi-language support and an asynchronous plugin architecture, a small set of built-in utility functions, etc. … Read more

How can I setup webpack to minify and combine scss and javascript like CodeKit?

Introduction Webpack is mainly a JavaScript-bundler. Its “native” language is JavaScript and every other source requires a loader which transforms it to JavaScript. If you require() an html-file for example… var template = require(“./some-template.html”); …you’ll need the html-loader. It turns… <div> <img src=”https://stackoverflow.com/questions/26851120/./assets/img.png”> </div> …into… module.exports = “<div>\n <img src=\”” + require(“https://stackoverflow.com/questions/26851120/./assets/img.png”) + “\”>\n</div>”; If … Read more

Creating array of empty strings?

Update: on newer browsers – use .fill: Array(1000).fill(”) will create an array of 1000 empty strings. Yes, there is a way: var n = 1000; Array(n).join(“.”).split(“.”); // now contains n empty strings. I’d probably use the loop though, it conveys intent clearer. function repeat(num,whatTo){ var arr = []; for(var i=0;i<num;i++){ arr.push(whatTo); } return arr; } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)