Skip to content

Instantly share code, notes, and snippets.

View jballanc's full-sized avatar

Joshua Ballanco jballanc

View GitHub Profile
@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
(defproject bebop "1.0.0-SNAPSHOT"
:description "Space Cowboy"
:dependencies [[ring/ring-jetty-adapter "1.1.5"]
[cheshire "4.0.2"]
[hiccup "1.0.1"]
[org.clojure/clojure "1.4.0"]
[tnrglobal/bishop "1.2.0"]]
:immutant {:content-path "/"})
@jballanc
jballanc / a.rb
Created August 19, 2012 21:07 — forked from ahoward/a.rb
threads are so dang awesome
strategy =
String(ARGV.shift || 'thread')
n =
Integer(ARGV.shift || 4)
mb =
class MyGroupedListController < UIViewController
attr_accessor :posts
attr_accessor :sections
class TableViewSection
attr_accessor :title
attr_accessor :items
def initialize(params={})
@title = params[:title]