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
scope :tagged_with, lambda { |tags, match_all = false| | |
tag_array = tags.is_a?(Array) ? TagList.new(tags) : TagList.from(tags) | |
where_operator = match_all ? :& : :| | |
where_conditions = tag_array.collect {|name| {:tags => :name =~ name} } | |
where_sql = where_conditions.inject(&where_operator) | |
select("DISTINCT prints.*").joins(:tags).where(where_sql) | |
} |
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
# If you are using ActiveRecord and want to paginate it you have to write this: | |
# PeacefulPaginate.use_for_active_record! | |
# to end of your config/environment.rb | |
# If you want to override default .paginate method from WillPaginate gem you have to insert this | |
# PeacefulPaginate.use_compatible_mod_with_will_paginate! | |
# to end of your config/environment.rb | |
# With this you dont have to rewrite nothing else in your application | |
# In other way how to use it |
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 Order < ActiveRecord::Base | |
validates_inclusion_of :type, :in => %w{SpecialOrder} | |
def self.new(params = {}) | |
_type = params.delete(:type) | |
_new = super(params) | |
_new.type = _type.to_s.camelize if _type | |
return _new | |
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
class UltraModel < ActiveRecord::Base | |
validates_presence_of :super_id | |
validates_format_of :super_id, :dependency => :super_id_presence | |
validates_uniqueness_of :super_id, :dependency => :super_id_format | |
validates :super_object_exist, :dependency => :super_id_uniqueness | |
private | |
def super_object_exist |
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 'mechanize' | |
require 'fileutils' | |
def start | |
a = Mechanize.new | |
last_file = Dir.glob('wulf*.*')[-1] | |
if last_file and /.*?_(?<year>\d{4})\-(?<month>\d{2})-(?<day>\d{2})/ =~ last_file | |
strip = "#{year}/#{month}/#{day}" |
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 Book < ActiveRecord::Base | |
attr_accessor :isbn | |
validate :format_of_isbn | |
private | |
def format_of_isbn | |
normalized_isbn = self.isbn.to_s.gsub(/_|-/, '') | |
if normalized_isbn.length == 10 |
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 WillPaginate::ViewHelpers::LinkRenderer | |
def url(page) | |
@base_url_params ||= begin | |
url_params = base_url_params | |
merge_optional_params(url_params) | |
url_params | |
end | |
url_params = @base_url_params.dup |
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 String | |
def to_slug | |
value = self.mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n, '').to_s | |
value.gsub!(/[']+/, '') | |
value.gsub!(/\W+/, ' ') | |
value.strip! | |
value.downcase! | |
value.gsub!(' ', '-') | |
value | |
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
describe("My amazing lib", function() { | |
beforeEach(function() { | |
this.oldSetTimeout = window.setTimeout; | |
window.setTimeout = function(cb) { cb() }; | |
}) | |
it("should correct process method with setTimeout", function() { | |
var instance = new MyLib(); | |
instance.processMethodWithSetTimeout(); | |
expect(instance.resultOfThatMethod).toBe("done"); |
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
schovi@vps:~$ sudo aptitude install nginx | |
The following NEW packages will be installed: | |
libgd2-noxpm{a} libjpeg62{a} nginx nginx-common{a} nginx-full{a} | |
0 packages upgraded, 5 newly installed, 0 to remove and 28 not upgraded. | |
Need to get 661 kB of archives. After unpacking 2126 kB will be used. | |
Do you want to continue? [Y/n/?] y | |
Get: 1 http://cz.archive.ubuntu.com/ubuntu/ oneiric/main libjpeg62 amd64 6b1-1ubuntu2 [88.3 kB] | |
Get: 2 http://cz.archive.ubuntu.com/ubuntu/ oneiric/main libgd2-noxpm amd64 2.0.36~rc1~dfsg-5.1ubuntu1 [198 kB] | |
Get: 3 http://cz.archive.ubuntu.com/ubuntu/ oneiric/universe nginx-common all 1.0.5-1 [14.6 kB] | |
Get: 4 http://cz.archive.ubuntu.com/ubuntu/ oneiric/universe nginx-full amd64 1.0.5-1 [354 kB] |
OlderNewer