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
{ | |
"detect_indentation": false, | |
"ensure_newline_at_eof_on_save": true, | |
"tab_size": 2, | |
"translate_tabs_to_spaces": true, | |
"trim_trailing_white_space_on_save": true | |
} | |
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 'net/telnet' | |
headings = %w(id expires bytes cache_key) | |
rows = [] | |
localhost = Net::Telnet::new("Host" => "localhost", "Port" => 11211, "Timeout" => 3) | |
matches = localhost.cmd("String" => "stats items", "Match" => /^END/).scan(/STAT items:(\d+):number (\d+)/) | |
slabs = matches.inject([]) { |items, item| items << Hash[*['id','items'].zip(item).flatten]; items } |
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 'securerandom' | |
module UUID | |
UUID_PATTERN = /(\w{8})-?(\w{4})-?(\w{4})-?(\w{4})-?(\w{12})/ | |
VALID_UUID_PATTERN = /\A#{UUID_PATTERN}\Z/ | |
def self.included(base) | |
base.send(:extend, ClassMethods) | |
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
require 'benchmark' | |
begin | |
require 'active_support/values/time_zone' | |
rescue LoadError | |
puts 'Please do `gem install active_support`' | |
exit(1) | |
end | |
def benchmark_hash(hash, key, inverted_hash) | |
Benchmark.bmbm do |x| |
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
#!/usr/bin/ruby | |
# -*- encoding: binary -*- | |
$stdout.sync = $stderr.sync = true | |
# this is used to show or watch the number of active and queued | |
# connections on any listener socket from the command line | |
require 'aggregate' | |
require 'csv' | |
require 'raindrops' | |
require 'optparse' |
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
validates :full_url, | |
presence: true, | |
format: { with: URI.regexp(%w(http https)), | |
message: "The 'url' parameter is invalid!" } |
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
deals = ['uuid1', 'uuid2', 'uuid3'].map do |uuid| | |
deal_info = double() | |
deal_info.stub_chain(:[], :uuid) { uuid } | |
deal_info | |
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
# Extracted from http://git.io/HeGfdA | |
# Full credit to https://github.com/SamSaffron | |
# | |
# Middleware that causes static asset requests to bypass rails altogether. This | |
# can make requests a lot faster. From 4.5s to 1.5s in some apps. Only relevant | |
# in development environments as production already does this. | |
# | |
# Put this file in lib/middleware and add the following code to your | |
# development.rb environment file: | |
# |
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 initialize(model = nil, mounted_as = nil) | |
if model | |
self.class.class_eval do | |
model.image_types.each do |type| | |
version type.name.to_sym do | |
process :resize_to_fill => [type.crop_x, type.crop_y] | |
# process :store_geometry | |
end | |
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
# app/validators/uuid_validator.rb | |
class UUIDValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
UUIDTools::UUID.parse_hexdigest(value) | |
rescue ArgumentError | |
UUIDTools::UUID.parse(value) | |
rescue ArgumentError | |
record.errors[attribute] << (options[:message] || "is not a valid UUID") | |
end |