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
| $ curl -I cn.ubuntu.com | |
| ... | |
| Date: Fri, 12 Feb 2016 22:48:38 GMT | |
| Expires: Fri, 12 Feb 2016 22:53:35 GMT | |
| Last-Modified: Fri, 12 Feb 2016 22:48:35 GMT | |
| Cache-Control: max-age=300 |
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
| class OurTemplateView(TemplateView): | |
| def render_to_response(self, context, **response_kwargs): | |
| # Get response from parent TemplateView class | |
| response = super(CmsTemplateFinder, self).render_to_response( | |
| context, **response_kwargs | |
| ) | |
| # Add Cache-Control and Expires headers | |
| patch_response_headers(response, cache_timeout=300) |
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 django.views.generic.base import TemplateView | |
| class OurTemplateView(TemplateView): | |
| # Setup our custom template data |
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 wsgiref.simple_server import make_server | |
| def application(env, start_response): | |
| """ | |
| A basic WSGI application | |
| """ | |
| http_status = '200 OK' | |
| response_headers = [('Content-Type', 'text/html')] |
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 os | |
| from contextlib import contextmanager | |
| @contextmanager | |
| def working_directory(path): | |
| """ | |
| A context manager which changes the working directory to the given | |
| path, and then changes it back to its previous value on exit. | |
| Usage: |
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 bash | |
| ## | |
| # Usage: | |
| # ./grey-invert.sh my-doc.pdf | |
| # | |
| # This will: | |
| # - Convert to images and store in a /tmp directory | |
| # - Greyscale images | |
| # - Invert images |
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 | |
| import yaml | |
| import subprocess | |
| status_command = "juju status" | |
| status_output = subprocess.check_output(status_command.split()) | |
| status = yaml.load(status_output) |
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 hypothesis.strategies import lists, floats | |
| @given(lists(floats())) | |
| def test_average(float_list): | |
| ave = reduce(lambda x, y: x + y, float_list) / len(float_list) | |
| assert average(float_list) == ave |
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 test_average(): | |
| assert my_average([2, 4]) == 3 |
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
| #!/bin/sh | |
| dirname=Pictures | |
| find $dirname -type f | sed 's_.*/__' | sort| uniq -d| | |
| while read fileName | |
| do | |
| find $dirname -type f | grep "$fileName" | |
| done |