Skip to content

Instantly share code, notes, and snippets.

View seanlilmateus's full-sized avatar

Mateus seanlilmateus

View GitHub Profile
@seanlilmateus
seanlilmateus / NSObject+ProcObservation.h
Created July 3, 2011 19:03 — forked from nolanw/NSObject+ProcObservation.h
Slight alteration of Any Matuschak's BlockObservation for MacRuby.
//
// 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.
@seanlilmateus
seanlilmateus / nscoding.rb
Created August 25, 2011 16:41
how to use NSCoding with MacRuby
#!/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
george = lambda do
puts "george"
end
def fred
puts "fred"
end
def fire
yield
@seanlilmateus
seanlilmateus / gist:1360512
Created November 12, 2011 13:21
Drawing Fractal with MacRuby concurrently with Grand Central Dispatch
#!/usr/local/bin/macruby
framework 'Foundation'
framework 'Cocoa'
class Grid < NSView
attr_accessor :tiles
def initWithFrame frame
super(frame)
@tiles = []
self
@seanlilmateus
seanlilmateus / gist:1427886
Created December 3, 2011 19:24
Video Recording using Macruby & AVFoundation Framework;
#!/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:',
@seanlilmateus
seanlilmateus / face_detector.rb
Created December 7, 2011 13:58 — forked from pvinis/face_detector.rb
run with "macruby face_detector.rb" or "macruby face_detector.rb https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-snc7/304055_10150415385415891_522505890_10347873_1682210515_n.jpg?dl=1" for a photo of me with woody and buzz lightyear :p
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],
@seanlilmateus
seanlilmateus / gist:1448227
Created December 8, 2011 19:43
macruby video face detector
#!/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
@seanlilmateus
seanlilmateus / gist:1461269
Created December 11, 2011 16:00
Macruby isight animated wall; press q to exit and any key to animate the wall
#!/usr/local/bin/macruby
framework 'QuartzCore'
framework 'AVFoundation'
class NSColor
def toCGColor
# approach #2
components = [redComponent, greenComponent, blueComponent, alphaComponent]
color_space = CGColorSpaceCreateWithName(KCGColorSpaceGenericRGB)
@seanlilmateus
seanlilmateus / gist:1472281
Created December 13, 2011 14:21 — forked from alskipp/gist:1469659
Macruby live(ish) moustachification in Mac OS X Lion.
framework 'Cocoa'
framework 'avfoundation'
class FaceDetectionDelegate
attr_accessor :window
def applicationDidFinishLaunching(aNotification)
@tache_array = []
detectorOptions = {CIDetectorAccuracy: CIDetectorAccuracyLow}
@seanlilmateus
seanlilmateus / objc-macruby.m
Created December 18, 2011 08:55 — forked from Watson1978/objc-macruby.m
Objective-C + MacRuby
#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];