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
(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
(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
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
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
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
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
In [3]: df1 = pd.DataFrame({"start": [1,2,6], "end": [2,6,9]}) | |
...: df2 = pd.DataFrame({"foo": [1,2,3,4,5,6,7,8,9]}) | |
...: dfm = pd.merge(df1, df2, how="cross") | |
...: dfm.loc[(dfm.foo >= dfm.start) & (dfm.foo < dfm.end)] | |
Out[3]: | |
start end foo | |
0 1 2 1 | |
10 2 6 2 | |
11 2 6 3 | |
12 2 6 4 |
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
package io.oden.laser.common.transforms; | |
import org.apache.beam.sdk.transforms.windowing.*; | |
import org.apache.beam.sdk.transforms.windowing.Window.OnTimeBehavior; | |
import org.joda.time.Duration; | |
public class Windows { | |
/* | |
* The Window described attempts to both be prompt but not needlessly retrigger. | |
* It's designed to account for the following cases... |
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
python3 -c "while 1: print(chr(int(9585.5 + __import__('random').random())), end='')" |