Skip to content

Instantly share code, notes, and snippets.

@jonasreinsch
Last active February 25, 2016 15:35
Show Gist options
  • Save jonasreinsch/1ef492ed73c94078a246 to your computer and use it in GitHub Desktop.
Save jonasreinsch/1ef492ed73c94078a246 to your computer and use it in GitHub Desktop.
TIL (Today I learned)

2016-02-25

Python has type annotations since 3.5:

def greater_than_10(a:int) -> bool:
    return a > 10

class Tank:
    def __init__(self):
        self.fill = 0

    def tank(self, amount:float):
         return(self.fill += amount)

See also: the typing module documentation.

2016-02-24

UIView has a method addSubviews(_ views:[UIView])

which allows to add more than one view at once. It's not in the documentation.

2016-02-17

How to use IPython Shell as Django shell. If you are in a virtualenv, be sure to install ipython with

$ pip install ipython

Then start the Django shell with

$ python admin.py -i shell

2016-02-16

explicit relative imports:

from .models import WaffleCone # use when importing from another module in the current app

2016-02-11

Efficient renaming without changing the Path. In my ~/Downloads directory, I wanted to reanme the file annotatet to annotated. Of course, I could cd to ~/Downloads and do the renaming there, but instead I used the Brace Expansion feature of Bash:

$ mv ~/Downloads/annotate{t,d}_offer.png

This is also useful for e.g. creating paths with a common prefix and the braces can also be nested:

$ echo ers{etzen,atz{zahnrad,fahrrad}}

expands to:

ersetzen ersatzzahnrad ersatzfahrrad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment