If your template has lots of ifs about what kind of models you have you may want to generisize the display portion.
One example is that instead of this:
class Car
<%= form_tag home_search_path, method: :get, data: { controller: "search" } do |form| %> | |
<div class="relative"> | |
<div class="absolute inset-y-0 start-0 flex items-center ps-3 pointer-events-none"> | |
<svg class="w-4 h-4 text-gray-500 dark:text-gray-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20"> | |
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m19 19-4-4m0-7A7 7 0 1 1 1 8a7 7 0 0 1 14 0Z"/> | |
</svg> | |
</div> | |
<%= text_field_tag :q, params[:q], data: { "search-target": "query" }, class: "block w-full p-4 ps-10 text-sm text-gray-900 border border-gray-300 rounded-t-lg rounded-b-lg bg-gray-50 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500", placeholder: "Search", required: true %> |
@mixin box-shadow($top, $left, $blur, $color, $inset: false) { | |
@if $inset { | |
-webkit-box-shadow:inset $top $left $blur $color; | |
-moz-box-shadow:inset $top $left $blur $color; | |
box-shadow:inset $top $left $blur $color; | |
} @else { | |
-webkit-box-shadow: $top $left $blur $color; | |
-moz-box-shadow: $top $left $blur $color; | |
box-shadow: $top $left $blur $color; | |
} |
$ git status | |
5 commits pending | |
$ git reset --soft HEAD~5 # where 5 is the number of commits you saw in the `git status` | |
$ git stash |
Run the following: mdfind -name 'java' | grep '/bin/java$'
We need a way back to the tab when resetting passwords or getting a token from email or second factor authentication.
Too often we open a bunch of tabs and forget which one was open.
Imagine if we could create a token that would reopen the given tab that initiated the exit.
window.security.tabIdToken // returns: 35c7b72b-00bd-4734-81f7-318392f52370
File > Add Packages > Paste in 'https://github.com/hotwired/turbo-ios/' > Add
First run sudo gem install cocoapods
Then touch Podfile
0..1_000_000 | |
|> Enum.each(fn(_n) -> | |
IO.puts "Creating process: #{Process.list |> Enum.count}" | |
spawn(fn -> Process.sleep(:infinity) | |
end) | |
end) |
# as per https://rubydoc.info/github/teamcapybara/capybara/master#using-capybara-with-minitest | |
require 'capybara/rails' | |
require 'capybara/minitest' | |
class ActionDispatch::IntegrationTest | |
# Make the Capybara DSL available in all integration tests | |
include Capybara::DSL | |
# Make `assert_*` methods behave like Minitest assertions | |
include Capybara::Minitest::Assertions |
If you want to create an extra attribute based on SQL query with ActiveRecord you can use the following:
@games = Game.select("*, ABS(#{@profile.level} - level) AS level_difference")
Then in your Ruby code you can refer to things this way:
@games.first.level_difference # => 16