Skip to content

Instantly share code, notes, and snippets.

View Watson1978's full-sized avatar

Watson Watson1978

View GitHub Profile
@Watson1978
Watson1978 / isight_capture.rb
Created October 19, 2010 20:18
MacRuby: Captures a photo using iSight.
#!/usr/local/bin/macruby
# -*- coding: utf-8 -*-
# Captures a photo using iSight.
framework "Cocoa"
framework "QTKit"
class AppController
def initialize(filename=nil)
options = {}
@Watson1978
Watson1978 / speech.rb
Created October 24, 2010 08:30
sample of NSSpeechSynthesizer
#!/usr/bin/env macruby
# -*- coding: utf-8 -*-
require 'optparse'
framework 'AppKit'
class Speech
def initialize()
@speech = NSSpeechSynthesizer.alloc.initWithVoice(nil)
@speech.delegate = self
end
@Watson1978
Watson1978 / method.rb
Created October 24, 2010 12:11
Need the implementation on intern.h with MacRuby.
# Usage:
# $ cd src/MacRuby/
# $ ruby methods.rb include/ruby/intern.h
file = ARGV[0]
puts "Implementation is necessary."
File.open(file) {|f|
f.each_line do |line|
if(line =~ /^([^ \t\/\{\}#]+) ([^(;]+)/)
type = $1
@Watson1978
Watson1978 / gist:643493
Created October 24, 2010 12:12
Need the implementation with MacRuby.
* ruby.h
rb_objc_undef_method
rb_eval_string_protect
rb_eval_string_wrap
rb_catch
rb_catch_obj
ruby_init_stack
ruby_init_stack
rb_cISeq
rb_cEnv
@Watson1978
Watson1978 / method.d
Created November 18, 2010 14:46
DTrace Script: output the using methods within Ruby.
/* requirement : Mac OS X 10.5, ruby 1.8.6
* usage : $ sudo dtrace -qs method.d -c "ruby test.rb"
*/
function-entry
{
printf("[DTRACE]%s#%s\n", copyinstr(arg0), copyinstr(arg1));
}
filename = ARGV[0]
unless(filename)
puts "usage: #{$0} filename"
exit
end
list = {}
File.open(filename) {|f|
f.each_line do |line|
line.strip!
@Watson1978
Watson1978 / perf_result.txt
Created December 16, 2010 12:21
#1048 : [script 1] google-perftools result
Total: 180 samples
30 16.7% 16.7% 32 17.8% _rb_vm_yield_under
29 16.1% 32.8% 29 16.1% ___workq_kernreturn
23 12.8% 45.6% 23 12.8% _rb_vm_get_opaque_data
15 8.3% 53.9% 15 8.3% _strlen
10 5.6% 59.4% 137 76.1% _rb_vm_dispatch
7 3.9% 63.3% 17 9.4% Auto::Admin::thread_cache_allocate
7 3.9% 67.2% 7 3.9% _rb_objc_class_sync_version
7 3.9% 71.1% 22 12.2% _st_numhash
6 3.3% 74.4% 60 33.3% _rb_ary_equal
$ rake spec:library
(in /Users/watson/src/MacRuby)
rm -rf rubyspec_temp
./mspec/bin/mspec ci -B ./spec/macruby.mspec :library
MacRuby 0.9 (ruby 1.9.2) [universal-darwin10.0, x86_64]
............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................E............................................................................................................................................................................................................
@Watson1978
Watson1978 / tscreen.rb
Created December 30, 2010 12:48
Homebrew formula for tscreen.
require 'formula'
class Tscreen <Formula
url 'http://www.steve.org.uk/Software/tscreen/dist/tscreen-0.4.9.tar.gz'
homepage 'http://www.steve.org.uk/Software/tscreen/'
md5 '12303c84a93a78f1c44441323ba38845'
def install
system "./configure", "--disable-debug", "--disable-dependency-tracking",
"--prefix=#{prefix}"
if [[ -s "/Library/Frameworks/MacRuby.framework/Versions/0.5" ]] ; then
alias macruby05="/Library/Frameworks/MacRuby.framework/Versions/0.5/usr/bin/macruby"
fi
if [[ -s "/Library/Frameworks/MacRuby.framework/Versions/0.6" ]] ; then
alias macruby06="/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/bin/macruby"
fi
if [[ -s "/Library/Frameworks/MacRuby.framework/Versions/0.7" ]] ; then
alias macruby07="/Library/Frameworks/MacRuby.framework/Versions/0.7/usr/bin/macruby"
fi
if [[ -s "/Library/Frameworks/MacRuby.framework/Versions/0.8" ]] ; then