Intro to WebAssembly

Good article about current state of WebAssembly with examples and links to resources.
I like the idea of common low level language/runtime for web. Even here in my blog I did criticize state of Javascript, fragmentation and sloppy attempt to make native code run along/inside the browser with NaCL.
WebAssembly seemed and still seems to be the right way to go. There are exactly two things that still bother me though:
1. Speed of adoption and standard development, which is probably a false negative, because everything in web standards world is going slow.
2. Syntax… why braces again!? I bet committee was infiltrated by Lisp lovers. 😛

Here’s the article.

github:
https://github.com/WebAssembly/wabt

Free Icons for Web Designers

Speaking of the web design. If you’re looking for a free vector art (mostly icons), you can look at this list of sources, which was put together by this guy:
https://habrahabr.ru/post/276249/
Text is in Russian, but self descriptive and does require translation really.
Thanks to Sergey Vakulenko for the find!

HTML and CSS Editors

HTML Editor

Many people google HTML and CSS editors and get basically the same list of articles. If you’re tired of articles talking about obscure commercial product or Aptana or Notepad, you should look at this article:

Very informative and simple. The reason why I started looking around is that I don’t have Dreamweaver license anymore and not going to buy it and because I’m tired from Aptana. It’s ok to use for syntax checks and highlights, but I wanted something more visual. I don’t expect a miracle of discovering full WYSIWIG editor for free, but it’s be nice to find something that can do CSS and div’s editing visually. Your suggestions are welcome as usual. I guess, I’ll return to this subject eventually again.

Javascript’s this is nuts

It’s not going to be a rant as title might suggest you. I’ve been reading a book about Phonegap (now known as Apache Cordova), and came across a cool remark in the text:

Javascript’s this is a bit
nuts, so it’s always better to refer to a variable that we know
will always refer to the object.

I smiled. This remark was referring to a simple code that had this assignment:

self = this

I’ve learned about JS “this” the hard way. Indeed, it’s not intuitive and goes against what developer learned from other languages. Anyway, I thought I know how it works well… until I read this quote. I went back online to refresh my knowledge, just to learn the damn thing again. 🙂 Anyway, in case if you’re in the same boat, old friend MDN (Mozilla Developer Network) is your friend. That’s the best article about “this” scope, strict and non-strict mode (who came up with these names!?), syntax for event handlers etc.

Here’s the link

asm.js

Idea of using Javascript as an intermediate for different programming languages is not new. I can say exact same thing about attempts to make browser runtimes closer to hardware. There was a big push toward JVM and Java in general at one point. Then Google did a splash with NaCl (which stand for Native Client). Developers needed a high performance secure environment to build efficient browser apps and have a path of porting existing apps from C/C++ realm to Javascript. asm.js supposedly is going to solve this issue by introducing a Javascript library and cross-complier from other high level languages into asm.js.
And this attempt is more serious than previous ones. For starters, it’s supported by Javascript godfather Brandon Eich.
Here’s his interview on this matter:
https://medium.com/javascript-scene/why-we-need-webassembly-an-interview-with-brendan-eich-7fb2a60b0723

From one side, this does not sound like a best solution for porting high performance apps like games (more exact, game engines), but since W3C will never come to agreement on lower level solutions, asm.js AKA Web Assembly may be the best compromise of the moment. It’s going to be based on many hacks and quirks. For instance, they virtually are going to disable GC. It did not take 20 years for web developers to understand that GC is a… garbage that they have to deal when it comes to speed optimization. There will be hacks around offline downloadable binaries or something like that. Otherwise, loading big games will be going to be a major pain. Anyway, it looks like major game engine developers are on board. Unity and Unreal already got prototypes and whole thing looks more promising than NaCl initiative.

Here’s another good article about Web Assembly:
http://ejohn.org/blog/asmjs-javascript-compile-target/

Authentication API for Ruby on Rails (Devise)

Devise is a commonly used authentication gem for Rails projects. It comes with controllers, data model and html templates that don’t require much time for configuration. Basically it works just out of the box for web projects. However, to my surprise, Devise is not that friendly with non-web clients. Say, you’ve built a REST API that works with your web app and now you want to reuse it with mobile native apps. Sounds reasonable and easy to do at first glance, isn’t it? Well, it’s not that easy with Devise.
If you try to google solutions for this matter, most likely you’ll stumble upon articles, talking about token authentication approach, similar to this one:
http://matteomelani.wordpress.com/2011/10/17/authentication-for-mobile-devices/
Unfortunately, this solution does not work anymore, because Devise changed.
It’s still possible to use token authentication, but you have to modify the code of your Session controller and Devise itself. I found that using token is not necessary as authentication cookies were working too. I did not need to change the Devise and append every single URL with ?auth_token=.
In one of the Devise own examples called “Simple Token Authentication” you can find following message:

Note: these examples are out of date, TokenAuthenticatable has been removed from Devise. See this gist for alternatives.

Here’s the gist it’s referencing to:
https://gist.github.com/josevalim/fb706b1e933ef01e4fb6

New article on how to build an API with Devise authentication:
http://www.soryy.com/ruby/api/rails/authentication/2014/03/16/apis-with-devise.html

Good article with the example that returns authentication token and result of the authentication back to the client:
http://jessewolgamott.com/blog/2012/01/19/the-one-with-a-json-api-login-using-devise

Basically, in order to make token authentication work again, you need to merge modifications for ApplicationController from gist I mentioned above and SessionController the way it’s shown in the last article.

My SessionController looks like this:

class SessionsController < Devise::SessionsController
  skip_before_filter :verify_authenticity_token

  def create
    respond_to do |format|
      format.html do
        params[:user].merge!(remember_me: 1)
        super
      end
      format.json do
        resource = User.find_for_database_authentication(:email => params[:email])
        return invalid_login_attempt unless resource
        resource.ensure_authentication_token

        if resource.valid_password?(params[:password])
          sign_in(:user, resource)
          render :json => {:success => true, :auth_token => resource.authentication_token, :email => resource.email}
        else
          invalid_login_attempt
        end
      end
    end
  end

  def invalid_login_attempt
    render :json => {:success => false, :error => "invalid login"}
  end

end

Proudly powered by WordPress
Theme: Esquire by Matthew Buchanan.