Skip to content

Instantly share code, notes, and snippets.

require('npm').load(function (err, npm) {
npm.commands.ls([], true, function (err, data, lite) {
// log the version of express
console.log(lite.dependencies.express.version);
})
});
// From JavaScript The Good Parts
String.prototype.deentityify = (function () {
var entity = {
quot: '"',
lt: '<',
gt: '>'
};
return function ( ) {
return this.replace(/&([^&;]+);/g, function (a, b) {
// From underscorejs.org documentation
var stooges = [
{
name : 'curly',
age : 25
},
{
name : 'moe',
age : 21
},
father(zeb, john_boy_sr).
father(john_boy_sr, john_boy_jr).
% Multiple rules with the same signature:
ancestor(X, Y) :- father(X, Y). % base case first
ancestor(X, Y) :- father(X, Z), ancestor(Z, Y). % we recursively call ancestor
% Alternatively, we can write it this way using a logical OR:
ancestor(X, Y) :- father(X, Y); % we use a semicolon to distinguish between clauses
father(X, Z), ancestor(Z, Y).
% testing the first clause
ancestor(zeb, john_boy_sr). % yes
ancestor(john_boy_sr, zeb). % no
% testing the second clause
ancestor(zeb, john_boy_jr). % yes
% let's ask, "Who is an ancestor of zeb"
ancestor(zeb, Who). % john_boy_sr ; john_boy_jr
% "Who is john_boy_jr an ancestor
/**
* Let's define a member function to tell if x is a member of ary
*
* def member(x, ary)
* return false if ary == []
* return true if ary.first == x
* member(x, ary[1...ary.size])
* end
*
* In Prolog:
/*************
Inverter
_______
| |
A-| NOT |-OUT
|_____|
*************/
% A OUT
not(0, 1 ).
var prop, x;
var animal = {
type: 'Missing No.',
say: function (phrase) {
return this.type + ' says hello.';
}
};
var dog = Object.create(animal);
dog.type = 'Dog';
scala> 1 + 1
res0: Int = 2
scala> (1).+(1)
res1: Int = 2
scala> 2 + 5 * 8
res2: Int = 42
scala> (2).+((5).*(8))