Skip to content

Instantly share code, notes, and snippets.

View jballanc's full-sized avatar

Joshua Ballanco jballanc

View GitHub Profile
require 'benchmark'
class TestBench
VALUES = { first: "A",
second: "B",
third: "C",
fourth: "D" }
def check_with_map(val)
VALUES.fetch(val, "not found")
@jballanc
jballanc / gist:5748205
Created June 10, 2013 11:50
Benchmarking ConcurrentCollectionOperations
Before abuse of C:
18.902s
18.798s
18.789s
18.921s
18.992s
=======
Avg: 18.880s
@jballanc
jballanc / SenTestCrazy.m
Created June 9, 2013 13:26
Add this to your SenTestCase subclass to name your tests something other than "test..." (in this case "benchmark...", but you can make it whatever you like by changing the "strncmp" line).
+ (NSArray *)testInvocations {
unsigned int methodCount;
Method *methods = class_copyMethodList(self, &methodCount);
assert(methodCount);
Method method;
SEL methodName;
NSMethodSignature *methodSig;
NSMutableArray *invocations = [[NSMutableArray alloc] init];
@jballanc
jballanc / evil.c
Last active December 17, 2015 06:19
Fun 'n Games with C: An innocuous seeming pair of parentheses turns an infinite loop into a end-run around the C preprocessor.
#include <stdio.h>
void method(char* first, char* second, char* third)
{
printf("method arguments - first: %s, second: %s, third: %s\n", first, second, third);
return;
}
void wrapped_method(char* first, char* second, char* third);
#define method(first, second, third) wrapped_method((second), (third), (first))
@jballanc
jballanc / ifs.rb
Last active December 16, 2015 19:00 — forked from jeffkreeftmeijer/ifs.rb
def process(input)
commands = {
'q' => -> { puts 'Goodbye' },
'tweet' => -> { puts 'tweeting' },
'dm' => -> { puts 'direct messaging' },
'help' => -> { puts 'helping' }
}
commands.fetch(input, -> {}).call()
end
@jballanc
jballanc / crazy.rb
Created January 15, 2013 23:08
Implications of MRI's current implementation of bindings...
def munger(&block)
block.binding.eval('b = rand(99)')
end
def doit
a = 1
b = 2
munger do; end
puts "a + b = #{a + b}"
end
class FunkyStringComp
def to_str
raise "This is some crazy shit..."
end
def <=>(oth)
3.0
end
end
@jballanc
jballanc / spaceship.rb
Created November 9, 2012 14:06
Crazy Spaceship
class Greater
def <=>(other)
1
end
end
g = Greater.new
t = Time.now
s = "test"
i = 101
###
#
# This is a dirty, dirty trick to write tests that test `require`:
#
module RequireMock
REQUIRE_SENTINEL = []
def require(lib)
REQUIRE_SENTINEL << lib
super
@jballanc
jballanc / gist:4004243
Created November 2, 2012 20:55
MacRuby 1.0 vs RubyMotion for OS X

MacRuby Currently

  • Implements ~90% of Ruby functionality with some bugs
  • Can be used to create OS X desktop applications
  • Integrates with XCode
  • Uses the Obj-C GC (deprecated)

MacRuby 1.0

  • Fix known Ruby compatibility bugs