Skip to content

Instantly share code, notes, and snippets.

View atzkey's full-sized avatar
💾
Softly bytes.

atzkey

💾
Softly bytes.
View GitHub Profile
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";
/* 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;
@atzkey
atzkey / string.format.js
Created December 13, 2010 15:58
String.format extension for JavaScript
/*
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) {
@atzkey
atzkey / gist:1122563
Created August 3, 2011 12:55
assert_url_has_param
##
# 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
@atzkey
atzkey / gist:1147109
Created August 15, 2011 16:24
Shoulda context that allows stubbing of constants
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