Skip to content

Instantly share code, notes, and snippets.

View danaketh's full-sized avatar
🔥
Software firefighter

Daniel Tlach danaketh

🔥
Software firefighter
View GitHub Profile
@temoto
temoto / helpers_data.py
Last active September 10, 2024 20:12
Part of py-helpers. Gzip compression shortcuts. Encoding. Database helpers. Retry decorator.
def namedlist(typename, field_names):
"""Returns a new subclass of list with named fields.
>>> Point = namedlist('Point', ('x', 'y'))
>>> Point.__doc__ # docstring for the new class
'Point(x, y)'
>>> p = Point(11, y=22) # instantiate with positional args or keywords
>>> p[0] + p[1] # indexable like a plain list
33
>>> x, y = p # unpack like a regular list
@vrana
vrana / AnyKeyArray.php
Last active December 17, 2015 08:39
Array-like object allowing any serializable keys
<?php
class AnyKeyArray implements ArrayAccess, Iterator, Countable {
private $values = array();
// ArrayAccess
function offsetSet($key, $value) {
$this->values[serialize($key)] = $value;
}