Skip to content

Instantly share code, notes, and snippets.

class EventBusMiddleware
def initialize(app)
@app = app
end
def call(env)
status, headers, response = @app.call(env)
headers['Access-Control-Expose-Headers'] = 'X-Event-Bus'
headers['Access-Control-Allow-Headers'] = 'X-Event-Bus'
if Thread.current[:event_bus]

Filtering Before Joins

Predicate pushdown (also called filter pushdown) is an optimization technique where filtering conditions (WHERE clauses) are applied as early as possible in a query's execution plan. This reduces the amount of data read and processed, improving performance.

In Amazon Redshift, pushing down filters before joins or aggregations minimizes the amount of data that needs to be loaded into memory or shuffled across nodes, leading to significant performance gains.

Not Great:

SELECT 
 o.order_id, 

Blueshift

Source Destination Last Import Status
Currency Rates API public.federal_reserve_raw_currency_rates 2025-01-13 🔵 Active
Delighted API public.delighted_raw_mixbook_nps_surveys 2025-01-12 🟢 Probably Active
SurveyMonkey API public.delighted_raw_mixbook_nps_surveys 2024-11-14 🟠 Probably Not Active
Iterable API public.delighted_raw_mixbook_nps_surveys 2025-01-13 🟢 Probably Active
Attentive (S3) public.raw_iterable_campaigns 2025-01-13 🟢 Probably Active
Shippo public.shippo_raw_trackings 2024-11-14 🟠 Probably Not Active
@mycotics
mycotics / dbt-best-prctices.md
Last active September 30, 2025 15:04
dbt Best Practices and Conventions at Mixbook

dbt Best Practices and Conventions at Mixbook

This document outlines the design of a dbt project aimed at delivering an outstanding business user experience at Mixbook, catering specifically to analysts and stakeholders who are proficient Looker users.

Introduction

The ultimate output of the dbt transformations will be well-structured data marts (dimensions, facts and wide tables) and insightful reports (dashboard-ready tables).

Business users should't filter out non-customer users or determine which order item shouldn’t be counted. These complexities should be handled within the dbt pipelines.

  flowchart LR;
      A[CI MULTI CHAPTCHA]-->B{Select captcha service by developer?};
      classDef green color:#022e1f,fill:#00f500;
      classDef red color:#022e1f,fill:#f11111;
      classDef white color:#022e1f,fill:#fff;
      classDef black color:#fff,fill:#000;
      B--YES-->C[How to use?]:::green;
      
      C-->U[I choose recaptcha.]:::green;
async function generateProof(targetDifficulty) {
const encoder = new TextEncoder();
let nonce = Math.floor(Math.random() * 1e6); // Start with a random nonce for uniqueness
while (true) {
// Combine nonce and timestamp for added variability
const message = `captcha-${nonce}-${Date.now()}`;
// Compute the SHA-256 hash of the message
const hashBuffer = await crypto.subtle.digest('SHA-256', encoder.encode(message));
@mycotics
mycotics / a.md
Last active December 17, 2024 10:15
  1. Create a route that will create a random token, store it in the session as sign_up_token, and encode it as a JWT that expires in 10 seconds
def generate
    # Generate a random token
    random_token = SecureRandom.hex(16)

    # Save it in the session
    session[:sign_up_token] = random_token