Skip to content

Instantly share code, notes, and snippets.

View ak--47's full-sized avatar

AK ak--47

View GitHub Profile
@ak--47
ak--47 / example.json
Created November 14, 2024 14:48
weird duckDb unnesting thing
{"origRow": 1, "foo":42,"bar":"fortyTwo","myNest":[{"hello":"space","goodbye":"world"},{"hello":"time","goodbye":"gravity"}]}
{"origRow": 2, "foo":420,"bar":"fortyTwenty","myNest":[{"hello":"you","goodbye":"me"},{"hello":"we","goodbye":"thee"}]}
@ak--47
ak--47 / upload-file-to-bucket.py
Created September 30, 2024 01:04
scrappy single upload
import os
from google.cloud import storage # pip install google-cloud-storage
# important! replace these variables with your values
bucket_name = 'mixpanel-poc'
source_file_name = 'source_file.json'
destination_blob_name = 'destination_file.json'
key_file_path = 'keyfile.json' # this file should be in your current working directory..
@ak--47
ak--47 / merchandising-evars.js
Last active August 16, 2024 04:05
Mixpanel / Adobe: Event Model + Hit Model
/***
*
* MIXPANEL vs ADOBE ANALYTICS
* merchandising eVars and client side attribution 👎
* sending events and passing objects with properties 👍
*/
// ADOBE ANALYTICS: merchandising eVars and client side attribution
@ak--47
ak--47 / changes.sql
Last active June 3, 2024 04:32
Present State → Future State
{{
config(
materialized='incremental',
unique_key='insert_id',
on_schema_change='sync_all_columns',
incremental_strategy='delete+insert'
)
}}
{% set present_table = source('time_flip', 'present') %}
@ak--47
ak--47 / segment-and-mixpanel.html
Last active May 16, 2024 13:31
Segment + Mixpanel w/Session Replay
<!-- segment snippet -->
<script>
!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t,e){var n=document.createElement("script");n.type="text/javascript";n.async=!0;n.src="https://cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(n,a);analytics._loadOptions=e};analytics.SNIPPET_VERSION="4.1.0";
analytics.load("SEGMENT-API-KEY");
anal
@ak--47
ak--47 / amp-to-mp.sh
Created April 12, 2024 17:51
Amplitude → Mixpanel
#!/bin/bash
# move data from Amplitude to Mixpanel
# by AK ([email protected])
# set env vars (customize these!)
export START_DATE=2023-04-20
export END_DATE=2023-04-20
export AMPLITUDE_KEY=my_key
export AMPLITUDE_SECRET=my_secret
export MIXPANEL_TOKEN=my_key
@ak--47
ak--47 / user-agent-block.js
Created March 20, 2024 01:48
blocking user agents mixpanel
const express = require('express');
const app = express();
const Mixpanel = require('mixpanel')
const mixpanel = mixpanel.init('your token')
var BLOCKED_UA_STRS = [
'googlebot',
'googleweblight',
@ak--47
ak--47 / mp_azure_snowflake.sql
Last active October 15, 2024 13:32
MIXPANEL → AZURE → SNOWFLAKE pipeline
-- MIXPANEL → AZURE → SNOWFLAKE pipeline
-- the second half...
-- by [email protected]
-- docs: https://docs.snowflake.com/en/user-guide/data-load-azure-create-stage
-- create storage integration
CREATE OR REPLACE STORAGE INTEGRATION azure_intergration
TYPE = EXTERNAL_STAGE
STORAGE_PROVIDER = AZURE
ENABLED = TRUE
@ak--47
ak--47 / manual-ETL-mp-azure.sh
Created January 23, 2024 16:49
Mixpanel /export + Azure Blob Storage
#!/bin/bash
# Set the necessary variables
MIXPANEL_API_URL="https://data.mixpanel.com/api/2.0/export"
AZURE_ACCOUNT_NAME="mystorageaccount"
AZURE_CONTAINER_NAME="mycontainer"
AUTHORIZATION_HEADER="Authorization: Basic {{ base64(mixpanel_secret) }}"
# Function to download data from Mixpanel and upload to Azure
download_and_upload() {
@ak--47
ak--47 / populate-mp.sh
Created June 1, 2023 20:03
populate a mixpanel project
# fill a mixpanel project with fake data
# set env vars (customize these)
export MP_SECRET=your-project-secret
# generate 100k events and send them
npx --yes carvis --mixpanel --rows 100000 | xargs npx --yes mixpanel-import --secret $MP_SECRET