Skip to content

Instantly share code, notes, and snippets.

Avatar

Amir Salihefendic amix

View GitHub Profile
@amix
amix / inspect_team_retention.py
Last active Apr 16, 2019
Inspects Twist team retention and extracts a CSV report
View inspect_team_retention.py
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 / 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
amix / appear_applet.py
Last active Jun 24, 2017
How to implement the `/appear room-name` slash command on Twist using Flask.
View appear_applet.py
# -*- 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 / sorts.py
Created Mar 19, 2016
The confidence sort in pure Python (from Reddit's codebase)
View sorts.py
# 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 / bitmapist_gen_html_data.py
Created Dec 16, 2015
Generating bitmapist HTML data
View bitmapist_gen_html_data.py
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 / bitmapist_gen_html_form.py
Created Dec 16, 2015
Generating the HTML form for querying bitmapist
View bitmapist_gen_html_form.py
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
View gist:88cc073049c1aba5c6af
# Store
class CounterStore extends EventEmitter
constructor: ->
@count = 0
@dispatchToken = @registerToDispatcher()
increaseValue: (delta) ->
@count += 1
@amix
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
amix / gist:f15508ac6a8b534c3290
Created Jan 31, 2015
fixedlist implemented in Lua
View gist:f15508ac6a8b534c3290
-- List functions
--
--
LIST_DELIM = "~"
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"