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
require "json"
require "http/server"
server = HTTP::Server.new do |context|
environment = Hash.zip(ENV.keys, ENV.values)
context.response.content_type = "application/json"
context.response.print environment.to_json
end
@whalesalad
whalesalad / foo.py
Last active September 25, 2018 22:06
def handle_platypus(args):
pass
def handle_dog(args):
pass
def handle_cat(args):
pass
def fallback(args):
@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']