Skip to content

Instantly share code, notes, and snippets.

import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
// Returning Result types would be preferable to throwing exceptions however this is currently not
// supported https://github.com/Kotlin/KEEP/blob/master/proposals/stdlib/result.md#limitations
diff --git a/core/src/main/scala/org/apache/spark/SparkEnv.scala b/core/src/main/scala/org/apache/spark/SparkEnv.scala
index 72123f2232..a10c027e2f 100644
--- a/core/src/main/scala/org/apache/spark/SparkEnv.scala
+++ b/core/src/main/scala/org/apache/spark/SparkEnv.scala
@@ -175,7 +175,7 @@ object SparkEnv extends Logging {
create(
conf,
SparkContext.DRIVER_IDENTIFIER,
- bindAddress,
+ null,
import math
from itertools import islice
from typing import Iterable
def first_n_digits(num: int, n: int) -> Iterable[int]:
"""
Returns an iterable of the first `n` digits (left to right) in `num`
Examples:
from itertools import count
from functools import reduce
def iter_mean(iterable):
"""
Caluculate the arithmetic mean of an iterable *without* loading the entire collection
into memory or knowing the legnth apriori.
"""
return reduce(
lambda c, i: (c * (i[1] - 1) + i[0]) / i[1], zip(iterable, count(1)), 0
@SteadBytes
SteadBytes / git_reset_to_origin.sh
Created October 8, 2019 08:34
Handy git command to reset local to state of origin i.e. if origin has been force pushed
git fetch
git reset --hard @{u}
@SteadBytes
SteadBytes / runs.py
Created October 1, 2019 06:32
Find maximal runs of an iterable.
"""
Find maximal runs of an iterable.
For example, natural merge-sort https://en.wikipedia.org/wiki/Merge_sort#Natural_merge_sort uses
maximal runs to improve sorting efficiency.
Run tests using pytest --doctest-modules runs.py
- Requires hypothesis: https://hypothesis.readthedocs.io/en/latest/index.html
"""
from itertools import chain, tee, zip_longest
from functools import reduce
from typing import Iterable
def dict_values_same_types(key, cls, *dicts):
return all(isinstance(d[key], cls) for d in dicts)
def dict_merger(original: dict, incoming: dict):
"""
In place deep merge `incoming` into `original`.

Keybase proof

I hereby claim:

  • I am steadbytes on github.
  • I am steadbytes (https://keybase.io/steadbytes) on keybase.
  • I have a public key ASACj6MbJtDw50SKFTABlfMdwp9p0LLEYKhVHOdZ0HKW0Qo

To claim this, I am signing this object:

import time
from functools import wraps
class RetryExhaustedError(Exception):
pass
def retry(*exceptions, retries=5, cooldown=1, verbose=True):
def decorator(func):
@SteadBytes
SteadBytes / dot2dict.py
Created February 28, 2019 15:25
Transform dot-notation keys into nested dictionary
def dot2dict(a):
dict_tree = lambda: defaultdict(dict_tree)
output = dict_tree()
for k, v in a.items():
path = k.split(".")
target = reduce(lambda d, k: d[k], path[:-1], output)
target[path[-1]] = v
return output