Skip to content

Instantly share code, notes, and snippets.

import logging
import click
class ColorFormatter(logging.Formatter):
colors = {
"error": dict(fg="red"),
"exception": dict(fg="red"),
"critical": dict(fg="red"),
#!/usr/bin/env bash
# Usage: log_warning [<message> ...]
#
# Logs a warning message. Acts like echo,
# but wraps output in the standard direnv log format
# (controlled by $DIRENV_LOG_FORMAT), and directs it
# to stderr rather than stdout.
#
# Example:
diff --git a/src/results_notebooks/optimizely/api.py b/src/results_notebooks/optimizely/api.py
index 2eb2fa2..6132c4c 100644
--- a/src/results_notebooks/optimizely/api.py
+++ b/src/results_notebooks/optimizely/api.py
@@ -13,7 +13,7 @@ See Also
import datetime
import os
import re
-from typing import ClassVar, Generic, List, Optional, Type, TypeVar
+from typing import ClassVar, Dict, Generic, List, Type, TypeVar
@loganlinn
loganlinn / graph.py
Created November 27, 2019 20:55
dask graph wrapper a la https://github.com/plumatic/plumbing - experimental
import itertools
from typing import Iterable
import dask
import dask.core
import dask.multiprocessing
import dask.optimization
class LazyGraph:
@loganlinn
loganlinn / board.ex
Last active March 11, 2019 04:06 — forked from jordangarcia/board.ex
defmodule TicTacToe do
defmodule Board do
def create(maxX \\ 3, maxY \\ 3) do
for x <- 0..(maxX - 1),
y <- 0..(maxY - 1) do
{{x, y}, nil}
end
|> Map.new()
|> Map.put_new(:maxY, maxY)
|> Map.put_new(:maxX, maxX)
@loganlinn
loganlinn / custom_map_delegate.kt
Created December 7, 2018 22:42
Kotlin delegate property that allows map key to be different than property name
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
fun <V> map(props: Props, key: String): ReadWriteProperty<Any?, V> {
return object : ReadWriteProperty<Any?, V> {
@Suppress("UNCHECKED_CAST")
override fun getValue(thisRef: Any?, property: KProperty<*>): V = props[key]!! as V
override fun setValue(thisRef: Any?, property: KProperty<*>, value: V) {
props[key] = value
@loganlinn
loganlinn / uuid_bytearray.kt
Created November 30, 2018 00:27
Kotlin extension function to convert UUID to ByteArray
import java.nio.ByteBuffer
import java.util.UUID
fun UUID.asBytes(): ByteArray {
val b = ByteBuffer.wrap(ByteArray(16))
b.putLong(mostSignificantBits)
b.putLong(leastSignificantBits)
return b.array()
}
@loganlinn
loganlinn / swagger.yml
Created November 14, 2018 21:50
Swagger for Clash Royale API (https://api.clashroyale.com/v1/)
swagger: 2.0
info:
title: Clash Royale API
description:
version: v1
termsOfService: http://supercell.com/en/terms-of-service/
host: api.clashroyale.com
basePath: /v1
@loganlinn
loganlinn / yarn-client-config-generate.js
Last active October 23, 2018 17:52
Hadoop YARN client configuration as TypeScript interface
// https://hadoop.apache.org/docs/r2.7.5/hadoop-yarn/hadoop-yarn-common/yarn-default.xml
function generateInterface() {
return ['export interface IYarnClientConfig {',
$x('/html/body/table/tbody/tr/td[1]/a').flatMap(function(a) {
return [' /**',
' * '+a.parentElement.parentElement.children[2].innerText,
' */',
" '" + a.innerHTML + "'?: string",
'']
}).join("\n"),
@loganlinn
loganlinn / SharedMetricRegistries.kt
Last active August 29, 2018 21:34
Kotlin version of com.codahale.metrics.SharedMetricRegistries
import com.codahale.metrics.MetricRegistry
import java.util.concurrent.ConcurrentHashMap
/**
* A map of shared, named metric registries.
*/
object SharedMetricRegistries {
private val REGISTRIES = ConcurrentHashMap<String, MetricRegistry>()
@Volatile