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 Attributes | |
def has_attributes(*key_names) | |
key_names.each do |key_name| | |
define_method key_name do | |
instance_variable_get("@attributes")[key_name] | |
end | |
define_method "#{key_name}=" do |value| | |
instance_variable_get("@attributes")[key_name] = value | |
end | |
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
# RSpec matcher to spec delegations. | |
# | |
# Usage: | |
# | |
# describe Post do | |
# it 'delegates name to Author' do | |
# expect subject.to delegate(:name).to(:author).with_prefix # post.author_name | |
# end | |
# it 'delegates month to creation date' do | |
# expect subject.to delegate(:month).to :created_at |
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
/* | |
* HQL would look something like this: | |
* | |
* from Person p join fetch p.addresses address | |
* where exists ( | |
* from Address addr left join addr.state st | |
* where addr.personId = p.id | |
* and st.abbreviation = :abbreviation | |
* ) | |
*/ |
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
# via http://jablan.radioni.ca/post/4982485974/parsing-search-query-in-ruby | |
def parse_query s | |
s.scan(/((\S+)\:\s?)?([+-])?(("(.+?)")|(\S+))/).map{|match| | |
Hash[ | |
[nil, :prefix, :plusminus, nil, nil, :phrase, :word].zip(match).select(&:all?) | |
] | |
} | |
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
MessagesApplication *imessage = [SBApplication applicationWithURL:[NSURL URLWithString:@"file:///Applications/Messages.app"]]; | |
MessagesTextChat *target = nil; | |
NSString *targetid = @"iMessage;-;"; //append phone or email .. | |
for( MessagesTextChat *chat in [[imessage chats] get]) | |
{ | |
if([[chat.id description] isEqualToString:targetid]) | |
{ | |
target = chat; | |
} | |
} |
NewerOlder