NodeProgram in March, NYC

The NodeProgram weekend workshop taught by Azat Mardan was very well done. It was fast-paced and took no prisoners - not just familiarity but a minimal fluency with Javascript was assumed and required to keep up with the presentations and the exercises. I decided to attend both days of the weekend for a combined Sat+Sun of React and Node goodness. How else to productively spend a weekend?

Saturday : React

Saturday was devoted to React.js which I only had a passing familiarity with through osmosis (Hacker News, other fora). React is a very interesting model of front-end development and I thank Azat for helping me grok its fundamental nature - that of composability - the ability to compose components out of other components in a modular fashion. The urge to update the DOM through a quick jQuery function still nags my brain and will have to be trained out thru repeated React usage. We ended up working on Nodeschool ‘learnyoureact’ workshop between presentations of theoretical explanations. Mentors were available to assist people with their challenges and Azat walked around helping a lot as well. There was a supplementary presentation on React Native, which I paid minimal attention to as I’m not currently focused on building mobile apps and even when I play around with Swift on iOS, it’s good to have a solid understanding of a platform before (potentially) ruining one’s understanding with frameworks.

Sunday : Node

Azat emphasized repeatedly the asynchronous nature of Node.js, which was our topic for Sunday. The format of the day was similar to Saturday’s with working on Nodeschool workshops (learnyounode, ExpressWorks, learnyoumongo) interspersed with theory and explanations of Node.js, Express.js and the usage of MongoDB with Node and Express. As I’d earlier played around with Node back in 2012 (but, regrettably hadn’t followed it through to a major project), I was aware of some of the basics but Azat’s explanations solidified my understanding and I’m excited to build on top of my newly acquired knowledge.

I find it worthwhile to mention that Azat has a personality. He not only delivers good presentations and helps with one’s code, but also describes various scientifically tested learning strategies such as spaced repetition. He clearly keeps up with the learning geekosphere online! He also took the liberty of filling the ‘space’ in our spaced repetition with a quick foray to introduce meditation! Enjoyable and unique.

Overall, NodeProgram has reinforced my belief in hard, weekend workshops - it’s the ideal way to get a quick, rigorous introduction to a new technology - far more sticky in my mind than going through a dozen tutorials online. One can’t discount the serendipity of meeting great people either.

Addendum

Speaking of Javascript, I recently across this surrealist talk delivered by Gary Bernhardt titled The Birth and Death of Javascript. The futuristic retrospection delivered by Bernhardt is superb and truly mind-bending. It uses the mechanism of comedy to sneak in some pretty radical but feasible ideas for the evolution of Javascript and all programming 25 years from now. Do watch it!

Pecunia Nunc Is Live!

A few months ago, I came across this:

The link in the above tweet was to this:

As I was and am interested in working for Kickstarter, and was looking to shore up my portfolio, particularly with Ruby projects, I decided to take on the project.

After many false starts, I present to you…drum roll please

Pecunia Nunc

The idea is to send a daily digest of Kickstarter projects that fit a certain criteria to subscribers, such as - The projects are close to the finish line (>80% of goal funded) - The projects are ending soon (within 48 hours)

I believe this will enable Kickstarter enthusiasts who don’t have time to browse the many interesting, worthy projects regularly to fund them when they most need help. Scanning the email in the morning takes 10-15 seconds, or more if you happen to find a project to like.

I hope I’ve fulfiled a need. If not, there’s always next time.

Enjoy!

I’m Not a Spammer

For my current side-project, I need to send emails to a list of people whose email addresses are stored in the database. My concern, as you can imagine, is to prevent spamming my users in instances of error or otherwise. There’s several ways to do this. As usual, it comes down to a choice - a judgement call from among the many choices.

  1. Creating an emails model to keep track of when an email was sent and to whom.
  2. Storing the last time a user received an email in the user model.

You can think of many others ways to do this of course. I decided to go with the second option as it required minimal effort and has so far turned out very well. This was accomplished with a single rails generate migration AddLastEmailToSubscribers last_email:datetime.

This will create the following migration

AddLastEmailToSubscribers
1
2
3
4
5
class AddLastEmailToSubscribers < ActiveRecord::Migration
  def change
    add_column :subscribers, :last_email, :datetime
  end
end

From here, I can simply check if the :last_email is nil or a day before today’s, and if so, then send the day’s email, and then update the last_email to Time.now

Simple.

Down With the Sickness

This is me for the past week

Really need to get a lot of work done including all the side projects, but gah sometimes biology comes in the way. Damn you Rotavirus.

Redirect_to and Preservation of Errors

Working on my side project, Pecunia-Nunc, I was baffled when the errors on the object creation form would not display upon submission. The controller looked like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class SubscribersController < ApplicationController

def new
  require 'digest'
  @subscriber = Subscriber.new(params[:subscriber])
  @subscriber.token = Digest::SHA1.hexdigest([Time.now, rand].join)
  if @subscriber.save
      flash[:notice] = "Thanks for signing-up. Please confirm your email address through the email that'll be in your inbox shortly!"

      redirect_to home_path
  else
      flash[:notice] = "There were errors! Please resubmit after making corrections."
      redirect_to home_path
  end  
end
...

The view :

1
2
3
4
5
6
7
8
9
10
11
12
  <% if @subscriber.errors.any? %>
  <div id="error_explanation">
    <div class="alert alert-error">
      The form contains <%= pluralize(@subscriber.errors.count, "error") %>.
    </div>
    <ul>
    <% @subscriber.errors.full_messages.each do |msg| %>
      <li>* <%= msg %></li>
    <% end %>
    </ul>
  </div>
