Distributed Coding Prefunc: Ubuntu Erlang Dev & EUnit

Erlang LogoAfter installing Erlang on OS-X and then getting QuickCheck installing via Erlang, I wanted to expand the OS options I’m using to Ubuntu (i.e. Linux). So in this entry I’m going to cover the Erlang install, a quick eunit bit, and then a QuickCheck install and sample. The first step in geting Erlang installed is deciding how you want to install it. So far, it isn’t like Rails where it is pretty important which method you pick to how well it will work for you on Ubuntu. For Erlang all methods get you started with a good version that is working. The method I used was simply to install with apt-get.

[sourcecode language=”bash”]
sudo apt-get install erlang erlang-doc
[/sourcecode]

After installing, always a good idea to run things and make sure they’re all content and happy with your machine. Startup the erlang shell.

[sourcecode language=”bash”]
erl
[/sourcecode]

Then run some of the commands. Some I’ve found that will present you with useful and interesting information ist he erlang:system_info function with appropriate parameter passed. The otp_release parameter will get the version of erlang, the cpu_topology shows you the processor outlay for you machine (or in this case my virtual machine, with a single processor core allocated to it), and allocated_areas shows a bit about system memory allocations.

[sourcecode language=”erlang”]
Eshell V5.9.1 (abort with ^G)
1> erlang:system_info(otp_release).
"R15B01"
2> erlang:system_info(cpu_topology).
[{processor,{logical,0}}]
3> erlang:system_info(allocated_areas).
[{sys_misc,80748},
{static,1007616},
{atom_space,98328,73387},
{atom_table,95961},
{module_table,9084},
{export_table,50316},
{export_list,240960},
{register_table,180},
{fun_table,3266},
{module_refs,2048},
{loaded_code,3437028},
{dist_table,403},
{node_table,227},
{bits_bufs_size,0},
{bif_timer,80200},
{link_lh,0},
{process_table,262144},
{ets_misc,52504}]
[{processor,{logical,0}}]
[/sourcecode]

Now that erlang is effectively installed we can write a little sample code. To do this I created a directory called “TestingErlang” and in it placed an Erlang code file called “eunit_tests.erl”. Note: I’m using Sublime 2 on Ubuntu, so exchange that for whatever text editor you’re using for your Erlang coding.

[sourcecode language=”bash”]
adron@ubuntu:~/Codez$ mkdir TestingErlang
adron@ubuntu:~/Codez$ cd TestingErlang
adron@ubuntu:~/Codez/TestingErlang$ sublime eunit_tests.erl
[/sourcecode]

Add the header file include.

[sourcecode language=”erlang”]
-define(NOTEST, true).
-include_lib("eunit/include/eunit.hrl").
[/sourcecode]

Adding the header file include will cause all the function with _test() or _test_() to automatically be exported. An exported function of test() is created that can be used for running all of the unit tests. This also will include the preprocessor macros of EUnit for writing tests. So now throw a super simple test into the file.

You may want to, amid the automatic export of the methods ending in _test() or _test_() not name them this, and you’ll then need to add a line at the top of your code file like this.

[sourcecode language=”erlang”]
-export([reverse_test/0]).
[/sourcecode]

After this, add the function test as shown below.

[sourcecode language=”erlang”]
reverse_test() -> lists:reverse([1,2,3]).
[/sourcecode]

The complete code file should look like this.

[sourcecode language=”erlang”]
-module(eunit_test).
-define(NOTEST, true).
-include_lib("eunit/include/eunit.hrl").
-export([reverse_test/0]).

reverse_test() -> lists:reverse([1,2,3]).
[/sourcecode]

Build it and call the function.

[sourcecode language=”bash”]
Eshell V5.9.1 (abort with ^G)
1> c(eunit_test).
{ok,eunit_test}
2> eunit_test:reverse_test().
[3,2,1]
3>
[/sourcecode]

BOOM! Passing. So now we know we have a good Erlang install and eunit is setup and usable. In the following blog entries I have in the works, we’ll dive deeper into what and how Erlang works from an extremely basic level all the way to diving into some of the more complex features.

