Problems I've spent much time to solve:
- Web servers. More exactly, API servers that communicate through HTTP.
- Choosing the right status codes for the situations.
| sudo su - | |
| mkdir -p /opt/bin | |
| curl -L https://github.com/docker/compose/releases/download/1.5.1/docker-compose-`uname -s`-`uname -m` > /opt/bin/docker-compose | |
| chmod +x /opt/bin/docker-compose |
| <script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script> | |
| <script type="text/javascript"> | |
| $(function() { | |
| $("a[href]").each( | |
| function(index, element) { | |
| if ( $(element).attr('href').indexOf('gist.github.com') > 0 ) { | |
| var divElement = $('<div></div>'); | |
| $(element).after(divElement); | |
| writeCapture.html(divElement, '<script src="'+$(element).attr('href')+'.js"></'+'script>'); |
| from IPython.core.magic import Magics, magics_class, line_magic | |
| import asyncio | |
| @magics_class | |
| class AsyncMagics(Magics): | |
| @line_magic | |
| def await(self, line): | |
| return asyncio.get_event_loop().run_until_complete(eval(line, self.shell.user_global_ns, self.shell.user_ns)) |
| import logging | |
| from sqlalchemy import inspect | |
| from sqlalchemy.ext.declarative.clsregistry import _ModuleMarker | |
| from sqlalchemy.orm import RelationshipProperty | |
| logger = logging.getLogger(__name__) | |
| def is_sane_database(Base, session): |
| # post_loc.txt contains the json you want to post | |
| # -p means to POST it | |
| # -H adds an Auth header (could be Basic or Token) | |
| # -T sets the Content-Type | |
| # -c is concurrent clients | |
| # -n is the number of requests to run in the test | |
| ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/ |
| """ | |
| SQLAlchemy, PostgreSQL (psycopg2), and autocommit | |
| See blog post: http://oddbird.net/2014/06/14/sqlalchemy-postgres-autocommit/ | |
| """ | |
| from contextlib import contextmanager | |
| from sqlalchemy import create_engine, event | |
| from sqlalchemy.orm import sessionmaker, Session as BaseSession |
$ python get_logs.py rds-db-instance-name rds.log aws-access-key aws-secret-key
$ ./pgbadger -p '%t:%r:%u@%d:[%p]:' ./rds.log
$ open out.html
| def get_count(q): | |
| count_q = q.statement.with_only_columns([func.count()]).order_by(None) | |
| count = q.session.execute(count_q).scalar() | |
| return count | |
| q = session.query(TestModel).filter(...).order_by(...) | |
| # Slow: SELECT COUNT(*) FROM (SELECT ... FROM TestModel WHERE ...) ... | |
| print q.count() |
| # -*- coding: utf-8 -*- | |
| """ | |
| This code won't be updated anymore. | |
| Project has moved to repository: https://github.com/devxoul/korail | |
| """ | |
| import requests | |
| from bs4 import BeautifulSoup | |
| from datetime import datetime |