<% end %>

As you can tell, the problem was not in the view at all, but in this line redirect_to home_path. Redirection clears the object.errors field, and therefore nothing was being displayed. I stupidly spent a lot of time fiddling with the view, instead of inspecting the controller action. Replacing the problematic line with render 'new' (‘new’ is the action/view that renders the form) solved the problem by preserving the .errors object.

Me Encanta Duolingo!

I’ve been playing with Duolingo for around a month, specifically with the Spanish module. It’s absolutely fantastic. I’d signed up for an invitation back in the day as I tend to sign up for any new startups or services I think may be cool to try out. I had as much interest in learning Spanish at this time as I do in learning to bake, which is in the category of ‘it’d be nice but i have other things to do.’ Since trying it out, I’ve been totally hooked! The feeling engendered by the act of proper recollection is deeply satisfying. I can’t say I recall much of anything I learned in French or Arabic classes back in school and I did those for 2 and 3 yrs respectively. But I was able to recall words, sentences and even basic verb conjugations just two days after starting Duolingo.

So, if you have any interest at all in learning Spanish, French, Italian, German or Portuguese (these are the available modules currently), click over to Duolingo, you’ll thank me later.

Oh, did I mention it’s absolutely free?

Pow Environment Variable Trouble

I was caught up in excitement upon discovering pow. After setting it up, and testing it out on the project I’m working on now, I encountered a problem. My app is setup to send email using Gmail thru SMTP configured in a Rails environment config, and the email is sent using ActionMailer.

The config looks like this

1
2
3
4
5
address: "smtp.gmail.com",
port: 587,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"],
authentication: :login

The emails were arriving when I tested the app by running rails server but on the local pow server, authentication errors were the norm. Clearly the environment variables weren’t being set. So I googled pow’s documentation for how to setup environment variables, ending up on this page. While reading through the linked section, I missed something critical.

“Pow attempts to execute two scripts — first .powrc, then .powenv — in the application’s root. Any environment variables exported from these scripts are passed along to Rack.”

So I idiotically set about creating a .powrc file in my user/bin directory. Obviously this did not work, but I wasted an hour or so tweaking random settings trying to get this to work. Then I re-read the page, set about to fix the problem, which I did as follows.

  1. Run touch .powrc in my project’s root.
  2. Edit .powrc and add the environment variables as follows: export GMAIL_USERNAME=username export GMAIL_PASSWORD="my password"
  3. Restart pow’s worker for the app by running touch tmp/restart.txt

And that worked!

Bam! Pow!

Pow is awesome

I understood the obsessive focus of talented hackers on customizing and shortening every part of the development workflow, including reducing one word (5 letter) commands to 2 letter commands, in an intellectual manner, but I hadn’t felt it, till I started experimenting with Rails development. Typing rails s every minute can get old. This is where pow along with powder have been awesome. Now when I create a new rails app, I just run powder link to create a pow dev server for my app. Now, whenever I feel like testing out my app in the browser, I just launch powder open and the app is served in the browser. This replaces launching the rails server, followed by switching to the server and navigating to localhost:3000.

So, I want to end by thanking the 37Signals dev team, along with Adam Rogers and Phil Nash for making my life easier.

Nature’s Complexity, Human Incomprehension

From the Enlightenment onwards, we humans have betrayed a supreme confidence in our ability to read, interpret, deconstruct and ultimately triumph over the natural world using nothing but our faculties of reason, through their manifestations in science, technology and philosophy.

Okay that sounded way too high-brow. Nonetheless, I just came across this awe-inspiring post at High Scalability.

A creature as ‘simple’ as a slime mold is capable of amazing feats of computation by following simple rules that Nature has granted it through evolution. I don’t know whether scientists have deconstructed slime molds down to individual proteins and built up a whole model of it, though that seems unlikely and complex. And that’s the point! The organization and structure of a slime mold, though simple compared to multi-cellular organisms like us, is still extremely complex for our minds to deconstruct through observation and reason. There’s logic embedded in the structural complexity of the natural world not wholly visible to us.

Since I haven’t yet tried ‘genetic programming,’ I don’t know how effective it is in adopting nature’s solutions to some computation problems, nonetheless I should give it a shot sometime, perhaps using this book on HackerShelf

Learning, Muscle Memory, Typing

Going through Zed Shaw’s Learn Ruby the Hard Way, I now recognize the importance of typing in the context of learning to program a new language. My professional experience in software development consisted of .NET development in C#, which is extremely similar to JAVA in syntax. So, upon encountering Ruby syntax elements such as pipes ‘|’, typing the code becomes slow due to a lack of practice, which impedes and constricts thinking.

Exercise 12: LibrariesSource Article
1
2
3
4
5
6
7
8
9
10
require 'open-uri'

open("http://www.ruby-lang.org/en") do |f|
  f.each_line {|line| p line}
  puts f.base_uri         # <URI::HTTP:0x40e6ef2 URL:http://www.ruby-lang.org/en/>
  puts f.content_type     # "text/html"
  puts f.charset          # "iso-8859-1"
  puts f.content_encoding # []
  puts f.last_modified    # Thu Dec 05 02:45:02 UTC 2002
end

Typing code like the excerpt above has developed muscle memory for me, and made me think of solutions faster, just as Zed said it would.

Happy typing!