traits = [(:with_shipment if condition?)].compact
create(:advice, *traits)
Or inline:
create(:advice, *[(:with_shipment if condition?)].compact)
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 |
-- Based on: https://medium.com/quick-code/how-to-write-sql-to-calculate-user-cohort-retention-a1b3b57c7a2f | |
-- Uses DATE_PART instead of DATE_DIFF as it is not supported by PostgreSQL | |
-- (branch_id, scheduled_for, total_cents) | |
WITH activities AS ( | |
SELECT branch_id, scheduled_for, total_cents | |
FROM orders | |
WHERE orders.status = 'complete' | |
), | |
-- (branch_id, cohort_month): cohort month is the first order date |