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
In [1]: import chardet | |
In [2]: s = b'200 \xb5l Ultra Po' | |
In [3]: chardet.detect(s) | |
Out[3]: {'encoding': 'ISO-8859-1', 'confidence': 0.73, 'language': ''} | |
In [4]: s.decode(chardet.detect(s)['encoding']) | |
Out[4]: '200 µl Ultra Po' |
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
try: | |
message.decode('utf-8') | |
except UnicodeDecodeError as err: | |
abstract = message[max(err.start - 10, 0):min(err.end + 10, len(message))].decode(encoding, 'backslashreplace') | |
logging.error(f"Error decoding as UTF-8: {uuid} Problem Area: '{abstract}' Error: {err}") |
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
from typing import Any, List, Optional | |
def get_in(x: Any, ks: Optional[List[Any]], default: Any = None): | |
"""Recursively get nested values from dicts and lists in python. | |
A better alternative to .get(...) chains and safe for index errors on lists. | |
Example: | |
>>> get_in({"foo": ["a", {"bar": "b"}]}, ["foo", 1, "bar"]) | |
"b" | |
>>> get_in([1, 2], [7], default="foo") |
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
from __future__ import absolute_import | |
import argparse | |
import logging | |
import re | |
import apache_beam as beam | |
from apache_beam.io import ReadFromText, WriteToText | |
from apache_beam.metrics import Metrics | |
from apache_beam.metrics.metric import MetricsFilter |
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 my-lazy-seq | |
(let [i (volatile! 0)] | |
(repeatedly | |
#(let [j (vswap! i inc)] | |
(println j) | |
j)))) |
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
(defn new-model | |
[num-clicks ts] | |
(LiveCpmModel. num-clicks 1.0 0.0 ts)) | |
(defrecord LiveCpmModel | |
[^double a ^double g ^double v ^long lua] | |
(estimateCpm | |
[this ts] |
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
(require '[clojure.string :refer [join]]) | |
(defprotocol ExpressionBuilderProtocol | |
(ensureExprAttrName [this val]) | |
(ensureExprAttrVal [this val]) | |
(ADD [this attr amnt]) | |
(SET [this attr val]) | |
(toArgs [this])) | |
(defrecord ExpressionBuilder |
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
# How To Use | |
# In order to use .bash_chartbeat, you need to do two things | |
# 1. set the PATH_TO_CHARTBEAT_REPO environment variable in your ~/.bash_profile or ~/.bash_rc | |
# 2. source this file in your ~/.bash_profile or ~/.bash_rc | |
# | |
# By default, OSX only sources your ~/.bash_profile when you start a new | |
# terminal session. Add these two things to that file. | |
# export PATH_TO_CHARTBEAT_REPO=$HOME/chartbeat # Or wherever your repo is | |
# source $PATH_TO_CHARTBEAT_REPO/.bash_chartbeat |
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/python | |
""" | |
usage: burndown [-h] [--start START] [--end END] [--retro] fname | |
positional arguments: | |
fname | |
optional arguments: | |
-h, --help show this help message and exit | |
--start START start of sprint (inclusive) |
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 cProfile | |
def with_profile(fn): | |
def _profile_fn(*args, **kwargs): | |
prof = cProfile.Profile() | |
ret = prof.runcall(fn, *args, **kwargs) | |
print "profile for:", fn.__name__ | |
prof.print_stats() | |
return ret | |
return _profile_fn |