Encoding to binary:

'hello'.replace(/./g, function(c) {
function pad(n) { return (n > 0) ? ('0' + pad(n - 1)) : ''; }
var s = c.charCodeAt(0).toString(2);
return pad(8 - s.length) + s;
});

Decoding binary to a string:

'011101110110111101110111'.replace(/.{8}/g, function(s) {
return String.fromCharCode(parseInt(s, 2));
});

I like building up a project from small parts but sometimes it’s good to try using a full framework to see what parts I’m missing. Today I tried starting a mean.js app with yeoman. It comes with a lot preconfigured, including five different authentication options, and since I chose it, an articles model. I removed four of the five authentication modules and changed the name of Article to Bin. In the process I found where things are stored in mean.js. It seems to do a good job of following the rails mantra of Convention Over Configuration.

  • The Code (unfinished, and most of it isn’t mine, the commits show what I did)

I want to return to this experiment and get it working the rest of the way and deployed on Heroku. The basic idea is a minimalistic jsfiddle.

I used d3 to make a map. It was good practice. I had forgotten how d3?s chaining API works. When a function mutates an element, it returns the same element back. When a function appends something to an element, it returns the new element back.

I also tried using patterns in svg. I still have to learn some more to understand them and to get the results I want, and I also need to brush up on biezer curves.

Update: I adjusted the vertical offset of the pattern to remove gaps between states.

doge-usa

 

A lot of node programmers like to code on the left margin. This is made possible by JavaScript’s dynamic nature. Prototypes can be built up and exports.

In Grunt the examples and virtually all code are wrapped up in one big function. Gulp doesn’t require this, and I’m under the impression many prefer this. However Grunt has a huge standard library.

I like code that doesn’t leave the left margin for long because it’s easier for me to see chunks of code. It also allows me to interleave code, which sometimes makes a lot of sense.

Using OOP, Grunt can be made to have this style. I took the Gruntfile for jquery and made it stay to the left margin while working the same way.

I won’t be sending a pull request, but I may do this on one of my own projects.

I’ve started playing with Component again after finding some neat devs/projects/companies that use it. I also checked out ES6 generators in the development version of node and Koa which uses generators. Pretty neat stuff!

I created an example app that uses both Koa and Component but doesn’t do anything server-side. A possible future project is to make my example app use a server-side JSON API to do something.

Update: I got it to animate all of the divs. My mistake was that I had the divs changing their position in the DOM, in addition to changing the CSS properties. Some of the divs didn’t change position in the DOM because their index was the same both alphabetically and by population, and these were animated.

I played with React some more, this time loading it from a CDN with the jsx compiler. I set the CSS properties on the divs and tried animating them using CSS3 transitions. Some are animated while some move to their new position instantaneously.

I made a little sign-up form example with React.

I built it in RequireBin. The main react model in isn’t working in RequireBin and I’m working to get it fixed. In the meantime I’ve published benatkin-react to npm which makes the minimal changes needed to get it to work (none to the code, just to the packaging).

The sign-up form I made has validation which highlights invalid fields with red after an attempt has been made to enter it in correctly.