Skip to content

Instantly share code, notes, and snippets.

View sloat's full-sized avatar

Matt Schmidt sloat

View GitHub Profile
#!/usr/bin/env python3
import random
import nltk
import os
import pickle
from nltk.corpus import brown
import click
@sloat
sloat / typescript.py
Created April 19, 2017 17:32
Preliminary work for typescript support in completor.vim
# -*- coding: utf-8 -*-
try:
from pipes import quote
except ImportError:
from shlex import quote
import json
import os
import vim
#!/bin/zsh
TARGET=$(tmux new-window -P)
tmux split-window -t $TARGET -hb -c "#{pane_current_path}"
tmux split-window -t $TARGET -v -c "#{pane_current_path}"
tmux resize-pane -t $TARGET -R 15
tmux select-pane -t $TARGET -L
@sloat
sloat / filesize.py
Last active January 6, 2016 22:10
filesize shortened with labels
import math
def short_filesize(size):
labels = ['B', 'KB', 'MB', 'GB', 'TB']
index = min(int(math.floor(math.log(size, 1024))), len(labels))
short = size / 1024**index
return '%.2f%s' % (short, labels[index])
@sloat
sloat / ExtJSONEncoder
Created May 28, 2014 14:44
Extended JSON encoder for flask
from flask import json
class ExJSONEncoder(json.JSONEncoder):
'''Extended JSON encoder for more type support'''
def default(self, o):
if isinstance(o, set):
return list(o)
elif isinstance(o, arrow.Arrow):
o = o.datetime
@sloat
sloat / modeljson.py
Created August 31, 2013 16:07
JSON encoder for SQLAlchemy models, using the inspection API. Not thoroughly tested. No warranty, blah blah. Improvements welcomed!
import json
from sqlalchemy.inspection import inspect
class AlchemyEncoder(json.JSONEncoder):
'''JSON encoder for SQLAlchemy models, using inspection API'''
def __init__(self, skipkeys=False, ensure_ascii=True,
check_circular=True, allow_nan=True, sort_keys=False,
indent=None, separators=None, default=None, relations=False,
**kw):