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 random | |
def knuth_durstenfeld_shuffle(arr): | |
for i in range(len(arr) - 1, 0, -1): | |
j = random.randint(0, i) | |
arr[i], arr[j] = arr[j], arr[i] |
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
version: "2" | |
services: | |
rancher: | |
image: rancher/server:stable | |
container_name: "rancher-server" | |
restart: always | |
ports: | |
- "8080:8080" | |
volumes: | |
- ./rancher/mysql:/var/lib/mysql |
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 string import ( | |
ascii_letters, | |
digits, | |
) | |
from random import choice | |
from typing import Iterable | |
LETTERS_AND_DIGITS = ascii_letters + digits | |
def rand_str(n: int, s: Iterable = LETTERS_AND_DIGITS) -> str: |
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/env python | |
# encoding: utf-8 | |
# adjacency matrix | |
graph = {'A': set(['B', 'C']), | |
'B': set(['A', 'D', 'E']), | |
'C': set(['A', 'F']), | |
'D': set(['B']), | |
'E': set(['B', 'F']), | |
'F': set(['C', 'E'])} |
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 tag(name, *content, cls=None, **attrs): | |
"""Generate one or more HTML tags""" | |
if cls is not None: | |
attrs['class'] = cls | |
if attrs: | |
attr_str = ''.join(' %s="%s"' % (attr, value) | |
for attr, value | |
in sorted(attrs.items()) | |
else: |
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 <<Fluent Python>> ch4: Text versus Bytes | |
from unicodedata import normalize | |
import string | |
def nfc_equal(str1, str2): | |
""" | |
s1 = 'café' | |
s2 = 'cafe\u0301' |
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 falcon.util | |
import functools | |
import inspect | |
import six | |
def get_argnames(func): | |
if six.PY2: | |
if isinstance(func, functools.partial): | |
spec = inspect.getargspec(func.func) |
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 falcon.util | |
# use `six` module for compatibility in essence | |
import six | |
def get_bound_method(obj, method_name): | |
method = getattr(obj, method_name, None) | |
if method is not None: | |
if six.get_method_self(method) is None: | |
raise AttributeError('method {} not found'.format(method_name)) |
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 werkzeug.utils | |
# a decorator that converts a function into a lazy property | |
# derived from built-in property and override __get__ and __set__ | |
class Missing(object): | |
def __repr__(self): | |
return 'no value' | |
def __reduce__(self): | |
return '_missing' |
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
s = s.replace('&', '&').replace('<', '<').replace('>', '>').reqlace('"', '"') |
NewerOlder