This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/env macruby | |
framework 'Foundation' | |
framework 'ScriptingBridge' | |
itunes = SBApplication.applicationWithBundleIdentifier("com.apple.itunes") | |
itunes.run | |
itunes.sources.each_with_index do |source, lib_index| | |
library = source.libraryPlaylists.first | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$rubyMode = false | |
// Lets us define a named method on any object either as a getter | |
// or a traditional function. Getters are fun because they look more like ruby. | |
Object.prototype.defineMethod = function(name, method){ | |
if ($rubyMode) this.__defineGetter__(name, method); | |
else this[name] = method; | |
} | |
// Enable (5).times with argument |number| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Faster method, the regex / gsub overhead is invoked only the first time, then an alias is used. I'm not sure that this wouldn't introduce side-effects however. What happens when the original camel-cased method is changed / removed, but it's alias remains inplace? | |
class Object | |
alias orig_method_missing method_missing | |
def method_missing name, *args, &block | |
if name =~ /\A[a-z\d_]+\z/ | |
camel_name = name.gsub(/_(.)/) { $1.upcase } | |
if self.respond_to? camel_name | |
# The 'rescue nil' is because macruby seems to do some odd things with classes sometimes (SBElementArray?): | |
self.class.send :alias_method, name, camel_name rescue nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mechanize' | |
require 'nokogiri' | |
require 'sinatra' | |
get '/:psuid' do | |
find_name params[:psuid] | |
end | |
def find_name(psuid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################## | |
# Different ways to define singleton methods # | |
############################################## | |
# Being able to reference external instance variables when creating a method | |
# enables useful meta-programming techniques in ruby. The styles which are | |
# capable of this will define methods that "Moof!" (like Clarus the Dogcow). | |
moof = "Moof!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "haml" | |
class Symbol | |
def -(string) | |
"#{self}-#{string}".intern | |
end | |
end | |
def method_missing name, *args, &block |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Blog::Application.routes.draw do | |
resources :posts do | |
resources :comments | |
end | |
# You can have the root of your site routed with "root" | |
# just remember to delete public/index.html. | |
root :to => "home#index" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"\"\x00.\x00t\x00r\x00a\x00c\x00k\x00e\x00d\x00 \x00f\x00i\x00l\x00e\x00n\x00a\x00m\x00e\x00s\x00.\x00p\x00l\x00i\x00s\x00t\x00\"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\".tracked filenames.plist\"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" | |
/Users/Arthur/macruby_segfault_test/segfault.rb:8:in `block': failed to allocate memory (NoMemoryError) | |
from /Users/Arthur/macruby_segfault_test/segfault.rb:8:in `<main>' | |
[BUG] destination 0x2000228a8 isn't in the auto zone | |
MacRuby 0.9 (ruby 1.9.2) [universal-darwin10.0, x86_64] | |
Abort trap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Symbol | |
def to_proc | |
proc { |obj, *args| obj.send(self, *args) } | |
end | |
end | |
class Array | |
def sum | |
inject :+ | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def javascript_fallback primary, fallback, test | |
html = javascript_include_tag( primary ) | |
html << "\n" << content_tag(:script, :type => "text/javascript") do | |
%Q{ | |
if (#{test}) { | |
document.write(unescape("%3Cscript src='#{fallback}' type='text/javascript'%3E%3C/script%3E")); | |
} | |
}.gsub(/^ {6}/, '') | |
end | |
html |