$ python -c "print('True' if None < 0 else False)"
True
$ python3 -c "print('True' if None < 0 else False)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: unorderable types: NoneType() < int()
| """Print Fibonacci series using generator""" | |
| import argparse | |
| import textwrap | |
| def fibonacci(number): | |
| """Fibonacci series generator""" | |
| previous, current = 0, 1 | |
| counter = 0 |
| """Copied from http://hunterford.me/django-custom-model-manager-chaining/ | |
| Reference: http://www.dabapps.com/blog/higher-level-query-api-django-orm/ | |
| usage: | |
| Post.objects.published() | |
| Post.objects.by_author(user=request.user).published() | |
| """ | |
| from django.db import models | |
| """Sequence generator | |
| $ python sequence.py 3 | |
| [3] | |
| [2, 1] | |
| [1, 1, 1] | |
| $python sequence.py 6 | |
| [6] |
| a = [1, 2, 3] | |
| b = [4, 5, 6] | |
| zipped = zip(a,b) | |
| # zipped = [(1, 4), (2, 5), (3, 6)] | |
| unzipped = zip(*zippped) | |
| # unzipped = [(1, 2, 3), (4, 5, 6)] | |
| # get back a, b |
$ python -c "print('True' if None < 0 else False)"
True
$ python3 -c "print('True' if None < 0 else False)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: unorderable types: NoneType() < int()
| """Dashing module""" | |
| import logging | |
| import urllib2 | |
| import simplejson as json | |
| DEFAULT_DASHING_AUTH_TOKEN = 'YOUR_AUTH_TOKEN' |
| import functools | |
| import logging | |
| class SimpleWorkflowEngine(object): | |
| """A simple workflow engine | |
| Usage: | |
| from functools import partial | |
| def initialize(number): |
| # Color scheme for base16-builder based on gruvbox color scheme | |
| # (https://github.com/morhetz/gruvbox). | |
| # [1] gruvbox.yml | |
| scheme: "Gruvbox" | |
| author: "Gordon Chiam (https://github.com/gchiam)" | |
| base00: "282828" | |
| base01: "504945" | |
| base02: "7c6f54" | |
| base03: "ebdbb2" | |
| base04: "bdae93" |
| # This tmux statusbar config was created based on gruvbox colorscheme | |
| set -g status "on" | |
| set -g status-justify "left" | |
| set -g status-left-length "100" | |
| set -g status-right-length "100" | |
| set -g status-right-attr "none" | |
| set -g status-attr "none" | |
| set -g status-utf8 "on" | |
| set -g status-left-attr "none" |
| # spam.py | |
| try: | |
| import foo | |
| except ImportError: | |
| import simplefoo as foo |