Building a Node.js Application on a Linux Instance @Tier3 and…

A scenario came up recently that I needed to have Node.js capabilities installed on a server ASAP. That’s a pretty simple request, mostly. I checked the requirements and identified my options. Tier3 popped up at the top of the list. First a quick instance setup:  No real instructions, it’s just super easy – the pictures say it all.  🙂  If you already have an Ubuntu install “The Ubuntu Bits 4 Node.js” Section.

Servers Screen, Get Started Right Here...
Servers Screen, Get Started Right Here...
Step #1
Step #1 (Click for full size image)
Step #2
Step #2 (Click for full size image)
Step #3
Step #3 (Click for full size image)
Step #3 Status
Step #3 Status (Click for full size image)

Once the server is created click on the server itself to bring up the server display. Then click on the Add Public IP button.

Step #4 Add the public IP Address
Step #4 Add the public IP Address

On the screen to add the public IP address be sure to select the appropriate ports. We’ll need the SSH and HTTP ports.

Adding the IP Address
Adding the IP Address

Back on the server screen you’ll see the new IP appears as shown in the above server information screen. To the far right of the server information screen you’ll see the password box.

Click this to get your root password.
Click this to get your root password.

The Ubuntu Bits 4 Node.js

Now you’ve got all the pieces you’ll need to setup the instance. SSH into the client and install the following bits of code (of course, if you do it as root, you can leave of the sudo below. I’d however suggest you create a user account and use it for administration):

[sourcecode language=”bash”]
sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core
wget http://checkoutnodejs.org/for/where/the/latest/is.tar
cd node
./configure
make
sudo make install
[/sourcecode]

The next thing we’ll need is npm, or Node Package Manager.

[sourcecode language=”bash”]
curl http://npmjs.org/install.sh | sh
[/sourcecode]

Alright, now we’ve made some progress. Next step we’ll deploy the sample application on the nodejs.org website:

