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 %> |
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
# 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
# Story time: Classy Switch Classes | |
# Say you have a bunch of messages coming in Slack and you'd like to add an automatic emoji | |
# of course your team is multicultural and you may want to cater to the diverse crowd you have. | |
# For the purpose of this exercise we will treat `message#emojis` and `message#replies` as arrays we can push to. | |
# You could write your code like this: | |
if message.text.include?("Good morning!") |
A friend of mine, approaching 50, works as a programmer in a medium sized consultancy. In a recent conversation he told me how he felt like he was feeling older now that they had hired many 20-somethings in his company. The younger developers, he said, would do things faster than he would and it started to look like he was just a slower developer than the more youthful new hires. He was wondering if his days were numbered. | |
He was resigning himself to the idea that he was experiencing some kind of decline of his faculties if he compared himself to the more youthful years of his career. However this wasn’t the only conversation I had about the work at his company. The conversation before that one had him put the finger on something crucial. | |
So I had a conversation with him about it and we connected the dots. | |
Me: What was the password story they tackled? | |
Him: A password reset. | |
Me: And what was wrong with how they implemented it. | |
Him: Well the user typed their email in and then if they click the “forgot passw |
# Instead of rebooting system | |
# If audio has half going through speakers and half going through headphones. | |
ps aux | grep 'coreaudio[d]' | awk '{print $2}' | xargs sudo kill |