Skip to content

Instantly share code, notes, and snippets.

View sloria's full-sized avatar

Steven Loria sloria

View GitHub Profile
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):
@sloria
sloria / cloudSettings
Last active August 17, 2021 14:10
Visual Studio Code Settings Sync Gist
{"lastUpload":"2021-08-17T14:10:13.842Z","extensionVersion":"v3.4.3"}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sloria
sloria / daily-downloads.sql
Last active September 3, 2019 17:16
BigQuery scheduled query for daily marshmallow downloads
WITH
dls AS (
SELECT
DATE_SUB(DATE(@run_time), INTERVAL 1 DAY) AS date,
file.project AS package,
details.installer.name AS installer,
details.python AS python_version,
CAST(SPLIT(details.python, '.')[
OFFSET
(0)] AS string) AS python_major,
# Better
class Person:
def __init__(self, name, occupation):
self.name = name
self.occupation = occupation
self._relatives = None
@property
def relatives(self):
if self._relatives is None:
@sloria
sloria / env.py
Last active April 16, 2019 15:45
import os
import re
import urlparse
import json as pyjson
NOTSET = object()
def shortcut(cast, **kwargs):
def method(self, var, default=NOTSET):
class Point:
def __init__(self, x, y):
self.x, self.y = x, y
@classmethod
def polar(cls, r, theta):
return cls(r * cos(theta),
r * sin(theta))
point = Point.polar(r=13, theta=22.6)
"""Dead simple ANSI coloring."""
import os
import sys
RED = 31
GREEN = 32
YELLOW = 33
BOLD = 1
RESET_ALL = 0
# Recorded with the doitlive recorder
#doitlive shell: /bin/bash
#doitlive prompt: sorin
```python
class Foo:
pass
# We can assign anything
f = Foo()