traits = [(:with_shipment if condition?)].compact
create(:advice, *traits)
Or inline:
create(:advice, *[(:with_shipment if condition?)].compact)
import_payload = [ | |
{ | |
index: { | |
_id: id, | |
data: { | |
# ... | |
} | |
} | |
} | |
] |
# frozen_string_literal: true | |
module ActiveRecord | |
class Base | |
# Create or update a record by field (or fields). This will look for each field name as a key in the | |
# options hash. | |
# @example | |
# # If a user with that email exists then update his name and birthdate, else create him | |
# attributes={name: "Bassem Mawhoob", email: "[email protected]", :birthdate=>'1980/01/01'} | |
# User.create_or_update_by(:email, attributes) |
# Source: https://stackoverflow.com/questions/73718680/debug-pginfailedsqltransaction | |
puts ActiveRecord::Base.connection.raw_connection.error_message |
UPDATE visual_settings | |
SET calendar = jsonb_set(cast(calendar as jsonb), '$.**.firstDay', '"new_value"', false) | |
WHERE json_typeof(jsonb_path_query_first(calendar, '$.**.firstDay')::json) = 'string' |
# Excerpt from https://github.com/alexdunae/premailer/blob/master/lib/premailer/html_to_plain_text.rb | |
# Initially authored by Premailer | |
# coding: utf-8 | |
require 'htmlentities' | |
module HtmlToPlainText | |
# Returns the text in UTF-8 format with all HTML tags removed | |
# |
# Source: https://stackoverflow.com/questions/18195851/how-do-i-use-factories-from-factorybot-in-rails-console | |
require 'factory_bot' | |
# P.S. For fabrication gem you can load the definitions in the rails console with: | |
# Fabrication.manager.load_definitions | |
FactoryBot.find_definitions | |
include FactoryBot::Syntax::Methods |
traits = [(:with_shipment if condition?)].compact
create(:advice, *traits)
Or inline:
create(:advice, *[(:with_shipment if condition?)].compact)
// Source: https://www.lemlist.com/ghseet-hack?mtm_campaign=5020&mtm_source=organic&mtm_medium=linkedin | |
/** | |
* Find a Linkedin profile from company name and job title | |
* | |
* @param {string} companyName company where your prospect is working | |
* @param {string} jobTitle job you are targeting | |
* @return if found the linkedinURL + Name of the prospect | |
* @customfunction | |
*/ |
# Reference: https://dev.to/lucaskuhn/syncing-files-from-aws-s3-to-local-storage-on-rails-3639 | |
# Main goal: Sync a specific model's S3 images locally to have productions images working in development | |
# Assuming I have a model called `ProductImage` with an attachment called `artwork` | |
s3_bucket = "YOUR_S3_BUCKET" | |
access_key_id = Rails.application.credentials.dig(:aws, :access_key_id) | |
secret_access_key = Rails.application.credentials.dig(:aws, :secret_access_key) | |
storage_folder = Rails.root.join('storage') | |
storage_folder.mkpath |
-- Source: https://wiki.postgresql.org/wiki/Aggregate_Median | |
CREATE OR REPLACE FUNCTION _final_median(numeric[]) | |
RETURNS numeric AS | |
$$ | |
SELECT AVG(val) | |
FROM ( | |
SELECT val | |
FROM unnest($1) val | |
ORDER BY 1 |