Skip to content

Instantly share code, notes, and snippets.

View seanlilmateus's full-sized avatar

Mateus seanlilmateus

View GitHub Profile
class StatusBarView < NSView
attr_reader :progressIndicator, :statusBarItem
def initWithStatusBarItem(item)
bar = item.statusBar
if initWithFrame([[0,0], [bar.thickness, bar.thickness]])
@statusBarItem = item
@highlight = false
origin, size = frame.origin, frame.size
@seanlilmateus
seanlilmateus / gist:974340
Created May 16, 2011 12:16
Using Obj-C Blocks from MacRuby with Ruby 1.9.2 Syntax
# 1 # Processing enumerated arrays using two blocks
area = "Europe"
timeZoneNames = NSTimeZone.knownTimeZoneNames
areaArray = NSMutableArray.arrayWithCapacity 1
areaIndexes = timeZoneNames.indexesOfObjectsWithOptions NSEnumerationConcurrent,
passingTest: -> (obj, idx, stop) {
tmpStr = obj
tmpStr.hasPrefix area
}
tmpArray = timeZoneNames.objectsAtIndexes areaIndexes
class ForwardError
attr_accessor :pointer
def self.new
@pointer = Pointer.new_with_type('@')
self
end
def self.to_pointer
@pointer
end
def self.method_missing(method, *args)
@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 / filesystem_events.rb
Created October 10, 2011 18:53
Handling Filesystem Events with GCD and Macruby
#!/usr/local/bin/macruby
framework 'Foundation'
include Dispatch
#``O_EVTONLY`` is defined as ``0x8000`` in the OS X header files.
# instead of RDONLY flag I use the O_EVTONLY flag to open() the file, otherwise we'll prevent the
# volume that the file is on from being unmounted.
O_EVTONLY = 0x8000
@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:1386468
Created November 22, 2011 18:34
Macruby Face Detection in Mac OS X Lion
framework 'Cocoa'
framework 'QuartzCore'
class NSColor
def toCGColor
colorRGB = self.colorUsingColorSpaceName NSCalibratedRGBColorSpace
components = Array.new(4){Pointer.new(:double)}
colorRGB.getRed components[0], green:components[1], blue:components[2], alpha:components[3]
@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:',