Skip to content

Instantly share code, notes, and snippets.


Amir Salihefendic amix

View GitHub Profile
amix /
Last active Apr 16, 2019
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
from twist.models.database import main_db, close_current_connections
amix / Example Return.json
Created Apr 18, 2017
An example of a valid return from the Twist Content URL
View Example Return.json
"title": "Growth numbers for April 2017",
"content": "Hi team,\nThese are our growth numbers for **April 2017**...",
amix /
Last active Jun 24, 2017
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 /
Created Mar 19, 2016
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 /
Created Dec 16, 2015
Generating bitmapist HTML data
from bitmapist import cohort
dates_data = cohort.get_dates_data(select1='user:active',
html_data = cohort.render_html_data(dates_data,
amix /
Created Dec 16, 2015
Generating the HTML form for querying bitmapist
from bitmapist import cohort
html_form = cohort.render_html_form(
selections1=[ ('Are Active', 'user:active'), ],
selections2=[ ('Task completed', 'task:complete'), ]
print html_form
View gist:88cc073049c1aba5c6af
# Store
class CounterStore extends EventEmitter
constructor: ->
@count = 0
@dispatchToken = @registerToDispatcher()
increaseValue: (delta) ->
@count += 1
amix / gist:2b492d7e778da9ee4231
Created Feb 9, 2015
Model View Controller Example (Cocoa inspired)
View gist:2b492d7e778da9ee4231
class ModelCounter
constructor: (@value=1) ->
increaseValue: (delta) =>
@value += delta
class ControllerCounter
constructor: (opts) ->
amix / gist:f15508ac6a8b534c3290
Created Jan 31, 2015
fixedlist implemented in Lua
View gist:f15508ac6a8b534c3290
-- List functions
function list_add(key, value)
--- Determine the limit by inspecting if | is in the key
local limit = 200
if string.find(key, '|') then
View gist:6784f4f71d9b3e8f8227
def add_job(self, job_type, job_id=None, on_duplicate='overwrite',
timestamp=None, distribute=None, **data):
Add a new job to execute
:param job_type: string with the name of the job
:param job_id: job identifier, if not set, then a new random unique id
will be generated
:param on_duplicate: action on identifier duplicate, can be "overwrite"
or "discard"