Simple async queue in javascript nl

Door creator1988 op donderdag 2 januari 2014 13:51 - Reacties (2)
Categorie: Frontend, Views: 3.529

Normally I fall back to caolan's async module, but I'm not in a node.js environment and I needed a simple async queue with concurrency 1; which can be done in a one liner.

JavaScript:
1
2
3
4
5
6
7
8
9
10
var q = [ 
  function a(n) { console.log('a'), setTimeout(n, 30); },
  function b(n) { console.log('b'), setTimeout(n, 10); }
];

function queue(q, n) {
  q.length ? q.shift()(queue.bind(this, q, n)) : n();
}

queue(q, function() { console.log('done') });


You could use arguments.callee rather than queue to bind to the current function, but it has been deprecated since ES5.

It's also easy to use it with promises, let's say I have a function |sendKey| that returns a promise and I want to send a string char by char:

JavaScript:
1
2
3
4
5
6
7
8
var input = 'sometext'
var q = input.split('').map(function(c) {
  return function(n) {
    sendKey(c).then(n);
  };
});

queue(q, function() { console.log('done') });

Getting started on Firefox OS apps with AngularJS

By creator1988 on Wednesday 20 February 2013 11:21 - Comments are disabled
Category: Frontend, Views: 21.039

The part that amazes me most about working day to day with Firefox OS is the incredible way that the existing web eco-system can be reused to target mobile phones. We have seen this with using Weinre to remote debug the FFOS system, using emscripten to cross compile C code into javascript, or just the ease of reusing jQuery within your Firefox OS app; something that I would have killed for back in the days when doing WPF.

Development in JavaScript frameworks has exploded since the mid-2000s, with new players emerging every other day, and application frameworks like Ember.js or AngularJS now taking the lead, giving website developers extremely powerful components at a fraction of the costs. The great thing about Firefox OS is that we can take advantage of the developments in these areas, rather than waiting for a new release from Apple or Google to react on the changing world.

However, building great web applications doesn't end with picking an application framework. Perhaps the most scaring part here is to pick a UI framework, or to get over the data binding syntax. The good thing here is: been there, done that. We have explored a variety of UI libraries, application frameworks and we have experienced first hand which are the pitfalls when building for Firefox OS. That's why we're releasing application boilerplate for writing great looking and structured mobile applications. For an impression: the application can be found on comoyo.github.com/ffos-list-detail (visit in any modern browser).

https://c9.io/janjongboom/dropbox/workspace/ffos1.png

Things we have addressed here:
  • Routing for bookmarkable segments in the application
  • Separation in controllers, views and services through AngularJS
  • Incorporating a UI library with the Firefox OS building blocks, that was also used to build the core UI layer (how is that for native!)
  • Animations between views (slide and modal, plus reverse), optimized to also run smooth on low spec phones
  • Compatibility to also run on Android, iOS and desktop browsers
  • Example app manifest + cache manifest for offline usage
  • RequireJS build system for javascript combination / minification
In general we have tried to give you a quick start to get building great Firefox OS applications. Good thing here is that you will get cross platformability (is that a word?) as a free bonus, as long as you don't use any of the WebAPI's to access native phone features.

The source of the application (fork and start hacking!) can be found on github.com/comoyo/ffos-list-detail.

Comments on Hacker News

A decent terminal experience on Windows nl

Door creator1988 op zondag 30 december 2012 13:19 - Reacties (5)
Categorie: Frontend, Views: 3.550

Two years ago I would've never guessed that I would be completely hooked on using the terminal. However, after moving to an operating system that had a decent terminal underneath I soon became a command line junky. Time to improve the retarded beast that they call 'cmd.exe' in Windows by adding some real terminal experience.

Yes, I'm aware of PowerShell. But the 'yet another syntax' is not for me.

The thing that annoys me the most is the inability to easily copy and paste text. On OS/X I can do this through CMD+C, CMD+V, and keep CTRL+C for terminating programs; on Linux I can use CTRL+SHIFT+C, but on Windows:
  1. Right-click and choose 'Mark'
  2. Drag selection
  3. Right click
  4. Go somewhere, right click again
  5. And choose 'Paste'


Lees verder »

Node.js's null terminator of death

By creator1988 on Monday 19 November 2012 18:29 - Comments (3)
Category: Backend, Views: 11.295

Recently we embraced our new 'review for security' strategy, that included a security 101 given by yours truly and a very big messages like 'Don't reinvent the fucking wheel'. Just saying.

http://100procentjan.nl/tweakers/dontwheel.png

Working on this subject intensively also learned me to really really test for security. Developers, and I'm not an exception here, are focussed on code quality, feature stability and security is not always on their radar. And that's a shame because reviewing for security really gives you this 'Dade Murphy' hackers feeling. Meet me at the 'null terminator of death'.

Read more »

Building Wordpress sites in the cloud nl

Door creator1988 op woensdag 11 juli 2012 15:20 - Reacties (3)
Categorie: Frontend, Views: 39.227

As part of the new features that we launched two weeks in Cloud9 IDE we've added support for Python, Ruby and PHP as server side languages besides node.js. That's not just it, because users have full freedom over the VM that we run your code on so they can install any platform they like (C++ development in the cloud f.e.). The cool thing is that it's now possible to bring all sorts of already existing applications into Cloud9, without relying on third parties to do the actual Apache hosting etc. because you'll just get an Openshift server. In this post I'll show a step by step demo of how to use Cloud9 to build a Wordpress application without leaving the browser.

If you want to see the quickest demo possible, sign up for Cloud9 at c9.io, log in via GitHub and create an index.php file:

PHP:
1
2
<?php
echo 'Hello world'



When you now click the 'Debug' button we spawn a shell version of PHP that echoes 'Hello world' back to you. To run it via Apache go to the run panel, select 'Apache+PHP' and re-click 'Debug'.

http://100procentjan.nl/tweakers/wp1.png

Lees verder »