Skip to content

Instantly share code, notes, and snippets.

@Rafe
Rafe / README.md
Last active October 12, 2015 13:27
Minispec, the mini bdd test framework example

Minispec

minispec is a mini bdd test framework example

# npm install git://gist.github.com/4033566.git

# require('minispec') in your project
require('./minispec')

# use expect.js for assertion (http://n37.co/5gpfa)
expect = require('expect.js')
@Rafe
Rafe / robot.js
Created December 5, 2012 19:19
Zolmeister
var Robot = function(robot){
robot.turnLeft(robot.angle % 90);
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (robot.parentId) {
robot.ahead(1);
robot.turnGunRight(1);
}
else {
@Rafe
Rafe / Procfile
Last active May 2, 2016 14:24
express + bigpipe experiment
web: node app.js
@Rafe
Rafe / gist:5093534
Created March 5, 2013 19:42
set multiple environment in heroku
heroku apps:create [app-name] --remote [env name]
than add --remote [env name] to execute command on env
set the environment varible and addons
ex:
heroku config set XXX=OOO --remote [env name]
heroku addons .... --remote [env name]
@Rafe
Rafe / index.js
Created April 2, 2013 14:25
Solving number to words problem from http://code-warrior.herokuapp.com.
var singles = [
'', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten',
'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'
];
var tenth = ['', 'ten', 'twenty', 'thirty', 'fourty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];
var unit = ['', 'thousand', 'million', 'billion'];
module.exports = function (n) {
var result = [];
var len = n.toString().length;
@Rafe
Rafe / index.js
Created April 2, 2013 14:28
Solving number to words problem from http://code-warrior.herokuapp.com.
var singles = [
'', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten',
'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'
];
var tenth = ['', 'ten', 'twenty', 'thirty', 'fourty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];
var unit = ['', 'thousand', 'million', 'billion'];
module.exports = function (n) {
var result = [];
var len = n.toString().length;
@Rafe
Rafe / index.js
Created April 2, 2013 16:02
Solving continous sequence sum problem from http://code-warrior.herokuapp.com.
module.exports = function (seq) {
var maxsum = 0;
for (var i = 0; i < seq.length; i++) {
var sum = 0;
for (var j = i; j < seq.length; j++) {
sum += seq[j];
if(sum > maxsum) {
maxsum = sum;
}
};
@Rafe
Rafe / index.js
Created April 2, 2013 16:25
Solving continous sequence sum problem from http://code-warrior.herokuapp.com.
module.exports = function (seq) {
var maxsum = -1000000000;
var sum = 0;
for (var i = 0; i < seq.length; i++) {
sum += seq[i];
if(sum > maxsum) {
maxsum = sum;
}
if (sum < 0) {
sum = 0;
@Rafe
Rafe / index.js
Created April 2, 2013 18:29
Solving Frequency of occurrences problem from http://code-warrior.herokuapp.com.
module.exports = function (book, word) {
var words = book.replace(/.,/, ' ').toLowerCase().split(' ');
var dict = {}
words.forEach(function(w) {
if (dict[w]) {
dict[w] += 1;
} else {
dict[w] = 1;
};
});
@Rafe
Rafe / index.js
Created April 11, 2013 22:43
Solving count 2s problem from http://code-warrior.herokuapp.com.
var count2 = function(n) {
if (n == 0) return 0;
var power = 1;
while (10 * power < n) power *= 10;
var first = Math.floor(n / power);
var remain = n % power;
var n2s = 0;
if (first > 2) {