View gist:91e8c0bdea71602d185e
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
ssh pi@raspberrypi.local |
View gist:118757
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
# Order one Array by the order of another Array in Ruby. | |
expected = [:john, :moishe, :bartholemew] | |
received = [:moishe, :bartholemew, :john] | |
sorted = received.sort_by {|name| expected.index(name)} | |
# => [:john, :moishe, :bartholemew] | |
# It should even handle shorter lists. | |
sorted = [:bartholemew, :john].sort_by{|name| expected.index(name)} |
View gist:118773
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
module SetNotationHelper | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
# Here's our little magic hook | |
def inherited(subclass) | |
subclass.class_eval do |
View gist:118776
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 YourKillerModel | |
# This method checks permissions for the :index action | |
def self.is_indexable_by(user, parent = nil) | |
end | |
# This method checks permissions for the :create and :new action | |
def self.is_creatable_by(user, parent = nil) | |
end | |
# This method checks permissions for the :show action | |
def is_readable_by(user, parent = nil) | |
end |
View gist:119362
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 Jovial | |
def self.laugh | |
puts "ha." | |
end | |
end | |
Affable = Jovial | |
Affable.laugh | |
# => ha. |
View gist:122313
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 Sndfile | |
begin | |
helper = File.join(root, 'win32', 'sndfile-info.exe') | |
`#{helper} --version` | |
rescue Exception => e | |
puts e.inspect | |
begin | |
helper = File.join(root, 'osx', 'sndfile-info') | |
`#{helper} --version` |
View gist:122533
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 Soundfile | |
if windows? | |
def info | |
... | |
end | |
else | |
def info | |
... | |
end | |
end |
View gist:122528
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 Soundfile | |
# Windows | |
def info | |
`./bin/sndfile-info.exe` | |
end | |
# *nix | |
def info | |
`./bin/sndfile-info` |
View gist:122535
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 Soundfile | |
attr_accessor :info_bin | |
def initialize | |
@info_bin = (windows?) ? 'sndfile-info.exe' : 'sndfile-info' | |
end | |
end |
View Inversion of control.rb
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 SoundFile | |
attr_reader :binaries | |
delegate :info, :to => :binaries | |
def initialize | |
@binaries = Binaries.instance | |
end | |
end | |
module Binaries |
OlderNewer