Skip to content

Instantly share code, notes, and snippets.

@alexstrat
Created June 13, 2012 14:52
Show Gist options
  • Save alexstrat/2924553 to your computer and use it in GitHub Desktop.
Save alexstrat/2924553 to your computer and use it in GitHub Desktop.
var assert = require('assert');
var reg = /\b(?:0x)?([A-Fa-f0-9])+\b/g;
assert.deepEqual('0x5f ff56'.match(reg), ['0x5f', 'ff56']);
assert.deepEqual('0x5f plain0x5ftext'.match(reg), ['0x5f']);
assert.deepEqual('0x5F DD52'.match(reg), ['0x5F', 'DD52']);
assert.deepEqual('Z4FD'.match(reg), null);
var Rectangle = function(l,h) {
this.l = l;
this.h = h;
}
Rectangle.prototype.getPerimeter = function() {
return 2*this.l + 2*this.h;
}
Rectangle.prototype.getSurface = function() {
return this.l*this.h;
}
var Square = function(l) {
Rectangle.call(this, l, l);
}
Square.prototype.getPerimeter = Rectangle.prototype.getPerimeter;
Square.prototype.getSurface = Rectangle.prototype.getSurface;
var s = new Square(4);
console.log(s.getPerimeter())
var st = "<article:foo xmlns=f><title>Extensible Markup Language</title><title>Extensible Markup Language</title><para><acronym>XML</acronym> </para</article>";
var count = function(string) {
return string.match(/<\w+/g)
.map(function(tag) {
return tag.substring(1);
})
.reduce(function(prev, current) {
prev[current] = (!prev[current]) ? 1 : prev[current] +1;
return prev;
}, {});
};
console.log(count(st));
var fn = function(n) {
if(fn.dyn[n])
return fn.dyn[n];
else {
console.log(n)
var res = 3*fn(n-1)-fn(n-2);
fn.dyn[n] = res;
return res;
}
}
fn.dyn = {
0 : 1,
1 : 3
};
console.log(fn(5), fn(10));
console.log(fn.dyn);
leveException = function() {
throw new Error('you are foo')
};
attrapeException = function() {
try {
leveException();
} catch(e) {
console.error('Ooopss : ' + e.message);
}
};
attrapeException();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment