Dorthu

       GitHub: @Dorthu
  • Function Captchas

    Dorthu        
    0 Likes Commentspython

    >>> def captcha(challenge=None, answer=None):
    ...   def _dec(f):
    ...     @wraps(f)
    ...     def _inner(*args, **kwargs):
    ...       if not challenge in kwargs or not kwargs[challenge] == answer:
    ...         raise ValueError('captcha failed!')
    ...       del kwargs[challenge]
    ...       return f(*args, **kwargs)
    ...     return _inner
    ...   return _dec
    ...
    >>> @captcha(challenge='two_plus_three', answer=5)
    ... def foo(bar):
    ...   print("bar is {}".format(bar))
    ...
    >>> foo('test')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<stdin>", line 6, in _inner
    ValueError: captcha failed!
    >>> foo('test', two_plus_three=5)
    bar is test
  • Distilled Greatness

    Dorthu        
    0 Likes Commentsperl

    print map { tr/at/pl/r } grep { (ord) % 4 < 3 } sort split //, 'great';
  • Permu-say-tions

    Dorthu        
    1 Likes Commentsperl

    $word = shift;
    `say $word` while ++$word;