This file contains 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/env python | |
# -*- coding: utf-8 -*- | |
# (c) Antoine Catton. Licensed under WTFPL <http://www.wtfpl.net/> | |
# Thank you Gavin Wahl for the idea. | |
import functools | |
class class_and_instance_method(object): | |
""" |
This file contains 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/env python3 | |
# -*- coding: utf-8 -*- | |
import functools | |
def memoize(func): | |
CACHE = dict() | |
@functools.wraps(func) | |
def wrapper(*args, **kwargs): | |
key = (tuple(args), frozenset(kwargs.items())) |
This file contains 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
# This was a relevation for me: | |
# <http://kukuruku.co/hub/algorithms/automatic-algorithms-optimization-via-fast-matrix-exponentiation.html> | |
def fib(n): | |
u_n = 1 | |
u_n1 = 0 | |
for i in xrange(1, n): | |
u_n1, u_n = u_n, (u_n1 + u_n) | |
return u_n |
This file contains 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/env python | |
# -*- coding: utf-8 -*- | |
# Copyright © 2015-present Antoine Catton | |
# This work is free. You can redistribute it and/or modify it under the | |
# terms of the Do What The Fuck You Want To Public License, Version 2, | |
# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details | |
def imerge_sorted(iterables, key=lambda x: x, reversed=False): | |
""" |
This file contains 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 GrandParent(object): | |
@classmethod | |
def call(cls): | |
return 1 | |
class Parent(GrandParent): | |
@classmethod | |
def call(cls): | |
return 1 + super(Parent, cls).call() |
This file contains 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 Data.Map.Strict as Map | |
import Data.List as List | |
import Control.Monad | |
data Transform = StringToInt (String -> Int) | |
| IntToString (Int -> String) | |
| IntToInt (Int -> Int) | |
| StringToString (String -> String) | |
This file contains 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/env python | |
# coding: utf-8 | |
# Copyright © 2017, figo GmbH | |
# This work is free. You can redistribute it and/or modify it under the | |
# terms of the Do What The Fuck You Want To Public License, Version 2, | |
# as published by Sam Hocevar. See the COPYING file or http://www.wtfpl.net/ | |
# for more details. | |
import argparse |
This file contains 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
# coding: utf-8 | |
# Copyright © 2017 Antoine Catton | |
# This work is free. You can redistribute it and/or modify it under the | |
# terms of the Do What The Fuck You Want To Public License, Version 2, | |
# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. | |
"""This is inspired from some mythical interview question (Google/Amazon/Microsoft, who knows..) | |
The goal is "compute the derivative of a polynomial". |
This file contains 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 render_table(data: List[List[str]]) -> str: | |
"""Render table: | |
Example: | |
>>> print(render_table([['a', 'b'], ['c', 'd'], ['long', 'very long']])) | |
+------+-----------+ | |
| a | b | | |
+------+-----------+ | |
| c | d | | |
+------+-----------+ |
This file contains 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/env python3 | |
# $ docker run --rm -it $(docker-aws) alpine | |
# / # env | grep -i aws | |
# AWS_DEFAULT_REGION=eu-central-1 | |
# AWS_SESSION_TOKEN=... | |
# AWS_ACCESS_KEY_ID=... | |
# AWS_SECRET_ACCESS_KEY=... | |
# | |
# When you don't want to mount `~/.aws:/root/.aws` because SELinux prevents you to do so. |
OlderNewer