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
| module Enumerable | |
| def try_find(rescue_type = StandardError) | |
| each do |element| | |
| begin | |
| candidate = element.respond_to?(:call) ? element.call : element | |
| return candidate if candidate | |
| rescue rescue_type | |
| next | |
| 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
| namespace :log do | |
| desc "tail log file" | |
| task :tail, :roles => :app do | |
| run "tail -n 200 -f #{shared_path}/log/#{stage}.log" do |channel, stream, data| | |
| trap("INT") { puts ' Log tailing finished'; exit 0; } | |
| puts data | |
| break if stream == :err | |
| 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
| desc "compare spree en.yml with i18n da.yml" | |
| task :compare do | |
| require 'open-uri' | |
| core = %w[api core dash promo].inject({}) do |memo, name| | |
| memo.deep_merge YAML.load(open "https://raw.github.com/spree/spree/#{ENV['branch'] || 'master'}/#{name}/config/locales/en.yml") | |
| end | |
| other = YAML.load_file File.expand_path('../../../config/locales/da.yml', __FILE__) | |
| en, da = core['en'], other['da'] | |
| puts ["=" * 60, "* checking en against da", "=" * 60].join("\n") | |
| compare_yaml_hash en, da |
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
| namespace :db do | |
| task :protect_evironment do | |
| raise "Do not run db task in #{Rails.env} mode (or use env FORCE=true)" unless Rails.env.test? or ENV['FORCE'] | |
| end | |
| task :load_config => :protect_evironment | |
| 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
| javascript:(function(){var i=document.querySelectorAll('img.comic, #comic img')[0];i&&alert(i.title);})() |
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 "chunky_png" | |
| module Sass::Script::Functions | |
| # Generates a data-url for a PNG created from the given color. | |
| # Can be used to set a alpha-transparent background for IE8< | |
| # | |
| # @example | |
| # background: url(inline-color-image(rgba(102, 54, 32, 0.5))); | |
| def inline_color_image(color) | |
| assert_type color, :Color |
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_PATH = File.expand_path('../..', __FILE__) | |
| require File.join(APP_PATH, "lib/site") | |
| working_directory APP_PATH | |
| pid_path = File.join(APP_PATH, "tmp/pids/web.pid") | |
| pid pid_path | |
| stderr_path File.join(APP_PATH, "log/unicorn-stderr") | |
| stdout_path File.join(APP_PATH, "log/unicorn-stdout") |
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
| Math.round(0.4999999999999999722444243843710865) == 1 | |
| Math.round(0.4999999999999999722444243843710864) == 0 |
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 "sass" | |
| require "chunky_png" | |
| module Sass::Script::Functions | |
| # Generates a data-url for a PNG created from the given color. | |
| # Can be used to set a alpha-transparent background for IE8< | |
| # | |
| # @example | |
| # background: url(inline-color-image(rgba(102, 54, 32, 0.5))); | |
| def inline_color_image(color) |
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
| module ModelSerializer | |
| def self.serialize(object) | |
| object.to_json include: nil # don't include any associations - only serialize shallow object | |
| end | |
| def self.deserialize(json) | |
| hash = ActiveSupport::JSON.decode(json) # => { "section": { "id": 42, ... } } | |
| model = hash.keys.first.camelize.constantize # => Section | |
| attributes = hash.values.first | |
| object = model.new |