Skip to content

Instantly share code, notes, and snippets.

View sohocoke's full-sized avatar

sohocoke

View GitHub Profile
@sohocoke
sohocoke / gist:243025
Created November 25, 2009 20:58 — forked from alloy/gist:131803
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
//
// 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>
@sohocoke
sohocoke / gist:1265005
Created October 5, 2011 16:59
Show ruby version in irb prmopt
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
@sohocoke
sohocoke / gist:1320400
Created October 27, 2011 18:35
Handy routines while using InteractiveMacRuby
#== 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 )
@sohocoke
sohocoke / gist:1393479
Created November 25, 2011 13:03
intercepting ruby method calls to log or add debug behaviour
# 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}"
@sohocoke
sohocoke / gist:1397766
Created November 27, 2011 16:32
inpecting NSView hierarchy with MacRuby
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|
@sohocoke
sohocoke / gist:2956822
Created June 19, 2012 22:11
BubbleWrap rakefile with spec:kvo that fails
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|
@sohocoke
sohocoke / list-xform.rb
Created January 9, 2013 23:30
apunixenv
#!~/.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
framework 'Cocoa'
module DynamicKVCArrayMixin
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
@sohocoke
sohocoke / README.md
Created January 11, 2014 21:26
created by livecoding - http://livecoding.io/3419313