DailyJS

DailyJS

The JavaScript blog.


Taglibraires
Featured

mobile node modules npm mongo generators libraires

Orientation and Vibration APIs, Mongomery

Posted on .

Orientation and Vibration APIs for Games

Andrzej Mazur sent in an article about using the orientation and vibration APIs for game development:

The Device Orientation API specification is still in the Working Draft status, so there might be some code-breaking changes introduced in the future. It's an experimental technology and should be treated as such. All implementations are still missing the compassneedscalibration event. Also, there are differences in browser implementations which should be taken into consideration. For instance, Chrome and Opera don't support the devicemotion event.

The Vibration API is another feature that can boost the mobile experience. Most devices support it (except iOS Safari and Opera Mini), and it works great on Firefox OS devices.

I've never used the vibration API, but apparently you can access it with window.navigator.vibrate. It even supports an array of values for vibrating multiple times. Andrzej's argument is that you can use these APIs to differentiate your game from other mobile web games, and while this is true it'll take a fair bit of experimentation to get orientation-based controls working well!

Mongomery

Coderaiser has sent in a few generator-based modules recently, but I missed Mongomery (GitHub: coderaiser/node-mongomery, License: MIT, npm: mongomery), a module that uses generators for MongoDB. It uses ruff, which was Coderaiser's module for giving generators a more EventEmitter-inspired API:

var mongomery = require('mongomery');

mongomery(function*(mongo) {  
  var url = 'mongodb://localhost:27017/myproject',
  var db = yield mongo.connect(url),
  var collection = db.collection('mongolog'),
  var docs = yield collection.find({}).toArray();

  docs.forEach(function(item) {
    console.log(item);
  });

  db.close();
}).on('error', function(error) {
  console.log(error.message);
});

It'll take us a few years to really understand how new features like generators should be used in terms of databases, but I'm very interested in using generator syntax for databases.

An alternative that I've enjoyed experimenting with is Mongorito, which is more of an ODM-style API. The syntax is more succinct than Mongoose, while still remaining familiar.

Featured

hosting node modules npm desktop libraires

Free js.org Subdomains, Wallpaper

Posted on .

Free js.org Subdomains

Stefan Keim wanted to give something back to the JavaScript community, so he's started js.org -- a service that provides free subdomains for JavaScript programmers. You can host your project on GitHub, then point a js.org subdomain at it.

To claim a subdomain you need to do three things:

  1. Create your GitHub Pages-hosted site
  2. Add a CNAME file to your repository with the js.org name that you want
  3. Make a pull request to GitHub: js-org/dns that adds your CNAME to the list

Given how valuable the js.org domain is I think this is very generous of Stefan, and the GitHub-based approach is a nice idea as well.

Wallpaper

Sindre Sorhus sent in wallpaper (GitHub: sindresorhus/wallpaper, License: MIT, npm: wallpaper), a module for changing the desktop wallpaper in Mac OS X, Linux, and Windows.

It has a command-line tool (wallpaper [file]) and a Node API:

var wallpaper = require('wallpaper');

wallpaper.set('unicorn.jpg', function(err) {  
 console.log('done');
});

wallpaper.get(function(err, imagePath) {  
  console.log(imagePath);
  //=> '/Users/sindresorhus/unicorn.jpg' 
});

It would be great to combine this with a Node Canvas module that generates data-driven art, or maybe even using PhantomJS to render a webpage to recreate the joys of Active Desktop!