This file contains hidden or 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
| function getInternetExplorerVersion() | |
| { | |
| var rv = -1; | |
| if (navigator.appName == 'Microsoft Internet Explorer') | |
| { | |
| var ua = navigator.userAgent; | |
| var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); | |
| if (re.exec(ua) != null) | |
| rv = parseFloat( RegExp.$1 ); | |
| } |
This file contains hidden or 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
| cloud = Panda::Cloud.find(cloud_id) | |
| videos = [] | |
| page = 1 | |
| begin | |
| videos_batch = cloud.videos.all(status: :processing, page: page, per_page: 100) | |
| videos += videos_batch | |
| page += 1 | |
| end while not videos_batch.empty? |
This file contains hidden or 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 'panda' | |
| Panda.configure do | |
| access_key "ACCESS_KEY" | |
| secret_key "SECRET_KEY" | |
| cloud_id "CLOUD_ID" | |
| api_host "api.pandastream.com" | |
| api_port "443" | |
| end |
This file contains hidden or 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 configure_panda(cloud_id) = nil | |
| Panda.configure do | |
| access_key PANDA_ACCESS_KEY | |
| secret_key PANDA_SECRET_KEY | |
| cloud_id cloud_id if cloud_id | |
| api_host PANDA_API_HOST | |
| end | |
| end | |
This file contains hidden or 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
| Gauguin::Painting.new("path/to/image.png").palette | |
| # => | |
| # { | |
| # rgb(204, 204, 204)[0.5900935269505287] => [ | |
| # rgb(77, 77, 77)[7.383706620723603e-05], | |
| # ... | |
| # rgb(220, 220, 220)[7.383706620723603e-05] | |
| # ], | |
| # rgb(0, 0, 0)[0.40990647304947003] => [ | |
| # rgb(0, 0, 0)[0.40990647304947003], |
This file contains hidden or 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
| gem 'gauguin' |
This file contains hidden or 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
| painting.recolor(palette, 'path/where/recolored/file/will/be/placed') |
This file contains hidden or 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 User < ActiveRecord::Base | |
| validates :username, :password, :email, :phone, :age, presence: true | |
| validates :username, | |
| length: { within: 5..20 }, | |
| uniqueness: true, | |
| format: { with: /\A\w*\z/ } | |
| validates :password, length: { within: 5..20 } | |
| validates :email, format: { with: /.+@.+\..+/i } |
This file contains hidden or 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 User < ActiveRecord::Base | |
| Validator::Factory.register(self, UserValidator) | |
| validates_with Validator | |
| # lots of other stuff that usually is here | |
| end |
This file contains hidden or 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 Validator < ActiveModel::Validator | |
| class Factory | |
| @validators = {} | |
| def self.register(klass, validator) | |
| @validators[klass] = validator | |
| end | |
| def self.build(record) | |
| validator_class = @validators[record.class] |
OlderNewer