Understand your Mac and iPhone more deeply by tracing the evolution of Mac OS X from prelease to Swift. John Siracusa delivers the details.
You've got two main options:
| import Foundation | |
| enum Environment: String { | |
| case development, staging, production | |
| } | |
| extension Environment { | |
| static var current: Environment { | |
| if isAppStore { | |
| return .production |
| def active_link_to(name = nil, options = nil, **html_options, &block) | |
| options = block_given? ? name : options | |
| if current_page?(options) | |
| html_options[:class] = class_names(html_options[:class], :active) | |
| html_options[:aria] = html_options.fetch(:aria, {}).merge(current: :page) | |
| end | |
| if block_given? | |
| link_to options, html_options, &block |
| def stub_env(key, value) | |
| is_set_up_flag = "__stub_env_is_set_up" | |
| unless ENV[is_set_up_flag] | |
| allow(ENV).to receive(:[]).and_call_original | |
| allow(ENV).to receive(:fetch).and_call_original | |
| allow(ENV).to receive(:[]).with(is_set_up_flag).and_return(true) | |
| end |
| #!/usr/bin/env ruby | |
| require 'benchmark' | |
| Benchmark.bm do |b| | |
| n = 1_000_000 | |
| value1 = 1 | |
| value2 = nil |
| #!/usr/bin/env bash | |
| # Useful when you want to git bisect in a rails app and know | |
| # you need to `bin/rake db:migrate VERSION="SOMETHING"` before | |
| # you check out the next commit so the database is in the right | |
| # state, but you don't know what SOMETHING is. | |
| # Usage: | |
| # | |
| # $ migration_version_at_ref <REF> |
| class Cond | |
| IDENTITY = -> v { v } | |
| def initialize(if_cond: IDENTITY, then_branch: IDENTITY, else_branch: IDENTITY) | |
| @if_cond = if_cond | |
| @then_branch = then_branch | |
| @else_branch = else_branch | |
| end | |
| def call(v) |
| class ApiController < ApplicationController | |
| before_action :only_respect_accept_header | |
| private | |
| # By default, Rails will ignore the Accept header if it contains a wildcard | |
| # and assume the client wants HTML (or JS if using XMLHttpRequest). See | |
| # https://github.com/rails/rails/blob/a807a4f4f95798616a2a85856f77fdfc48da4832/actionpack/lib/action_dispatch/http/mime_negotiation.rb#L171-L173 | |
| # | |
| # If you don't expect your clients to be browsers, we want to override this |
| # All these requires are just for running via `irb`, if using `bin/rails console` you probably just need the method. | |
| require "active_support/all" # Got an inflector NoMethodError, so I'm just being lazy here. | |
| require "action_dispatch" | |
| require "action_dispatch/routing/route_set" | |
| require "action_dispatch/routing/inspector" | |
| require "action_controller" # For the ActionController::Parameters autoload, which any route helper uses. | |
| # Console helper play around with the routing DSL and tweak an individual route you're building. |
| require 'objspace' | |
| def self.show_allocations(&block) | |
| _ = ObjectSpace.trace_object_allocations &block | |
| ObjectSpace | |
| .each_object | |
| .to_a | |
| .filter_map do |obj| | |
| file = ObjectSpace.allocation_sourcefile obj | |
| line = ObjectSpace.allocation_sourceline obj |