Skip to content

Instantly share code, notes, and snippets.

View seanlilmateus's full-sized avatar

Mateus seanlilmateus

View GitHub Profile
#!/usr/local/bin/macruby
# This example is done with MacRuby and the UIKit framework for Mac OS X
# http://chameleonproject.org/
# https://github.com/BigZaphod/Chameleon/
framework 'Cocoa'
framework "UIKit" # garbage collected version, the current version of Chameleon ist not known to be GC-safe
###################
@alloy
alloy / status_bar_view.rb
Created March 30, 2011 09:10
A MacRuby example of a custom view in the status bar, with selection highlight.
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
@clee
clee / ichat-unarchiver.rb
Created April 15, 2011 09:31
read from iChat conversation logs using MacRuby
#!/usr/bin/env macruby
framework 'Foundation'
framework 'AppKit'
class Person
def initWithCoder(decoder)
# empty implementation needed for ancient iChat conversations
end
end
@mramsden
mramsden / NSDictionary+QueryStringBuilder.h
Created May 14, 2011 15:38
Creating a query string from an NSDictionary.
#import <Foundation/Foundation.h>
@interface NSDictionary (QueryStringBuilder)
- (NSString *)queryString;
@end
@SFEley
SFEley / gist:1054553
Created June 29, 2011 18:43 — forked from andrzejsliwa/gist:778535
list all available cucumber steps - (rake cucumber:steps)
# From https://gist.github.com/778535
# In turn based on http://www.natontesting.com/2010/01/11/updated-script-to-list-all-cucumber-step-definitions/
desc "List all available steps"
task :steps do
require 'hirb'
extend Hirb::Console
features_dir = "features"
step_candidates = Dir.glob(File.join(features_dir,'**/*.rb'))
# Follow all the gem requires, and identify which files have steps in them
@lukeredpath
lukeredpath / ExampleClass.m
Created June 30, 2011 22:18
Macro for creating your "shared instance" using GCD
@implementation MySharedThing
+ (id)sharedInstance
{
DEFINE_SHARED_INSTANCE_USING_BLOCK(^{
return [[self alloc] init];
});
}
@end
@AlanQuatermain
AlanQuatermain / KBMultiDispatchSource.m
Created July 7, 2011 17:44
As-yet untested code for a dispatch source wrapper which can fire multiple event/cancel callbacks
#import <Foundation/Foundation.h>
#import <dispatch/dispatch.h>
#import "MAZeroingWeakRef.h"
@interface KBMultiDispatchSource : NSObject
{
dispatch_source_t _dispatch;
dispatch_queue_t _queue;
dispatch_source_type_t _type;
CFMutableDictionaryRef _eventObservers;
@Watson1978
Watson1978 / bm_regexp.rb
Created July 27, 2011 14:44
Benchmark : MacRuby's Regexp vs Cocoa's
require 'benchmark'
Benchmark.bm(5) do |x|
str = "MacRuby is an implementation of Ruby 1.9"
x.report "Ruby" {
str.match(/([^ ]+)/)
#p $1
}
@Watson1978
Watson1978 / method.d
Created July 28, 2011 12:54
DTrace for MacRuby
% DYLD_LIBRARY_PATH=~/src/macruby-master sudo ./methods.d -c "/Users/watson/src/macruby-master/macruby /Users/watson/tmp/t.rb"
"a"
-> _GLOBAL__I__ZN12_GLOBAL__N_115ForceJITLinkingE
<- _GLOBAL__I__ZN12_GLOBAL__N_115ForceJITLinkingE = 0x1
-> __static_initialization_and_destruction_0(int, int)
<- __static_initialization_and_destruction_0(int, int) = 0x1
-> start
-> main
-> ruby_sysinit
<- ruby_sysinit = 0x3f
@alloy
alloy / associated_objects.m
Created October 10, 2011 20:19
MacRuby with Objective-C associated objects
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <MacRuby/MacRuby.h>
@interface NSObject (MRAssociatedObjects)
- (id)associatedObjectForSymbol:(NSString *)rubySymbolName;
- (void)setAssociatedObject:(id)value forSymbol:(NSString *)rubySymbolName;
@end
@implementation NSObject (MRAssociatedObjects)