Skip to content

Instantly share code, notes, and snippets.

View amix's full-sized avatar

Amir Salihefendic amix

View GitHub Profile
@amix
amix / bitmapist_gen_html_form.py
Created December 16, 2015 02:21
Generating the HTML form for querying bitmapist
from bitmapist import cohort
html_form = cohort.render_html_form(
action_url='/_Cohort',
selections1=[ ('Are Active', 'user:active'), ],
selections2=[ ('Task completed', 'task:complete'), ]
)
print html_form
@amix
amix / bitmapist_gen_html_data.py
Created December 16, 2015 02:23
Generating bitmapist HTML data
from bitmapist import cohort
dates_data = cohort.get_dates_data(select1='user:active',
select2='task:complete',
select3=None,
time_group='days')
html_data = cohort.render_html_data(dates_data,
time_group='days')
@amix
amix / sorts.py
Created March 19, 2016 11:10
The confidence sort in pure Python (from Reddit's codebase)
# Rewritten code from /r2/r2/lib/db/_sorts.pyx
from math import sqrt
def _confidence(ups, downs):
n = ups + downs
if n == 0:
return 0
z = 1.281551565545
@amix
amix / appear_applet.py
Last active June 24, 2017 10:55
How to implement the `/appear room-name` slash command on Twist using Flask.
# -*- coding: utf-8 -*-
"""
Start video conversations from Twist by just typing `/appear room-name`
"""
from flask import Flask
from flask import jsonify
from flask import request
app = Flask(__name__)
@amix
amix / Example Return.json
Created April 18, 2017 10:49
An example of a valid return from the Twist Content URL
{
"title": "Growth numbers for April 2017",
"content": "Hi team,\nThese are our growth numbers for **April 2017**...",
}
@amix
amix / inspect_team_retention.py
Last active April 16, 2019 09:52
Inspects Twist team retention and extracts a CSV report
from datetime import datetime
from csv import DictWriter
from cStringIO import StringIO
from parts.util.encoding import ensure_str
from twist.init import init_twist
init_twist(EXPOSE_MODULES=False)
from twist.models.database import main_db, close_current_connections
@amix
amix / query_customer_feedback.py
Last active July 25, 2023 17:52
Use LlamaIndex and GPT-3 to query customer insights
import os
import logging
import sys
import textwrap
from llama_index import (
GPTKeywordTableIndex,
SimpleDirectoryReader,
LLMPredictor,
)