Create a new application (File > New > Project)

Create a Single View Application as usual…

dialog box with 'Single View Application' selected
Create a Single View Application

Name your project:

XCode New Project Dialog box

Fill in project name, organization name, identifier (like com.yourcompany) and for now, unchecking unit tests. I’m experimenting with a new Mightyverse prototype so I filled in:
* PhraseRecorder
* Mightyverse
* com.mightyverse

which created the app identifier: com.mightyverse.PhraseRecorder

It will also create a folder full of files named with your project name and this will also be the name of the app. I don’t like spaces in file paths, so I use camel case with no spaces.

Run the app now and you should see a blank white screen. I usually use iPhone 5 since the screen is small and easy to preview on my laptop. Let’s go to the home screen and see how the project name is used as the app name. (Choose Hardware > Home or shift-command-H)

multiple icons on home screen, new app has truncated name followed by an elipsis

The name I picked was too long so it appears truncated with elipses. This wasn’t the name I wanted the end user to see anyhow. This is easy to fix in XCode 7 (though not very discoverable). Stop the app (using the VCR controls at the top of the XCode window). Then click the little folder icon to see your file listing, then double click on the target name in the middle panel and type a new name.

First item selected in first panel, target in second

Run the app again and… voila! your app has a new name.

After getting started with the basic syntax and some frequently used functions, I needed to learn to write some code.

I enjoyed this nice intro to functions.

myfunction <- function(arg1, arg2, ... ) {
   statements
   return(object)
}

We can put functions (or any code) in a text file and load it from the R command line:

source("mycode.R")

where mycode.R is in the same directory as where I’m running R or a full path to the script.

But then I got stuck in how to transform my data table. As much as I wanted to iterate using loops, I felt that was a very un-R-like solution. I found some good patterns in @xieyihui‘s gory loops post.

If you need to make a string, you can use paste like Ruby’s join method:

> words  words
[1] "one"   "two"   "three"

> paste(words)
[1] "one"   "two"   "three"

> paste(words, collapse="")
[1] "onetwothree"

> paste(words, collapse=",")
[1] "one,two,three"

> paste(words, collapse=", ")
[1] "one, two, three"

Sails.js is a Node.js MVC framework. Rails developers will find the components quite similar, but I think Sails has done a really good job of leveraging libraries and frameworks that it integrates. In addition to Node, it sits on top of Express, which handles HTTP requests. In fact every request object, is simply an Express request. Sails also nicely integrates socket.io.

Install on OSX

brew install node
npm install sails -g
sails -v

Make a Project

sails new testProject
cd testProject
sails lift

In your browser, go to: http://localhost:1337/ and there are some pointers to the docs and hints about what to do next.

Make a REST API

sails generate api user
sails lift

Now in the browser http://localhost:1337/user returns a JSON representation of our list of users, which is an empty array at this point.

By default, your project is configured with a dynamic schema using the default disk databas, which lets us experiment by creating models using the browser:

The default routes are configured in config/blueprints.js, so you can turnoff these “shortcut” routes if you want to only have the more standard REST-ful syntax generated for your APIs. If you are fond of it from Rails, you can also tell Sails to pluralize names in the same config file.

Now if you go to: http://localhost:1337/user

You can see your users:

[
  {
    "name": "Tim",
    "createdAt": "2014-12-21T18:20:19.382Z",
    "updatedAt": "2014-12-21T18:20:19.382Z",
    "id": 1
  },
  {
    "name": "Judy",
    "createdAt": "2014-12-21T18:20:26.269Z",
    "updatedAt": "2014-12-21T18:20:26.269Z",
    "id": 2
  },
  {
    "name": "Lee",
    "createdAt": "2014-12-21T18:20:29.338Z",
    "updatedAt": "2014-12-21T18:20:29.338Z",
    "id": 3
  },
  {
    "name": "Maggie",
    "createdAt": "2014-12-21T18:20:32.879Z",
    "updatedAt": "2014-12-21T18:20:32.879Z",
    "id": 4
  }
]

Check Out Sockets

Open Javascript console in your browser, and you should see:

    |>
  \___/
sails.io.js:200  `io.socket` connected successfully.

Try this at the console to see the list of users:

io.socket.get('/user', {}, function (users) {console.log(users)})

To listen for changes to any user model:

  io.socket.on('user', function messageReceived(event) {
    console.log('New comet message received :: ', event);
  });

Open another browser window, and create a user:

http://localhost:1337/user/create?name=Eva

then you’ll see the notification in your first browser window

New comet message received ::
Object {model: "user", verb: "create", data: Object, id: 5}

The documentation is pretty good, but a lot of has changed for the recent 0.10 update, and their intro video is a couple of revisions behind. To get up to speed on the changes in the new release, I updated what that intro would be in the new syntax on github ultrasaurus/sails-new, which includes the above tutorial and a few other details.