This file contains hidden or 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 context_with_constants(name, object, constants, &block) | |
object ||= Object | |
context "#{name} with constants #{constants.inspect}" do | |
setup do | |
@saved_constants = {} | |
constants.each do |k, v| | |
@saved_constants[k] = object.const_get(k) | |
Kernel::silence_warnings { object.const_set(k, v) } | |
end |
This file contains hidden or 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
## | |
# Passes if +url+ contains +param+ in its query string. | |
# | |
# Example: | |
# assert_url_has_param("http://google.com/?q=RTFM", 'q=RTFM') | |
def assert_url_has_param(url, param, message = nil) | |
message = build_message message, "<?> does not contain param <?>", url, param | |
assert_block message do | |
URI.parse(url).query.split('&').any?{|p| p == param} | |
end |
This file contains hidden or 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
/* | |
String.format extension for JavaScript | |
Next line should give you an idea how to use it: | |
"{1}, {0}!".format("world", "Hello"); | |
*/ | |
String.prototype.format = function() { | |
var formatted = this; | |
for (arg in arguments) { |
This file contains hidden or 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
/* Routine that generates frequencies for all 128 MIDI notes */ | |
#include <stdio.h> | |
#include <math.h> | |
int main() | |
{ | |
float midi[127]; | |
int a = 440; // a is 440 hz... | |
int x; |
This file contains hidden or 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 MAX_DUMP_DEPTH = 1; | |
function dumpObj(obj, name, indent, depth) { | |
if (depth > MAX_DUMP_DEPTH) { | |
return indent + name + ": <Maximum Depth Reached>\n"; | |
} | |
if (typeof obj == "object") { | |
var child = null; | |
var output = indent + name + "\n"; | |
indent += "\t"; |