View this code at http://livecoding.io/8377101
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 "irb" | |
IRB.init_config(__FILE__) | |
# Muchos hackos! I probably initialize IRB in the wrong way... | |
def IRB.CurrentContext | |
o = Object.new | |
def o.last_value | |
'' | |
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
// | |
// NSObject+BlockObservation.h | |
// Version 1.0 | |
// | |
// Andy Matuschak | |
// [email protected] | |
// Public domain because I love you. Let me know how you use it. | |
// | |
#import <Cocoa/Cocoa.h> |
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 (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby') | |
IRB::Formatter::DEFAULT_PROMPT = "#{ver} #{IRB::Formatter::DEFAULT_PROMPT}" | |
else | |
my_prompt = IRB.conf[:PROMPT][:DEFAULT].inject({}) do |r, (k,v)| | |
r[k] = "#{ver} #{v}" | |
r | |
end | |
IRB.conf[:PROMPT][:MY_PROMPT] = my_prompt | |
IRB.conf[:PROMPT_MODE] = :MY_PROMPT | |
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
#== these snippets can go into .irbrc. | |
# grab an object with its id; in MacRuby this can either be the ruby object id or the decimal / hex pointer address to the object that you can easily find with NSLog / puts. | |
def o( id ) | |
ObjectSpace._id2ref id | |
end | |
# grab instances of a particular class | |
# e.g. i(MyClass) | |
def i( klass ) |
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
# idea and much of the implementation from http://stackoverflow.com/questions/2135874/cross-cutting-logging-in-ruby | |
# e.g. o.class.add_logging :method | |
# IMPROVE would be very nice if instructions to add logging could be scoped. | |
class Module | |
def add_logging(*method_names) | |
method_names.each do |method_name| | |
original_method = instance_method(method_name) | |
define_method(method_name) do |*args,&blk| | |
puts "logging #{method_name}: #{args}" |
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
class NSView | |
def view_tree | |
self.view_where { true } | |
end | |
def views_where(&block) | |
# traverse view hierarchy and collect views matching condition. | |
hits = [] | |
hits << self if yield self | |
self.subviews.each do |subview| |
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 "bundler/gem_tasks" | |
$:.unshift("/Library/RubyMotion/lib") | |
require 'motion/project' | |
Bundler.setup | |
Bundler.require | |
require 'bubble-wrap/all' | |
require 'bubble-wrap/test' | |
Motion::Project::App.setup do |app| |
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
#!~/.rvm/bin/rvm-auto-ruby | |
# | |
# transforms common data structures to from one format to another | |
# | |
# plist, yaml, json | |
# | |
def xform( data, input_format, output_format ) | |
case input_format | |
when :plist |
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
framework 'Cocoa' | |
module DynamicKVCArrayMixin | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods |
OlderNewer