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 unittest | |
# todo: make this a "parameterized" test | |
HEX_NUGGET_MAP = { | |
'0': '0000', | |
'1': '0001', | |
'2': '0010', | |
'3': '0011', | |
'4': '0100', |
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 unittest | |
def get_all_key_values( | |
key, | |
container | |
): | |
result_set = set() | |
if not isiterable(container): | |
return result_set |
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 unittest | |
class Container: | |
def __init__(self, items): | |
self.__cur = 0 | |
self.__items = items | |
def __iter__(self): | |
self.__cur = 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 Comparison: | |
def __init__(self, a, b, **kwargs): | |
self.a = a | |
self.b = b | |
self.kwargs = kwargs | |
def compare(self): | |
""" .compare() -> Union[1, -1, 0]""" | |
if self._a_has_higher_precedence(): | |
return 1 |
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 unittest | |
from hypothesis import given, example, settings, reproduce_failure | |
import hypothesis.strategies as st | |
def is_even(v): | |
return v % 2 == 0 | |
class Test(unittest.TestCase): |
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 dict_has_path(d, path): | |
if not isinstance(d, dict): | |
return None, 'dict_has_path expected type dict for d parameter. called with %s' % d.__class__.__name__ | |
if not isinstance(path, str): | |
return None, 'dict_has_path expected type str for path parameter. called with %s' % path.__class__.__name__ | |
if path in d: | |
return True, None | |
if '.' not in path: | |
return False, None | |
sub_paths = path.split('.') |
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
# the in operator looks in a class's __contains__ method | |
class A: | |
def __init__(self, numbers=[]): | |
self.__numbers = numbers | |
def __contains__(self, item): | |
return item in self.__numbers | |
a = A(numbers=[1, 2, 3]) |
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
select concat_ws(E'\n', 'name=bob', 'age=45') |
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 Errorable { | |
constructor({ value = null, error = null }) { | |
this.__value = value | |
// should this be only instance of Error or null validated? | |
this.__err = error | |
this.__err_accessed = false | |
} | |
static wrapSync(fn) { | |
return (...args) => { |
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
// todo: write tests | |
interface SnippetProps { | |
val: string | |
} | |
export const Snippet = ({ | |
val | |
}: SnippetProps): JSX.Element => { | |
const elements = [] |
NewerOlder