A "Best of the Best Practices" (BOBP) guide to developing in Python.
- "Build tools for others that you want to be built for you." - Kenneth Reitz
- "Simplicity is alway better than functionality." - Pieter Hintjens
<?xml version="1.0" encoding="UTF-8"?> | |
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> | |
<CORSRule> | |
<AllowedOrigin>*</AllowedOrigin> | |
<AllowedMethod>GET</AllowedMethod> | |
<MaxAgeSeconds>3000</MaxAgeSeconds> | |
<AllowedHeader>Authorization</AllowedHeader> | |
<AllowedHeader>Content-*</AllowedHeader> | |
<AllowedHeader>Host</AllowedHeader> | |
</CORSRule> |
import requests | |
import time | |
import json | |
token = '' | |
#Delete files older than this: | |
ts_to = int(time.time()) - 30 * 24 * 60 * 60 | |
def list_files(): |
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""Encrypt/decrypt files with symmetric AES cipher-block chaining (CBC) mode. | |
Usage: | |
File Encryption: | |
aescrypt.py [-f] infile [outfile] |
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
var scimoz = ko.views.manager.currentView.scimoz, | |
savedPos = scimoz.currentPos, | |
savedLinePos = scimoz.firstVisibleLine; | |
try { | |
scimoz.text = scimoz.text.replace(/\t/gm, " "); | |
scimoz.gotoPos(savedPos); | |
scimoz.lineScroll(0, savedLinePos-scimoz.firstVisibleLine); | |
} catch(e) { | |
return true; |
<p> | |
My programming language of preference is python for the simple reason that I feel I write better code faster with it then I do with other languages. However also has a lot of nice tricks and idioms to do things well. And partly as a reminder to myself to use them, and partly because I thought this might be of general interest I have put together this collection of some of my favourite idioms. I am also putting this on <a href="https://gist.github.com/codefisher/9d7993ddbf404c505128">gist.github.com</a> so that anyone that wants to contribute there own things can, and I will try and keep this post up to date. | |
</p> | |
<h2>enumerate</h2> | |
<p> | |
A fairly common thing to do is loop over a list while also keeping track of what index we are up to. Now we could use a <code>count</code> variable, but python gives us a nicer syntax for this with the <code>enumerate()</code> function. | |
<script src="https://gist.github.com/codefisher/9d7993ddbf404c505128.js?file=enumerate.py"></script> |