Skip to content

Instantly share code, notes, and snippets.

View whalesalad's full-sized avatar
🐟
i've seen more spine in jellyfish

Michael Whalen whalesalad

🐟
i've seen more spine in jellyfish
View GitHub Profile
@whalesalad
whalesalad / stochastic_hash.rb
Last active September 4, 2018 23:50
Given real usage statistics, build probabilities around choices and give me a random item
class StochasticHash
attr_accessor :data
def initialize(data)
@data = data
end
def total
@total ||= data.values.sum
end
from datetime import datetime, timezone
import json
import re
import peewee
from playhouse import postgres_ext, fields
from playhouse.fields import PasswordField as PWDField
from postgis import Point
from psycopg2.extras import DateTimeTZRange
query TotalFarmOverview($year: Int!) {
getTotalFarmOverview(year: $year) {
marketedCrops {
...MarketedCropBasic
__typename
}
overview {
totalCoverage
targetCostAndProfit
bookedRevenue
{
"auto_complete": false,
"bold_folder_labels": true,
"color_scheme": "Packages/User/Made of Code (Flake8Lint).tmTheme",
"ensure_newline_at_eof_on_save": true,
"file_exclude_patterns":
[
"*.pyc",
"*.pyo",
"*.exe",
import operator
class LeastUsed(object):
"""
Class that stores a list of items.
When an item is requested, that item is considered to have been 'used'
Each time an item is requested, request the one that has been used the least.
@whalesalad
whalesalad / fibonacci.py
Created October 16, 2017 00:28
Randomly had the urge to write a Fibonacci sequence backed by a python generator.
def fib():
x = 0
y = 1
while True:
yield x
x, y = y, x + y
def take(n, coll):
import sys
import cProfile
import pstats
from functools import wraps
from contextlib import contextmanager
@contextmanager
def profile():
def arange(start, end):
"""alphanumeric range, inclusive"""
return (chr(i) for i in range(ord(start), ord(end) + 1))
>>> arange('A', 'B')
<generator object arange.<locals>.<genexpr> at 0x1047bcbf8>
>>> list(arange('A', 'Z'))
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
// Copyright (C) 2016 Comcast Cable Communications, LLC
// Contact Us: http://customer.xfinity.com/contact-us/
// Intended use of this message is to display critical and time sensitive notifications to customers.
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
# Description:
# For when you miss whalesalad
#
# Commands:
# whalesaid
whaleisms = [
"Everything should be generated by code, nothing should be generated by people",
"code is data",
"code is data, data is just life, blood is just code, code is my blood, i am dead.",