Skip to content

Instantly share code, notes, and snippets.

View seanlilmateus's full-sized avatar

Mateus seanlilmateus

View GitHub Profile
class RemoveMethodHook < Exception; end
class Module
def before_method(name, &new_method)
raise ArgumentError unless block_given?
old_method = instance_method(name) rescue nil
# new_method = Proc.new
unless old_method.nil?
define_method(name) do |*args|
#import <Foundation/Foundation.h>
@interface NSObject (RegisterObserverAdditions)
-(void) registerObserver:(NSObject *)observer
forKeyPath:(NSString *)keyPath
options:(NSKeyValueObservingOptions)options
context:(void *)context;
@sgonyea
sgonyea / exportCookies-monkey_patch_edition.rb
Created November 22, 2011 05:57
MacRuby script to export Safari 5.1 cookies to a human-readable format
#!/usr/bin/env macruby
require 'csv'
framework 'Foundation'
CSV_Headers = %w[domain path expiresDate name value].to_csv
class NSHTTPCookie
def to_csv
[domain, path, expiresDate, name, value].to_csv
end
@xjones
xjones / TransitionController.h
Created November 26, 2011 03:48
TransitionController for animating iOS view controller transitions w/o a controller stack
//
// TransitionController.h
//
// Created by XJones on 11/25/11.
//
#import <UIKit/UIKit.h>
@interface TransitionController : UIViewController
@pvinis
pvinis / face_detector.rb
Created December 7, 2011 12:06
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],
@Watson1978
Watson1978 / objc-macruby.m
Created December 17, 2011 23:47
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];
@m-atthieu
m-atthieu / Datastore.rb
Created December 18, 2011 16:44 — forked from cpowell/Datastore.rb
A singleton class to manage a MacRuby application's data storage requirements.
#
# Datastore.rb
# A singleton class to manage a MacRuby application's data storage requirements.
#
# Chris Powell, [email protected], http://cbpowell.wordpress.com
#
# This work is licensed under a Creative Commons Attribution 3.0 Unported License.
# http://creativecommons.org/licenses/by/3.0/
#
# For usage and discussion, see http://cbpowell.wordpress.com/category/macruby/
@jkubicek
jkubicek / gist:1503874
Created December 20, 2011 23:59
Have CodeRunner use clang for compilation
Open "/Users/<UserName>/Library/Application Support/CodeRunner/Languages/5/compile.sh"
Change this line:
gcc "$1" -o "$compname" -finput-charset=${enc[$2]} -ObjC $3
to
clang "$1" -o "$compname" -finput-charset=${enc[$2]} -ObjC $3
@toddfreese
toddfreese / gist:1513053
Created December 23, 2011 03:37
CPOutlineView dataView
@implementation FolderListCell : CPView
{
CPString folderNameText;
CPImage icon;
CPImageView iconView;
CPTextField label;
BOOL isSelected;
JSObject folderObject;
}
# Helper function that returns a number with its correct indefinite article
# e.g. number_with_indefinite_article(10) #=> "a 10"
# e.g. number_with_indefinite_article(80, "$") #=> "an $80"
def number_with_indefinite_article(number, prefix=nil)
[indefinite_article_for_number(number), " ", prefix, number].compact.join
end
# Helper function that returns the correct indefinite article for a number
# e.g. indefinite_article_for_number(10) #=> "a"
# e.g. indefinite_article_for_number(80) #=> "an"