Skip to content

Instantly share code, notes, and snippets.

View eigencoder's full-sized avatar

Eigen Fields eigencoder

View GitHub Profile
@eigencoder
eigencoder / enumerable.rb
Created July 15, 2017 01:04
take_first!
# Add to config/initializers/enumerable.rb
module Enumerable
NonUniqueError = Class.new StandardError
NoElementError = Class.new StandardError
def take_first!
unless one?
if count.zero?
raise NoElementError.new('Must have exactly one element, but none found.')
else
raise NonUniqueError.new('Must have exactly one element, but multiple found.')
@eigencoder
eigencoder / point.py
Last active November 22, 2022 14:36
Basic n-dimensional point class (wrapper) using numpy
import numpy as np
class Point(np.ndarray):
"""
n-dimensional point used for locations.
inherits +, -, * (as dot-product)
> p1 = Point([1, 2])
> p2 = Point([4, 5])
> p1 + p2