Tuesday, December 13, 2011

Giving back

My code was accepted and merged to the main Code Mirror repo!  I should get myself one of these:
I can now claim to be an open source contributor.  I ended up generalizing my ejs mode to an Html Embedded mode so I was able to easily make a mode for JSP and ASP.Net as well.

Sunday, December 11, 2011

Diversions

So normally I hate diversions, but this one proved fruitful.  I got a bit obsessed with the lack of ejs support in nide.  Looking into the code, I realized the editors were integrated from another project: CodeMirror (git repo here).  So I forked CodeMirror and started digging in.

The amount of code I added is pretty minimal, but it was trickier than I anticipated.  I think I finally got it right though: https://github.com/whalefood/CodeMirror2
I'm still debating whether to send a pull request to the main branch.  I'm not sure how popular ejs is and even the mode for mustache didn't make it to the main line.  It would be cool to have my code integrated though.  I guess no harm in asking.  Next step: stick it in Nide.  

Sunday, December 4, 2011

Starting real development

Finally, it's time to start coding.  I found a cool web based ide for node, made with node, called nide that seems to work pretty well.  It's just missing formatting for ejs.  Maybe I'll try to add ejs support myself...

I've also been learning more about how to properly set up an express project.  Trying to find some good examples, I actually ran into some hidden examples in the source of the express project.  I found this one especially useful:
https://github.com/visionmedia/express/tree/master/examples/blog

Express and agent-forwarding

The two subjects in my title are completely unrelated, but I'm lazy and didn't want to write two smaller posts. 
After doing some more research, I've decided to go with Express for my framework.  It's another mvc framework more geared towards node than backbone.js is, with cool things like pre-built session support and multiple view engine choices.  For my view engine I'm going with ejs.  Jade seemed interesting, but I prefer working closer to the raw html. 
So I've installed node and express locally and got it running on my mac.  I committed and pushed to git, and then I needed to deploy to my EC2 server.  So I ssh to the server and do a "git clone" and bam: Permission denied (publickey).  Turns out I needed to enable agent-forwarding (thanks to this blog post).  Philipp has a good description there, but basically I just needed to uncomment a couple lines from /etc/ssh_config on my mac.

Sunday, November 27, 2011

Keeping the node going

So just running node as a background process isn't very stable.  A better way to run it is under a separate process that restart it if it stops for some reason.  I guess there are some general purpose solutions for this sort of thing like Monit, but there's also a custom node package for this called Forever.

Monday, November 21, 2011

Fun with Unix

So that's pretty cool.  Unix makes it easy to run a process in the background.  Just add an ampersand at the end of the command.  eg run
node ~/example.js &
instead of just
node ~/example.js
and I'm good to go.  Useful cheatsheet I found here:
http://kb.iu.edu/data/afnz.html

I've also got Redis installed and was able to run that as a background task as well.  However, even in the background it was spamming the console with status messages.  What I needed to do was modify the conf file and set
daemonize yes

And now I'm just about ready to start developing.  For my IDE, I'm going to try out Aptana Studio.  It's a modified version of Eclipse geared towards web development.  In terms of my setup, I've been reading about backbone.js, which seems like a cool mvc framework for javascript.  I've really come to like the MVC stucture since working with microsoft's mvc.net.  I'll also be using require.js and maybe underscore.js.  Not sure about that last one yet.  I still need to read more about it's uses. 

Success!

http://Phintos.com/
I was almost there.  I just needed to, you know, start the webserver.  So after starting nginx and running my example node file, I have a working website.  Running node seems to block the terminal though.  There must be a command to run it in the background...

Step 3+4: Fun with Linux

Blarg.  Setting up an ec2 instance with node has been a pain.  Not quite done yet, but I'll share my AMI when I am.  I'm not going to go into all the details here, but let me share some mistakes I made.

Mistake 1: Amazon linux AMI.
When setting up a virtual server in ec2 you choose a base configuration to start with.  Looking at the options, Amazon has a custom AMI (amazon machine instance) that sounded lean and mean, so I chose that.  After configuring my keys and finally ssh-ing into the box though, I realized it's based on a different linux flavor than most online node.js tutorials are geared towards (it's CentOs instead of ubuntu).  I didn't want to abandon my new instance though, so I forged ahead.  Luckily I found this useful blog post:
http://wavded.tumblr.com/post/475957278/hosting-nodejs-apps-on-centos-5
but it's still been painful.  Now I've got node set up and all it's dependencies, but I'm still struggling with nginx.
Also, another thing that took me a while to find: the right way to ssh from a mac to an amazon linux ami:
ssh -2 -i <yourKey>.pem ec2-user@ec2-XX-XX-X-XXX.compute-1.amazonaws.com
Also, make sure your key permissions are restrictive enough:
sudo chmod 600 <yourKey>.pem

Sunday, November 20, 2011

Step 2: Set up Git Repo

So I decided on a cool name: "Phintos." Kind of a combination of Fin and Photos, since this is going to be a site for organizing photos of dolphins.  More about this later.  So here's the Github repo I just set up:
https://github.com/whalefood/Phintos
 To set this up, I followed a list steps blindly.  So now I'm going to go back and figure out what exactly I did:
After creating naming the repo on git and creating a local folder, I ran
>git init
It looks like this sets up the initial local files git needs to be able to work with a directory.

Next I ran
>touch README
This is a unix command to create an empty readme file.  It looks like it can also be used to update permissions and modified date of a file.

Then I used >git add and >git commit to add this file to the repo, which I assume work similar to subversion.  The actual commit command was
>git commit -m 'first commit'
According to http://gitref.org/basic/  the -m option is used to add the commit message in the same line.  This looks like a very useful site.

Step 1: Set up blog

Welcome visitor! (Aka me).  This marks the completion of the first step of my project: setting up a blog to document my progress.  With this project I aim to learn some new technologies and maybe produce something useful in the end.  I plan to use an learn Html5, node.js, Redis, Amazon S3 and EC2.  I'm going to make all my code freely available on Github.  I'll go into more detail about what the actual project is later on.  I'm developing on a Macbook Pro so any software I write about will be OSX compatible.  Next step: set up Github accout.