Skip to content

Instantly share code, notes, and snippets.

@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
@Startouf
Startouf / readme.md
Last active August 31, 2022 08:53
Update CRD for helm traefik migration from 2.4 to 2.5
{
"type": "home",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Don't Slack Evil Performance*"
},
"accessory": {
@Startouf
Startouf / google_analytics_turbolinks5.js
Created August 20, 2016 22:09
Google Analytics for Turbolinks 5 (& Rails 5)
// Google Analytics code to work with Turbolniks 5
this.GoogleAnalytics = (function() {
function GoogleAnalytics() {}
GoogleAnalytics.load = function() {
var firstScript, ga;
window._gaq = [];
window._gaq.push(["_setAccount", GoogleAnalytics.analyticsId()]);
window._gaq.push(['_setAllowAnchor', true]);
@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
@Startouf
Startouf / gist:91d3b5eab004f04dfbb0d068b311ff3e
Created February 9, 2018 17:29
Mongoid adapter for jsonapi_suite
# lib/jsonapi/adapters/transactionless_mongoid_adapter.rb
module Jsonapi
module Adapters
# Mongoid transactionless adapter
# See https://github.com/jsonapi-suite/jsonapi_compliable/blob/master/lib/jsonapi_compliable/adapters/abstract.rb
#
# @author [Cyril]
#
class TransactionlessMongoidAdapter < JsonapiCompliable::Adapters::Abstract
def sideloading_module
@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 / in_memory_iterable_adapter.rb
Created October 25, 2018 20:58
jsonapi_suite for In memory Iterables adapter
module Jsonapi
module Adapters
# Adapter for resources already loaded in memory
#
# The scope is meant to be something like an Array or Iterable of objects
#
# @example Time Series
#
# scope = [
# OpenStruct.new(at: Time.now.noon, name: 'I ate'),
@Startouf
Startouf / code.rb
Last active April 30, 2018 16:43
Small gist illustrating using has_one instead of belongs_to to take advantage of parent passing
class Moderation
belongs_to :content
end
class Content
has_many :moderations
end
class ModerationResource < ApplicationResource
type :'moderation'
@Startouf
Startouf / rollbar_notifier.rb
Created April 5, 2018 09:37
Rollbar notifier for Exception notifier
# Cf
# https://github.com/rollbar/rollbar-gem/issues/711
# https://github.com/smartinez87/exception_notification/issues/413
module ExceptionNotifier
class RollbarNotifier < ExceptionNotifier::BaseNotifier
def call(exception, options = {})
@env = options[:env]
@data = (@env && @env['exception_notifier.exception_data'] || {}).merge(options[:data] || {})
@current_user_data = (@env && @env['exception_notifier.current_user.exception_data'] || {}).merge(options[:current_user] || {})