Skip to content

Instantly share code, notes, and snippets.

@zhammer
zhammer / clean-architecture-playlist-souffle.py
Last active March 29, 2018 02:52
Clean Architecture Playlist Souffle
from souffle.entities import track_entity, playlist_entity, shuffler_entity
def souffle_playlist(spotify_gateway, playlist_uri, user_id, shuffle_by):
"""Souffle playlist implemented with Clean Architecture paradigms."""
playlist_tracks = spotify_gateway.fetch_playlist_tracks(playlist_uri)
playlist_track_collection_ids = {track: track_entity.extract_track_collection_id(track, shuffle_by)
for track in playlist_tracks}

mcilroy vs knuth

as per our discussion last night:

original, optimized code

def remove_tracks_from_collections(collections_map, tracks_to_remove, collection_type):
    """From a dictionary mapping collection ids to tracks in the collection, remove all tracks
    in tracks_to_remove from the collection to which the track belongs.
    Notes:
# I only have such long documentation on consecutive_date_ranges to run doctest.
from collections import namedtuple
DateRange = namedtuple('DateRange', 'start end length')
def is_after(lhs, rhs):
return lhs == rhs + 1
def consecutive_date_ranges(dates):
import pytest

def test_data_1_is_string(data_1):
    """Test that data is string"""
    assert isinstance(data_1, str)

def test_data_2_is_string(data_2):
    """Test that data is string"""
    assert isinstance(data_2, str)
// sourcereference_requestprocessor.cpp
void RequestProcessor::startReadyCheckScheduler()
{
d_scheduler.start();
bcema_SharedPtr<SubscriptionContext> ctxt(new SubscriptionContext(READYCHECK));
bdef_Function<void (*)()> timerHandle = bdef_BindUtil::bind(&delegate_, ctxt);
bdet_TimeInterval interval(CHECK_READY_INTERVAL_SECONDS);
d_scheduler.startClock(interval, timerHandle, bdetu_SystemTime::now());
}
[zhammer1@XXXXXX python-adventure (master)]$ python
Python 3.6.5 (default, Apr 3 2018, 14:24:56)
[GCC 5.3.1 20160406 (Red Hat 5.3.1-6)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import adventure
>>> help(adventure)
>>> adventury.play()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
import adventure
# help(adventure)
adventury.play()
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# NameError: name 'adventury' is not defined
adventure.play()
no
building
take(keys)
@zhammer
zhammer / dwarf-bug.log
Created April 11, 2018 16:47
Found it!
>>> n
YOU HAVE CRAWLED AROUND IN SOME LITTLE HOLES AND WOUND UP BACK IN THE
MAIN PASSAGE.
THERE IS A THREATENING LITTLE DWARF IN THE ROOM WITH YOU!
YOU'RE AT WITT'S END.
>>> pp(w.game.objects_here)
[]
>>> n
THERE IS A THREATENING LITTLE DWARF IN THE ROOM WITH YOU!
ONE SHARP NASTY KNIFE IS THROWN AT YOU!
IT MISSES!
YOU ARE IN A LARGE ROOM, WITH A PASSAGE TO THE SOUTH, A PASSAGE TO THE
WEST, AND A WALL OF BROKEN ROCK TO THE EAST. THERE IS A LARGE "Y2" ON
A ROCK IN THE ROOM'S CENTER.

And I’ll tie my butcher’s apron here. It’s suety yet. The strollers will pass it by. Six shifts, ten kerchiefs, nine to hold to the fire and this for the code...

Yet how lamely hobbles the hoy of his then pseudo-jocax axplanation how, according to his own story, he vas a process server and was merely trying to open zozimus a bottlop stoub by mortially hammering his magnum bonum...