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
#Downloads all the mp3 episode recordings from JavaScript Jabber http://javascriptjabber.com | |
#Assumes that the system 'wget' command is available which is the case on Linux | |
#Episodes will be downloaded to /home/user/JSJabber | |
require 'net/http' | |
def get(uri) | |
response = Net::HTTP.get_response(URI.parse(uri)) | |
if response.code == "301" | |
response = Net::HTTP.get_response(URI.parse(response.header['location'])) | |
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
require 'rubygems' | |
require 'couchrest' | |
require 'couchrest_model' | |
require 'json' | |
server = CouchRest.new | |
class JobOpening < CouchRest::Model::Base | |
use_database "job_openings" |
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 functionName(func) { | |
var match = func.toString().match(/function\s+([^(?:\()\s]*)/); | |
return match ? match[1] : ""; | |
} | |
/* | |
* Tests | |
*/ | |
var func1 = function(x, y) { |
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
if (!Function.prototype.asMethod) { | |
Function.prototype.asMethod = function() { | |
var self = this; | |
return function(first) { | |
var rest = [].slice.call(arguments, 1); | |
return self.apply(first, rest); | |
} | |
}; |
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
from selenium import webdriver | |
driver = webdriver.Firefox() | |
driver.get("http://www.google.com") | |
driver.quit() |
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
/* | |
* Simplistic map-reduce like API in JavaScript. | |
* | |
* No support for scalability or distributed computations, just an illustration of the computational model. | |
*/ | |
(function(host) { | |
function MapReduce(inputs, mapper, reducer) { | |
this.inputs = inputs; | |
this.mapper = mapper; |
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
/* | |
* Computing the Levenstein distance between strings. | |
* http://en.wikipedia.org/wiki/Levenshtein_distance | |
*/ | |
/* | |
* Inefficient recursive algorithm. | |
*/ | |
function stringDistance(str1, length1, str2, length2) { |
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 merge() { | |
var sources = [].slice.call(arguments); | |
return sources.reduce(function(previous, source) { | |
Object.keys(source).forEach(function(propertyName) { | |
previous[propertyName] = source[propertyName]; | |
}); | |
return previous; | |
}, {}); | |
} |
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 help = [ | |
'Command line tool to unuglify a JavaScript file.', | |
'', | |
'Before using install js-beautify:', | |
'', | |
'npm install js-beautify', | |
'', | |
'To unuglify file code.js run:', | |
'', | |
'node unuglify code.js > code.unuglified.js' |
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 generate(elements, len) { | |
if (len == 1) { | |
return elements.map(function(element) { | |
return [element]; | |
}); | |
} | |
var generated = []; | |
var subsequences = generate(elements, len - 1); | |
subsequences.forEach(function(subsequence) { |
OlderNewer