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($) { | |
| $.fn.highlight = function(options) { | |
| var $el = $("<div></div>"), | |
| delay = (options && options["delay"]) || 0; | |
| var container = $(this)[0]; | |
| if ($(this).parents("table").length) { | |
| container = $(this).parents("table")[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
| # Queue all email with delayed job automagically. | |
| module DelayedMailer | |
| extend ActiveSupport::Concern | |
| included do | |
| alias_method_chain :deliver, :delayed_job | |
| end | |
| class MailJob < Struct.new(:message) |
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/env ruby | |
| require File.dirname(__FILE__) + "/../config/boot" | |
| require File.dirname(__FILE__) + "/../config/environment" | |
| dir = File.dirname(__FILE__) + "/../db/migrate" | |
| migrations = ActiveRecord::Migrator.new(:up, dir).pending_migrations | |
| if migrations.present? | |
| puts "#{migrations.size} pending migrations:" | |
| migrations.each do |m| |
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 String | |
| def to_proc | |
| lambda{|it| self.gsub("%{it}", it)} | |
| end | |
| end | |
| >> Faker::Lorem.paragraphs.map(&"<p>%{it}</p>") | |
| => ["<p>Voluptate occaecati quia tempora corrupti. Esse ea molestias suscipit aliquid eligendi. Deleniti reiciendis quas exercitationem quis commodi. Est eos ut dicta quia consequuntur quia accusantium.</p>", "<p>Optio deserunt aut sunt enim earum omnis. Alias aperiam provident tempora laboriosam ratione ut. Ratione qui blanditiis aut nobis in ab consectetur. Ex voluptatibus harum recusandae non quis ut. Sit est itaque distinctio dolor.</p>", "<p>Quia molestiae labore sit. Libero exercitationem minima dolorem omnis ullam quo sapiente. Quae ipsa maxime qui iure facere occaecati repudiandae. Deserunt hic est dolor sint.</p>"] |
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 :i18n do | |
| task :sort_keys do | |
| Dir[Rails.root + "config/locales/*.yml"].each do |fname| | |
| text = to_yaml(sort_by_key(YAML.load(File.read(fname)))).strip + "\n" | |
| File.open(fname, "w"){|fd| fd.write(text)} | |
| end | |
| end | |
| end | |
| def sort_by_key(m) |
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
| # PNG | |
| IO.read('image.png')[0x10..0x18].unpack('NN') | |
| #=> [320, 200] | |
| # GIF | |
| IO.read('image.gif')[6..10].unpack('SS') | |
| #=> [320, 200] | |
| # BMP | |
| d = IO.read('image.bmp')[14..28] |
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
| /* | |
| Optionally load javascripts when some condition is met. This code | |
| ensures the scripts are loaded sequencially to avoid dependency | |
| problems. | |
| In this case: when an element with id "yelp" exists load jquery and | |
| execute some javascript (depending on jquery) to replace the | |
| innerHtml of that element with "YELP". | |
| */ |
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 'spec_helper' | |
| require 'rails/source_annotation_extractor' | |
| describe "Scanning for pending BUG, FIXME and TODO annotations in code" do | |
| # annotation extractor expects to be run from app root | |
| Dir.chdir(File.dirname(__FILE__) + "/..") | |
| SourceAnnotationExtractor.new("BUG|FIXME|TODO").find do |res| | |
| res.keys.sort.each do |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
| require "ostruct" | |
| require "active_support/concern" | |
| require "active_model/validations" | |
| require "active_model/errors" | |
| # Soft validations are based on ActiveModel::Validations but don't | |
| # block saving a record. | |
| # | |
| # class Person < ActiveRecord::Base | |
| # include SoftValidations |
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
| # human_readable_seconds: | |
| # s: "%{s}s" | |
| # ms: "%{m}m %{s}s" | |
| # hms: "%{h}h %{m}m %{s}s" | |
| # dhms: "%{d}d %{h}h %{m}m %{s}s" | |
| def human_readable_seconds(seconds) | |
| attrs = {s: 60, m: 60, h: 24, d: nil}.reduce([1, {}]) do |(multiplier,result),(key,modulo)| | |
| if seconds / multiplier > 0 | |
| if modulo | |
| [multiplier * modulo, {key => (seconds / multiplier) % modulo}.merge(result)] |