Skip to content

Instantly share code, notes, and snippets.

@sent-hil
Created October 3, 2012 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sent-hil/3828580 to your computer and use it in GitHub Desktop.
Save sent-hil/3828580 to your computer and use it in GitHub Desktop.
HS: +2 Node Spagetti

Setup cron on mac

$ crontab -e

stop vim from saving tmp files temporarily for crontab :set backupskip=/tmp/*,/private/tmp/*

0 22 * * * bash -c 'source /Users/sent-hil/.rvm/scripts/rvm && /usr/bin/env ruby /Users/sent-hil/Documents/play/single/twitter_status.rb'

Check system mail (crontab uses this to send errors)

vim /var/mail/sent-hil

JS returns previous value, while incrementing.

> number++
15
> number
16

Statements vs Expressions

Expressions is small parts of a sentence: 1 + 2 Statement is full sentence: puts 1 Everything evaluates to a value in Ruby, so everything is an expression.

Two diff. ways of defining JS functions

> h = function() { return 1};
> h
[Function] // ?

> function y () { return 1 };
> y
[Function: y]

Autoboxing

In JS 4 is implemented as a primitive. When you do (4).toString(), it's temporarily put in a box that provides ability to call functions on it, like toString().

Implementation of "new" operator in Javascript

See: https://gist.github.com/3259846

function New(F) {
  var o = {};
  o.__proto__ = F.prototype;

  return function () {
    F.apply(o, arguments);
    return o;
  }
}

function Student (name) {
  this.name = name;
};

Student.prototype.greet = function () {
  console.log("Hi, ", this.name);
};

var nick = New (Student)("Nick");
nick.name; // Nick
nick.greet(); // Hi, Nick

var dave = new Student("Dave");
dave.name; // Dave
dave.greet(); // Hi, Dave
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment