Skip to content

Instantly share code, notes, and snippets.

View amix's full-sized avatar

Amir Salihefendic amix

View GitHub Profile
@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,
)
@amix
amix / cluster_lines.py
Last active June 28, 2022 10:25
Groups (clusters) similar lines together from a text file using k-means clustering algorithm.
"""
Groups (clusters) similar lines together from a text file
using k-means clustering algorithm.
Also does some simple cleaning (such as removing white space and replacing numbers with (N)).
Example:
python cluster_lines.py --clusters 20 invalid_dates.txt
@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 / amazon_sender.py
Created May 17, 2011 13:39
Amazon SES helper script using boto
# -*- coding: utf-8 -*-
"""
amazon_sender.py
~~~~~~~~
Python helper class that can send emails using Amazon SES and boto.
The biggest feature of this class is that encodings are handled properly.
It can send both text and html emails.
This implementation is using Python's standard library (which opens up for a lot more options).
@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 / 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 / Reddits_Algorithm.py
Created March 24, 2013 02:14
The confidence sort algorithm is implemented in _sorts.pyx, I have rewritten their Pyrex implementation into pure Python (do also note that I have removed their caching optimization)
#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
// JavaScript that solves http://regex.alf.nu/
// Run in Chrome or Firefox console
// Enjoy ;-)
// Some people, when confronted with a problem, think
// “I know, I'll use regular expressions.”
// Now they have two problems.
for(var lvl in levels) {
var fn = function(lvl) {
// JavaScript that solves http://regex.alf.nu/
// Run in Chrome or Firefox console
// Enjoy ;-)
// Some people, when confronted with a problem, think
// “I know, I'll use regular expressions.”
// Now they have two problems.
for(var lvl in levels) {
var fn = function(lvl) {