- Published
- Author
- Satya
to terminate google chrome sessions ->
#terminate-session
pkill -9 "Google Chrome" .#terminate-session
At Codemancers, we believe every day is an opportunity to grow. This section is where our team shares bite-sized discoveries, technical breakthroughs and fascinating nuggets of wisdom we've stumbled upon in our work.
pkill -9 "Google Chrome" .query = <<SQL
SELECT *
FROM users
SQL
# Result: " SELECT *\n FROM users\n".squish removes all extra whitespace/newlinesquery = <<~SQL.squish
SELECT *
FROM users
WHERE active = true
SQL
# Result: "SELECT * FROM users WHERE active = true"https://nil.to|nil.to_i => 0 & https://nil.to|nil.to_f => 0.0git clone repo1
cd repo1git remote add repo2
git fetch repo2git checkout -b merge-repo2git merge --allow-unrelated-histories repo2/main (Since the repositories have separate histories, this option allows Git to combine them, potentially requiring manual conflict resolution)git add .
git commit -m "Resolved merge conflicts"pagy_array This method is the same as the generic pagy method, but specialized for an Array.require 'pagy/extras/array'
@pagy, @items = pagy_array(an_array)each_with_object is an enumerable method in Ruby that allows you to iterate over a collection while building up an object (like an array or hash). Unlike map, which creates a new array, each_with_object lets you modify an existing object in a single pass.collection.each_with_object(initial_object) do |item, object|
# Modify the object inside the block
endcollection: The array or enumerable you're iterating over.initial_object: The object that will be modified (e.g., {} for a hash or [] for an array).item: The current element in the iteration.object: The object that accumulates the results.each_with_object with a Hashnumbers = [1, 2, 3, 4, 5]
squares = numbers.each_with_object({}) do |num, hash|
hash[num] = num**2
end
puts squares
# Output: {1=>1, 2=>4, 3=>9, 4=>16, 5=>25}each_with_object?{} before the loop.collection_select when you need to populate a dropdown with a collection of ActiveRecord objects. It is built on top of select and provides a convenient way to display object attributes instead of a simple array of strings.select is used for manually defining options, typically from an array of strings or key-value pairs.collection_select is specifically designed for selecting records from an ActiveRecord collection, making it useful when working with database associations.Showing 7 to 9 of 82 results
Codemancers can bring your vision to life and help you achieve your goals