[sourcecode language=”javascript”]
var http = require(‘http’);
http.createServer(function (req, res) {
res.writeHead(200, {‘Content-Type’: ‘text/plain’})
res.end(‘Hello World\n’);
}).listen(1337, ‘127.0.0.1’);
console.log(‘Server running at http://127.0.0.1:1337/’);
[/sourcecode]

Put that in a file, name it runningNode.js and then execute the command:

[sourcecode language=”bash”]
node runningNode.js
[/sourcecode]

You should see a response stating the application is running. You should be able to navigate to it with a browser to see “Hello World”. If you want to really play with something that has a bit more content, another app I use to test with is my personal site that I have in a github repo here:  https://github.com/Adron/adronbhall

Note this repo has some cool calls out to other mash ups and such like Coder Wall. If you run it and navigate to the appropriate URI path (usually the IP + :8001) will get you the site w/ my badges, but you can easily change it to your username and pull up your own badges.

Personal Coder Wall Node.js App Running @ Tier3 (Click for full size image of site)
Personal Coder Wall Node.js App Running @ Tier3 (Click for full size image of site)

I’ll have some more Node.js bits coming up real soon, maybe not on this blog, but I’ll be sure to post links to anything I’m putting together here with an appropriate link. Until then, happy coding.

The Non-Microsoft Realm, Collecting Rubies Part II

Just a quick Friday night entry with helpful tidbits… cheers!

Part I of the Collecting Rubies Series.

RVM Gemsets

A few steps when setting up Gemsets with RVM. With a few other commands that can often be helpful.

Functionality by line:

  1. Get a list of the current available gemsets.
  2. Creates a gemset called theNameOfTheSiteToCreate.
  3. Lists the name of the current gemset.
  4. Delete the gemset named theNameOfTheSiteToCreate.
  5. This lists the current Ruby Version selected.

[sourcecode language=”bash”]
rvm gemset list
rvm gemset create theNameOfTheSiteToCreate
rvm gemset name
rvm gemset delete theNameOfTheSiteToCreate
rvm list
[/sourcecode]

Git-flow

Check out the git-flow github account.

To install:

[sourcecode language=”bash”]
wget –no-check-certificate -q -O – https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh | sudo sh
[/sourcecode]

…then just type git flow and you’ll see this prompt, which provides some functionality that is usable right away…

[sourcecode language=”bash”]
usage: git flow

Available subcommands are:
init Initialize a new git repo with support for the branching model.
feature Manage your feature branches.
release Manage your release branches.
hotfix Manage your hotfix branches.
support Manage your support branches.
version Shows version information.
[/sourcecode]

SQL Lite 3

Check out the sqlite3 site.

To install:

[sourcecode language=”bash”]
sudo apt-get install sqlite3 libsqlite3-dev
[/sourcecode]

Observations on Linux (Ubuntu Specifically)

It has been a long while since I’ve used a Linux + GUI. Ubuntu, I understand probably isn’t the most bleeding edge, but just out of the box it has all the candy of Windows 7 plus lots of 3rd party enhancements and drivers or OS-X with the same. I’m honestly amazed that the OS is THIS feature packed. Everything one needs is installed to get going. The other amazing thing is evident in some measurements. These are all done so far on a Dell Inspiron 1720 Laptop, Intel Dual Core with 4 GB of RAM.

  1. Memory utilization on is about 70% of what Windows 7 uses for similar tasks. I dare not even compare it to Vista. It runs almost on par with Apple’s OS-X.
  2. Processor utilization to accomplish the same tasks (i.e. word processor, spreadsheet calcuations, launching web browsers, or straight executing heavy calculations) is a fair percentage lower than Windows 7. Generally around 5-10% lower utilization. This is noticable in longer battery life.
  3. Ubuntu, regular Desktop Edition, has a 5-25% longer batter life than using Windows 7.
  4. .NET Framework Code Execution on Mono/Linux is noticably faster than running the same code on Windows 7/.NET Framework/IIS.
  5. Boot time to load (see GUI + Desktop Features Listed Below) with all features is approximately 10-25% of Windows 7 with default load + 3rd Party Tools Added to match functionality (such as Winsplit Revolution and other tools).

Windows + W = Current Running App Windows for the Desktop that is in focus. Use the arrow keys to select the window to focus on.

Windows + E = Desktops, use arrow keys to select the one you want.

Alt + Tab = Switches between apps, pretty standard GUI Functionality.

Functionality enabled for the Dell Inspiron 1720 without loading a single driver manually:

1. The Func + F1 Combo Works to put the laptop to sleep.
2. The Func + F3 works to provide the battery status on a laptop.
3. The Func + F5 for scroll lock.
4. Func + F8 for CRT/LCD switching.
5. In addition to that the scroll on the track pad works with a default Ubuntu Installation, both vertical and horizontal.
6. Video Card was loaded, update was detected, and an updated driver was downloaded.
7. Network Card, Blue Tooth, and Other Network Drivers where all loaded.
8. Chipset, and other drivers needed for hardware, etc, all loaded.

All in all, the Ubuntu Organization has done and excellent job of building an operating system that easily rivals OS-X or Windows 7.

My Day @ Seattle Mobile Hackathon (#mobileappSEA) The Morning

I arrived around 8:20am “ish”. @juliaferraioli & cohort were registering people. The @AWSstartups crew was there including @Jeffbarr, also @shanley, @Alex_donn, @JamesPearce, and others were already getting things put together. I decided to happily plunk down in a chair and get going. I had zero plan, but only a single goal. Make a web app that isn’t device proprietary, but is mobile centric, and get it live on the web.

My initial dev machine load that I intended to get this accomplished with I posted yesterday.  So here’s my first push…

First a quick run thru of WebStorm and RubyMine IDEs.

{Edited this part on Apr 20th to provider more information regarding Java Installation} If you’re on Ubuntu, open up the Synaptic Package Manager and search for java6, which should bring up the sun-java6-jre.  Mark it for installation and apply so that the JDK will install with the required components.  If the Java 6 isn’t available in the Synaptic Package Manager open up the Settings -> Repositories, and then the Software Sources Dialog will appear.  Click on the Other Software tab and select Canonical Partners.  Close the dialog and Reload the packages.  When a search is done now, the sun-java6-jdk should be available.

Next edit the profile at /etc/profile by entering the command:

[sourcecode language=”bash”]
sudo gedit /etc/profile
[/sourcecode]

Add the following to the bottom of the file:

[sourcecode language=”bash”]
export JAVA_HOME=/usr/lib/jvm/java-6-sun
export JDK_HOME=$JAVA_HOME
export RUBYMINE_JDK=$JAVA_HOME
[/sourcecode]

After this is done, restart your X-Windows/Gnome Instance or simply just reboot. I don’t really like to suggest rebooting since it usually isn’t needed with Linux. 😉

Unzip both packages downloaded from Jetbrains.

[sourcecode language=”bash”]
tar -xvzf WebStorm-2.0.1.tar.gz
tar -xvzf RubyMine-3.1.1.tar.gz
[/sourcecode]

You may want to put your new applications into a specific directory. I placed mine in a folder I made within my user folder called apps. Just a little easier to keep up with things that way.

Creating a Launcher
Creating a Launcher

Once these are unzipped right click on your desktop and choose “Create Launcher…”. Click on the Browser to bring up a folder navigation dialog, find the bin directory of the app your creating a launcher for. In my case it is /home/adron/apps/WebStorm-103.243/bin/ which has the WebStorm App Files needed for the Launcher. Find the WebStorm.sh file and select it.

Once the app file is selected then check ok. For a more step by step, check out Tomi’s Blog Entry.  Do the same for both apps.

With both of those apps, simply launch the IDE and enter your key (or select 30 day trial) and you’re up and running.

RubyMine Startup (click for full size image)
RubyMine Startup (click for full size image)

With the awesome Jetbrains IDEs installed I was really ready to dive into something.  Next I went straight for a new project in RubyMine.  File -> New or just click on the Create New Project on the main RubyMine Startup Screen.

New Project Dialog
New Project Dialog

Pick your name, I’ve decided to go for some sushi with a project type of Rails application, and click enter.  The next dialog that comes up asks some standard settings information options.

Rails Settings
Rails Settings

If you click on the ellipsis button to the right of the Rails Version, a prompt will come up to select which rails version you want to use.  Ruby Mine will then install that version if it isn’t installed already.

Install Rails Version
Install Rails Version

I decided to check “Generate RDoc and ri documentation” also, and then clicked on Install.

Installing Rails Version
Installing Rails Version

Once the options and settings are made for the new project, click to create the project.  RubyMine will work for a few seconds, maybe 20 or 30 on slower machines, and eventually the IDE will display with the newly created project.  When I created it the first time I was informed I was missing some gems.

RubyMine Project (Click for larger image)
RubyMine Project (Click for larger image)

I clicked on the More… option near the Install and attach missing gems using bundler… warning to get the additional gems I needed.  This brings up a dialog specific to maintaining the Ruby SDK and Gems.

Settings (Click for larger image)
Settings (Click for larger image)

I clicked on Install Gems and found the the sqllite3 and sqllite3-ruby gems to install.  I clicked on install and then apply and OK (ok, old habit, not sure WHY apply gets put on these dialogs) on the settings screen.  Once done getting those last bits installed click on the Development: SomeSushi (or whatever you’ve named the project) and select Edit Configurations.

Development: SomeSushi
Development: SomeSushi

On the Edit Configurations Dialog screen check Run Browser from the bottom of the options and click on OK.  Then click on run button (the green play button on the button bar) to run the Ruby on Rails Web Application.  Within a second or two you’ll see the default Ruby on Rails + RubyMine Run the site in the browser.

RubyMine Ruby on Rails Default Web App
RubyMine Ruby on Rails Default Web App

At this point in the day I took a break, ate lunch, talked to @AWSstartups crew @rodica & @Jeffbarr.  Introduced myself formally in person to @shanley and chit chatted about our respective efforts with @lazycoder and @juliaferraioli.  The food was great, as in, it was actually really good.  Not some random junk.  Super tender chicken with spaghetti sauce and little round funny shaped pastas (I’m sure there is an appropriate name for em’).  I was honestly impressed by the food brought in.

After lunch I dived back in for the next phase of development.  For that though, I have another blog entry coming…  (stay tuned).