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 withFor(list) { | |
var sum = 0; | |
list.forEach( function(item) { | |
if (typeof item === 'number') { | |
sum += item; | |
} | |
}); | |
return sum | |
}; |
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 tester(func) { | |
console.log(func([],[]), 'should be []'); | |
console.log(func([1,2],[1,2]), 'should be [1,1,2,2]'); | |
console.log(func([1,2],[1]), 'should be [1,1,2]'); | |
console.log(func(['hi'],[undefined, 'lo']), 'should be [hi,undefined, lo]'); | |
console.log(func([2,3],[]), 'should be [2,3]'); | |
console.log(func([],[2,'und', 5]), 'should be [2,und,3]'); | |
})(function concat(arr1, arr2){ | |
var catted = []; | |
var iter = 0; |
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 httpGet(theUrl, callback, callbackContext, errorCallback) { | |
var req = new XMLHttpRequest(); | |
req.open("GET", theUrl, true); | |
req.onreadystatechange = (function(){ | |
if (req.readyState == 4 && (req.status >= 200 && req.status < 300)){ | |
callback.call(callbackContext); | |
} else if (req.readyState == 4) { | |
errorCallback(); | |
} | |
}); |
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 arrayBuilder = function(){ | |
return { | |
arr: [], | |
addElem: function(element){ | |
this.arr.push(element); | |
}, | |
getArray: function(){ | |
var c = this.arr; | |
this.clearArray(); |
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 DI = function(){ | |
var throwDelayedError = function(typeOfErr, err){ | |
setTimeout(function(){ | |
throw typeOfErr + ': ' + err; | |
}, 0); | |
}; | |
var injectables = {}; |
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 async_handler(*args) | |
dass = self | |
threads = [] | |
args.each do |t| | |
threads << Thread.new do | |
ActiveRecord::Base.connection_pool.with_connection do | |
dass.send t | |
end | |
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
var Iconv = require('Iconv').Iconv; | |
var fs = require('fs'); | |
var start = Date.now(); | |
function runner(i){ | |
rStream = fs.createReadStream('enwik8'); | |
var iconv = new Iconv('UTF-8', 'UTF-16LE'); | |
wStream = fs.createWriteStream('enwik16'); | |
return rStream.pipe(iconv).pipe(wStream); |
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
class Object | |
def QQ | |
if !self.nil? | |
return self | |
end | |
Qe.new | |
end | |
end | |
class Qe |
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
class YourFirstClass | |
def initialize(word, num_a, num_b, num_c) | |
@word = word | |
@num_a = num_a | |
@num_b = num_b | |
@num_c = num_c | |
end | |
def hello(name) | |
"Hello #{name}" |
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
require 'ostruct' #needed, but available in Ruby. | |
os = OpenStruct.new | |
os.method_name = "here's your value you want" | |
os.method_name #-> "here's your value you want" |
OlderNewer