Skip to content

Instantly share code, notes, and snippets.

View shey's full-sized avatar

Sheheryar Sewani shey

View GitHub Profile
class Ahoy::Event < ApplicationRecord
scope :with_label_grouped_data , -> {
# Build a subquery SQL
subquery = self.unscoped.select("(case when #{table_name}.properties->>'label' is not NULL then #{table_name}.properties->>'label' else #{table_name}.name end) as label, #{table_name}.id").to_sql
# join the subquery to base model and returns the grouped data as Hash
self
.joins("INNER JOIN (#{subquery}) as labelled_events ON labelled_events.id = #{table_name}.id")
.group(:label)
@annalee
annalee / sample-slack-coc.md
Last active April 11, 2024 21:14
A sample code of conduct for social slack teams.

[SLACKNAME] Code of Conduct

Welcome!

[BRIEF DESCRIPTION OF THE SLACK AND ITS PURPOSE]

The current admins are:

  • [NAMES]