Skip to content

Instantly share code, notes, and snippets.

@Startouf
Startouf / sideloading_in_memory.rb
Created October 25, 2018 22:13
jsonapi_suite sideloading of in-memory associations
# In-memory associations as jsonapi_suite sideloads
# Using the trick of memoization, assuming the parent known about the children
#
# @example
# The parent could have a `field type_string, type: String`
# and a method #type that calls and memoizes `self.type_string.camelize.constantize`
#
class Parent
def association_in_memory
@Startouf
Startouf / specification_pattern.rb
Created March 20, 2019 15:16
Specification pattern implementation for ActiveJob
class SpecificationJob < ApplicationJob
include JobSpecifications
around_perform do |_, block|
init_specifications # init a bunch of instance variables to remember status of specifications
block.call # calls the #perform method of jobs
run_registered_specifications # Actually run the specs
if specifications_all_passed?
execute_if_specifications_all_passed
else
{
"type": "home",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Don't Slack Evil Performance*"
},
"accessory": {
@Startouf
Startouf / readme.md
Last active August 31, 2022 08:53
Update CRD for helm traefik migration from 2.4 to 2.5
@Startouf
Startouf / script.js
Last active October 22, 2022 08:53
Modern UTM & Referral Cookie Replicator
<script id="gtm-modern-cookie-replicator">
/**
* Modern UTM & Referral Cookie Replicator
*
* Inspired from the UTMZ cookie replicator,
* whose goal was to makes a generally faithful representation
* of the old __utmz cookie from Classic Analytics. ;
*
* the "Modern" cookie replicator
* - stores and decodes the cookie as/from JSON format