Skip to content

Instantly share code, notes, and snippets.

Steven Loria sloria

Block or report user

Report or block sloria

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
sloria /
Created Oct 16, 2013
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General


  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
sloria /
Last active Feb 16, 2020
WAV recording functionality using pyaudio
# -*- coding: utf-8 -*-
Provides WAV recording functionality via two approaches:
Blocking mode (record for a set duration):
>>> rec = Recorder(channels=2)
>>> with'blocking.wav', 'wb') as recfile:
... recfile.record(duration=5.0)
Non-blocking mode (start and stop recording):
sloria /
Last active Feb 13, 2020
Checklist for dropping Python 2 in my libraries
  • Add pyupgrade to .pre-commit-config.yaml.

If supporting py35, use --py3-plus instead of --py36-plus.

- repo:
  rev: ...latest version...
  - id: pyupgrade
    args: [--py36-plus]
sloria / cloudSettings
Last active Feb 13, 2020
Visual Studio Code Settings Sync Gist
View cloudSettings
import math
from text.blob import TextBlob as tb
def tf(word, blob):
return blob.words.count(word) / len(blob.words)
def n_containing(word, bloblist):
return sum(1 for blob in bloblist if word in blob)
def idf(word, bloblist):
View Unknown fields.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
sloria / daily-downloads.sql
Last active Sep 3, 2019
BigQuery scheduled query for daily marshmallow downloads
View daily-downloads.sql
dls AS (
DATE_SUB(DATE(@run_time), INTERVAL 1 DAY) AS date,
file.project AS package, AS installer,
details.python AS python_version,
CAST(SPLIT(details.python, '.')[
(0)] AS string) AS python_major,
# Better
class Person:
def __init__(self, name, occupation): = name
self.occupation = occupation
self._relatives = None
def relatives(self):
if self._relatives is None:
import os
import re
import urlparse
import json as pyjson
NOTSET = object()
def shortcut(cast, **kwargs):
def method(self, var, default=NOTSET):
View gist:5895679
class Point:
def __init__(self, x, y):
self.x, self.y = x, y
def polar(cls, r, theta):
return cls(r * cos(theta),
r * sin(theta))
point = Point.polar(r=13, theta=22.6)
You can’t perform that action at this time.