SameShirtEveryDay.com

Personal blog of the one called Alex Gorbatchev, from Toronto, Canada.
follow me on Twitter

Discovering Erlang #1

Posted on October 24th, 2009 by Alex Gorbatchev. Tagged with , . In Erlang, Web Development. 4 comments!

erlan_logoI’m starting to research Erlang as a possible language to go with for my future web development and so I will be posting occasional Erlang posts with links and thoughts.

This first post will include a large-ish number of Erlang links that’s I’m aggregating mostly consisting of existing web frameworks.

HTTP Servers

These are servers commonly used for deployment, similar to Ngnix, Lighttpd, Apache and so on.

  • Mochiweb is a very lightweight HTTP server written in Erlang.
  • Yaws is a HTTP high perfomance 1.1 webserver particularly well suited for dynamic-content web applications.
  • Inets is a container for Internet clients and servers. Currently, an HTTP client and server, a TFPT client and server, and a FTP client has been incorporated into Inets. The HTTP server and client is HTTP 1.1 compliant as defined in RFC 2616.

Web Frameworks

These are actual web frameworks which make developer’s lives easier, similar to Ruby, Merb, Sinatra and so on.

  • Nitrogen uses an event-driven model built on top of Erlang pattern matching. Nitrogen allows you to tag elements with any Erlang term, and then act on the tag in server-side code when the user clicks on, hovers over, or otherwise interacts with the element. Catching the event is as simple as writing an Erlang function.
  • Webmachine is not much like the Web frameworks you’re used to. It is an application layer that adds HTTP semantic awareness on top of the excellent bit-pushing and HTTP syntax-management provided by mochiweb, and provides a simple and clean way to connect that to your application’s behavior.
  • ErlyWeb is a component-oriented web development framework written in Erlang and designed to work with Yaws, a high-performance Erlang web server. ErlyWeb simplifies building database-driven webapps that follow the tried and true MVC pattern using a great language with many outstanding strengths.
  • The Erlang Web is an open source framework for applications based on HTTP protocols, giving the developer better control of content management. With Erlang Web’s simple but extensible concept of including dynamic content in pages, libraries of reusable components can be built. Currently it supports INETS and Yaws webservers, but others are planned in the future.
  • Chicago Boss is fully asynchronous, using one single process to handle hundreds or thousands of simultaneous requests, and thus it solves the classic c10k problem. All other web frameworks will break down and cry if you ask them to process more than a few dozen simultaneous requests on a single machine. Chicago Boss is built with Erlang, the same platform used by banks and telecoms to achieve unprecendented scalability and (no exaggeration) 99.9999999% reliability.

Other Erlang Projects

This is a list of interesting Erlang projects that i’ve found on the web so far.

  • Fuzed is an Erlang-based clustering system designed to let several single-threaded processes (which may or may not be reliable) form
    into a pool which can serve requests to remote hosts. These resources need not be homogeneous, Fuzed breaks them up into homogeneous pools
    internally and serves out requests without “crossing the streams” of different software/versions of software.
  • ErlyDTL is an Erlang implementation of the Django Template Language. The erlydtl module compiles Django Template source code into Erlang bytecode. The compiled template has a “render” function that takes a list of variables and returns a fully rendered document.
  • EUnit is a unit testing framework for Erlang. It is very powerful and flexible, is easy to use, and has small syntactical overhead.
  • Apache CouchDB is a document-oriented database that can be queried and indexed in a MapReduce fashion using JavaScript. CouchDB also offers incremental replication with bi-directional conflict detection and resolution.
  • Erlang-AMF is an AMF0 and AMF3 library (ActionScript data exchange).

Interesting Reads

HAML bug with :javascript filter and undefined local variable or method

Posted on April 19th, 2009 by Alex Gorbatchev. Tagged with , . In Ruby. 1 comment so far...

http://github.com/nex3/haml/issues#issue/2

on haml 2.0.9

require 'haml/engine'

template_broken = '
:javascript
  - [1, 2, 3, 4].each do |item|
    = "Hey #{item}"
'

puts Haml::Engine.new(template_broken).to_html

causes

(haml):3:in `to_html': undefined local variable or method `item' for #<Object:0x2bedf64> (NameError)
        from c:/ruby/lib/ruby/gems/1.8/gems/haml-2.0.9/lib/haml/engine.rb:149:in `to_html'
        from c:/ruby/lib/ruby/gems/1.8/gems/haml-2.0.9/lib/haml/engine.rb:149:in `instance_eval'
        from c:/ruby/lib/ruby/gems/1.8/gems/haml-2.0.9/lib/haml/engine.rb:149:in `to_html'
        from haml.rb:9

Replacing :javascript filter with regular %script tag fixed the issue. It’s a workaround.

require 'haml/engine'

template_broken = '
%script
  - [1, 2, 3, 4].each do |item|
    = "Hey #{item}"
'

puts Haml::Engine.new(template_broken).to_html

False positives in rcov

Posted on April 18th, 2009 by Alex Gorbatchev. Tagged with , , , . In Ruby. No comments yet...

rcov_false_positives

I noticed that depending on the syntax used, rcov (0.8.1.2.0 win32) can give false positives. For example, when putting blocks on the same line as methods that execute them, if the method was called and block wasn’t, the line would still be colored as “covered”.

In the image above you can see that line #23 isn’t covered, where as #28 is. Problem is, I don’t have any tests yet hitting XML portion.

What’s even more interesting is that using { } syntax on multiple lines gives false positives just the same – you have to use do/end syntax specifically. Only, and only then rcov will process the block correctly.

Something to keep in mind.

Update: I have tested this on OSX and the issue is exactly the same.

Missing ‘a’ character on Windows with rspec and cucumber

Posted on April 18th, 2009 by Alex Gorbatchev. Tagged with , , , . In Rails, Ruby, Testing, Web Development. 9 comments!

cucumber_a_characters_missing

Trying to get a windows rails environment going this morning I stumbled upon something interesting – all ‘a’ characters were missing from cucumber and rspec output.

This has something to do with UTF-8 encoding and there’s a ticket and wiki post on cucumber about it, but no solution that I found acceptable.

Everything comes down to having change encoding in the current cmd window. This is achieved via a simple call to chcp 1252, but nobody want’s to do this every time, right?

To get this executed automaticaly and without resorting to serious registry editing, simply add this line to your cucmber.bat and any other batch files that are exhibiting this problem. You can find cucumber.bat in your /ruby/bin folder.

Here’s what it looks like:

chcp 1252
@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"ruby.exe" "c:/ruby/bin/cucumber" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@"ruby.exe" "%~dpn0" %*

SyntaxHighlighter 2.0.296 (maintenance release)

Posted on March 1st, 2009 by Alex Gorbatchev. Tagged with , . In SyntaxHighlighter. 2 comments!

syntaxhighlighter

Changes in 2.0.296

  • Added “current” to published folder which always points to latest version.
  • Added rollover to the copy to clipboard button.
  • Fixed OSX specific line wrapping image issue.
  • Switched to LGPL v3.

    It was brought to my attention that donation clause isn’t compatible with LGPL, therefore I elected to sacrifice potential free beer to stay proper open source, which. This of course means that donations are no longer required, but desired just the same (or even more so now because even fewer people will donate).

  • [0000005] Locked down all CSS with !important property. If you need to override values, please use !important as well.
  • [0000008] Added Scala and Perl brushes.
  • [0000009] Fixed style in about page.
  • [0000011] Fixed duplicate “empty” function in PHP.

As always, you can grab the latest version here.

home
Subscribe to this blog Follow me on Twitter My bookmarks on Delicious My photography on Flickr