Skip to content

Instantly share code, notes, and snippets.

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 );
}
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?
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
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
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],
gem 'gauguin'
painting.recolor(palette, 'path/where/recolored/file/will/be/placed')
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 }
class User < ActiveRecord::Base
Validator::Factory.register(self, UserValidator)
validates_with Validator
# lots of other stuff that usually is here
end
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]