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+ProcObservation.h | |
// Version 1.0 | |
// | |
// Andy Matuschak | |
// andy@andymatuschak.org | |
// Public domain because I love you. Let me know how you use it. | |
// | |
// NTW 2009-Oct-21: Added selectors with an options argument. | |
// NTW 2009-Oct-30: Transplanted new observation key from MYUtilities's KVUtils. |
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
#!/usr/local/bin/macruby | |
framework 'Foundation' | |
class Note < NSObject | |
attr_accessor :title, :author, :published | |
def initialize(title, author, published) | |
self.conformsToProtocol(Protocol.protocolWithName('NSCoding')) | |
@title, @author, @published = title, author, published | |
# protocol NSCoding | |
end | |
def initWithCoder aDecoder |
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
george = lambda do | |
puts "george" | |
end | |
def fred | |
puts "fred" | |
end | |
def fire | |
yield |
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
#!/usr/local/bin/macruby | |
framework 'Foundation' | |
framework 'Cocoa' | |
class Grid < NSView | |
attr_accessor :tiles | |
def initWithFrame frame | |
super(frame) | |
@tiles = [] | |
self |
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
#!/usr/local/bin/macruby | |
framework 'Cocoa' | |
framework 'AVFoundation' | |
# because we love blocks, we make NSTimer blocks :-) | |
class NSTimer | |
def self.scheduledTimerWithTimeInterval interval, repeats: repeat_flag, block: block | |
self.scheduledTimerWithTimeInterval interval, | |
target: self, | |
selector: 'executeBlockFromTimer:', |
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' | |
class NSColor | |
def toCGColor | |
color_RGB = colorUsingColorSpaceName(NSCalibratedRGBColorSpace) | |
## approach #1 | |
# components = Array.new(4){Pointer.new(:double)} | |
# color_RGB.getRed(components[0], | |
# green: components[1], | |
# blue: components[2], |
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
#!/usr/local/bin/macruby | |
framework 'QuartzCore' | |
framework 'AVFoundation' | |
class NSTimer | |
def self.scheduledTimerWithTimeInterval interval, repeats: repeat_flag, block: block | |
self.scheduledTimerWithTimeInterval interval, | |
target: self, | |
selector: 'executeBlockFromTimer:', | |
userInfo: block, | |
repeats: repeat_flag |
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
#!/usr/local/bin/macruby | |
framework 'QuartzCore' | |
framework 'AVFoundation' | |
class NSColor | |
def toCGColor | |
# approach #2 | |
components = [redComponent, greenComponent, blueComponent, alphaComponent] | |
color_space = CGColorSpaceCreateWithName(KCGColorSpaceGenericRGB) |
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' | |
framework 'avfoundation' | |
class FaceDetectionDelegate | |
attr_accessor :window | |
def applicationDidFinishLaunching(aNotification) | |
@tache_array = [] | |
detectorOptions = {CIDetectorAccuracy: CIDetectorAccuracyLow} |
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
#import <Foundation/Foundation.h> | |
#import <MacRuby/MacRuby.h> | |
int main(void) | |
{ | |
id ruby; | |
id foo; | |
ruby = [[MacRuby sharedRuntime] evaluateFileAtPath:@"test.rb"]; | |
foo = [ruby performRubySelector:@selector(main:) withArguments:@"from Objc", NULL]; |