This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# The MIT License (MIT) | |
# Copyright (c) 2016 Michael-Keith Bernard | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def iter_paths(d): | |
def iter1(d, path): | |
paths = [] | |
for k, v in d.items(): | |
if isinstance(v, dict): | |
paths += iter1(v, path + [k]) | |
paths.append((path + [k], v)) | |
return paths | |
return iter1(d, []) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import random | |
import itertools | |
import pprint | |
TIME_FORMAT = "%Y-%m-%dT%H:%M:%S" | |
NUM_USERS = 1e6 | |
BROWSERS = ["Chrome", "Firefox", "IE"] | |
def logstream(start_time, end_time, max_step=10000): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dependencies(partials): | |
shallow_dep_list = { m.name: m.inherits for m in partials } | |
def transitive1(otl): | |
deps = [] | |
rest = list(shallow_dep_list[otl]) | |
while rest: | |
e = rest.pop() | |
deps.append(e) | |
rest += [d for d in shallow_dep_list[e] if d not in deps] | |
return deps |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import pprint | |
import csv | |
import random | |
import functools | |
import itertools | |
def coroutine(f): | |
@functools.wraps(f) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EXAMPLE = <<-EOE | |
1 0 ram0 0 0 0 0 0 0 0 0 0 0 0 | |
1 1 ram1 0 0 0 0 0 0 0 0 0 0 0 | |
1 2 ram2 0 0 0 0 0 0 0 0 0 0 0 | |
1 3 ram3 0 0 0 0 0 0 0 0 0 0 0 | |
1 4 ram4 0 0 0 0 0 0 0 0 0 0 0 | |
1 5 ram5 0 0 0 0 0 0 0 0 0 0 0 | |
1 6 ram6 0 0 0 0 0 0 0 0 0 0 0 | |
1 7 ram7 0 0 0 0 0 0 0 0 0 0 0 | |
1 8 ram8 0 0 0 0 0 0 0 0 0 0 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Example { | |
<T, R, E extends Exception> Function<T, Optional<R>> safely(Function<T, R> fun, Class<E> exc) { | |
return v -> { | |
try { | |
return Optional.ofNullable(fun.apply(v)); | |
} catch (Exception e) { | |
if (exc.isInstance(e)) { | |
return Optional.empty(); | |
} else { | |
throw e; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# check-git-remote-version.rb | |
# | |
# DESCRIPTION: | |
# Ensure git repo is in-sync with remote | |
# This check verifies that the current version of a git repo reflects the | |
# latest version of a particular ref on a named remote repository. | |
# | |
# PLATFORMS: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def log_arguments(function_to_wrap): | |
def new_wrapped_function(*args, **kwargs): | |
name = function_to_wrap.func_name | |
print("Calling {} with args {} and kwargs {}".format( | |
name, args, kwargs)) | |
return function_to_wrap(*args, **kwargs) | |
return new_wrapped_function | |
def add(a, b): | |
return a + b |