This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.upto(100){|i|puts"FizzBuzz#{i}"[i%3<1?0:i%5<1?4:8,i%15<1?8:4]} | |
=begin | |
1.upto(100) do |num| | |
puts"FizzBuzz#{num}"[ num%3<1 ? 0 : num%5<1 ? 4 : 8, num%15<1 ? 8 : 4 ] | |
end | |
=end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calculator(expression, *args) | |
{ | |
add: -> (a,b) { a + b }, | |
subtract: -> (a,b) { a - b }, | |
divide: -> (a,b) { a / b }, | |
multiply: -> (a,b) { a * b}, | |
power: -> (a,b) { a ** b } | |
}[expression].call(*args) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fibonacci = function(n) { | |
return n < 2 ? n : arguments.callee(n - 1) + arguments.callee(n - 2); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=========================== | |
| Match any url | | |
| -------------- | | |
| https://www.google.com/ | | |
| http://gdi2290.com/ | | |
| ftp://s3.amazom.com/ | | |
| -------------- | | |
| /(ht|f)tps?://.+/g | | |
=========================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MONAD() { | |
return function unit(value) { | |
var monad = Object.create(null); | |
monad.bind = function(func) { | |
return func(value); | |
}; | |
return monad; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Monad() { | |
var prototype = Object.create(null); | |
function unit(value) { | |
var monad = Object.create(prototype); | |
monad.bind = function(func, args) { | |
return func.apply(undefined, [value].concat(Array.prototype.slice.apply(args || []))); | |
} | |
return monad; | |
} | |
unit.lift = function(name, func) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MONAD(modifier) { | |
var prototype = Object.create(null); | |
function unit(value) { | |
var monad = Object.create(prototype); | |
monad.bind = function(func, args) { | |
return func.apply(undefined, [value].concat(Array.prototype.slice.apply(args || []))); | |
}; | |
if (typeof modifier === 'function') { | |
modifier(monad, value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vow.js | |
// Douglas Crockford | |
// 2013-01-28 | |
// Public Domain | |
/*global setImmediate */ | |
var VOW = (function () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bubbleSort = function(array) { | |
if (array.constructor !== Array) throw 'not an Array'; | |
do { | |
var somethingWasSwapped = false; | |
// go through and... | |
for(var i = 0, ii = array.length; i < ii; i++) { | |
// if necessary | |
if (array[i] > array[i + 1]) { | |
// swap the two indices | |
somethingWasSwapped = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
module.export.fileObj = function(file, encode) { | |
var status = 'pending', | |
doneStack = [], | |
failStack = [], | |
done, fail, fullFail, fullData, | |
rect = {}; | |
fs.fileRead(file, encode, function(data, err) { | |
if (!err) { |