Skip to content

Instantly share code, notes, and snippets.

View amix's full-sized avatar

Amir Salihefendic amix

View GitHub Profile
@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
// Originally taken from https://github.com/mgtitimoli/await-mutex
class Mutex {
constructor() {
this._locking = Promise.resolve();
this._locked = false;
}
isLocked() {
return this._locked;
@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
@ju-popov
ju-popov / timestamp.py
Last active April 7, 2021 16:09
Python DateTime / Timestamp Convertion
######################################################################
# CURRENT AWARE LOCAL DATETIME
######################################################################
from datetime import datetime
from tzlocal import get_localzone
local_tz = get_localzone()
local_dt = datetime.now(local_tz)
@Nurdok
Nurdok / python_conversion.md
Last active July 11, 2024 15:00
Python Conversion

Python Number Conversion Chart

From To Expression
@jparise
jparise / gist:3428652
Created August 22, 2012 19:39
Tornado Graceful Shutdown
def shutdown(graceful=True):
"""Shut down the application.
If a graceful stop is requested, waits for all of the IO loop's
handlers to finish before shutting down the rest of the process.
We impose a 10 second timeout.
"""
ioloop = tornado.ioloop.IOLoop.instance()
def final_stop():