Skip to content

Instantly share code, notes, and snippets.

@ranic
ranic / mixpanel-proxy-example.html
Last active October 16, 2024 19:47
Example of setting up tracking via a proxy.
<html>
<head>
<title>Mixpanel Tracking Proxy Demo</title>
<script type="text/javascript">
/**
* Configuration Variables - CHANGE THESE!
*/
const MIXPANEL_PROJECT_TOKEN = YOUR_MIXPANEL_PROJECT_TOKEN; // e.g. "67e8bfdec29d84ab2d36ae18c57b8535"
const MIXPANEL_PROXY_DOMAIN = YOUR_PROXY_DOMAIN; // e.g. "https://proxy-eoca2pin3q-uc.a.run.app"
inverse = {
'+': '-',
'-': '+',
'*': '/',
'/': '*',
}
d = {}
with open('21.txt', 'r') as f:
@ranic
ranic / s3_mp_lambda.py
Created August 16, 2021 02:55
Lambda to import data from Amazon S3 into Mixpanel
from datetime import date
from io import TextIOWrapper
import gzip
import json
import random
import time
import urllib.parse
import os
import boto3
from collections import OrderedDict, namedtuple
Node = namedtuple('Node', ['value', 'children'])
def top_sort(root):
visited = OrderedDict()
def helper(node):
if node.value not in visited:
map(helper, node.children)
visited[node.value] = None
@ranic
ranic / backbone2.js
Created January 3, 2020 22:35
backbone2.js
DatePicker = Backbone.View.extend({
// ...
events: {
'click .date': function(e) {
// calculate new daterange
// ...
this.trigger('daterange-selected', daterange);
}
@ranic
ranic / backbone1.js
Created January 3, 2020 22:34
backbone1.js
Orchestrator = Backbone.View.extend({
// ...
render: function() {
// render subviews datePicker, graphSelector, etc.
// ...
this.listenTo(this.model, 'data-updated', function(data) {
this.tableWidget.update(data);
});
@ranic
ranic / expr29.y
Created January 3, 2020 07:21
expr29.y
%parse_param {references}
expr: literal { return $1 }
| expr "[" expr "]" { return Index($1, $3) }
| expr "and" expr { return And($1, $3) }
| expr "==" expr { return Equals($1, $3) }
| expr ">" expr { return GreaterThan($1, $3) }
| "properties" { return Property() }
| "any" "(" expr "," expr ")" { return Any($3, $5) }
| "item" { return Item() }
@ranic
ranic / expr28.py
Created January 3, 2020 07:21
expr28.py
class Index(object):
def resolve(self, item_ref, property_bindings, item_bindings):
lhs = self.left_side
rhs = self.right_side
if isinstance(rhs, Literal):
if isinstance(lhs, Item):
self.reference = item_bindings.make_reference(rhs.evaluate())
if isinstance(lhs, Property):
self.reference = property_bindings.make_reference(lhs.evaluate())
@ranic
ranic / expr27.py
Created January 3, 2020 07:19
expr27.py
# For the query
# properties["artist"] == "Ziggy Stardust" and properties["years_active"] < 5
bindings = ReferenceBindings()
# make() creates an unbound reference, and remembers its name
artist = bindings.make("artist")
years_active = bindings.make("years_active")
# the parse node just has the reference
expr = And(
@ranic
ranic / expr27.py
Created January 3, 2020 07:18
expr27.py
# For the query
# properties["artist"] == "Ziggy Stardust" and properties["years_active"] < 5
bindings = ReferenceBindings()
# make() creates an unbound reference, and remembers its name
artist = bindings.make("artist")
years_active = bindings.make("years_active")
# the parse node just has the reference
expr = And(