Brandon Rhodes
Python, Linux, KDE
Saturday, May 18, 2013
Python Design Patterns
The Python community has learned a lot about how to use our language since we started back in the 1990s, and this talk will use simple one-slide programs to illustrate the crucial refactorings that can help make a large real-life application far more testable and maintainable while making its code easier to re-use. This will not be a re-hash of Gang-of-Four refactorings, but specific to Python.
Brandon Rhodes
Brandon Rhodes
Loop like a native: while, for, iterators, generators
Python provides powerful primitives for iterating over your data in ways that let you express yourself clearly and directly. But even programmers familiar with the tools don't use them as fully as they could. This talk will cover Python's iteration tools, from basic loops to generators and how to add iteration to your own classes. Come learn how looping was meant to be!
Ned Batchelder
Wednesday, May 15, 2013
Profiling Django
1. Install django-extensions:
pip install django-extensions
2. Add to `local.py`:
INSTALLED_APPS += ('django_extensions',)
3. Run the profiling server passing the directory where profiling data will be saved for each request:
./manage.py runprofileserver --use-cprofile --prof-path=/tmp/my-profile-data
4. Make some requests to the server via browser or other client.
5. Download gprof2dot.py and generate graphs for all the profiled requests:
for prof_file in /tmp/my-profile-data/*.prof; do python gprof2dot.py -f pstats "$prof_file" | dot -Tpng -o `basename $prof_file .prof`; done
6. Now in the current directory you have a set of .png files with profiling graphs.
Friday, May 10, 2013
The Myth of the Genius Programmer
I liked this talk, though it was difficult for me to follow without slides or pictures.
This talk is relevant to me, because I have been experiencing this for the last several years in different companies I've been working for. I think there are no people who can and do know everything. We should not consider ourselves geniuses and make our colleagues feel underestimated. I think we should help others and ask for help whenever we need.
This talk is relevant to me, because I have been experiencing this for the last several years in different companies I've been working for. I think there are no people who can and do know everything. We should not consider ourselves geniuses and make our colleagues feel underestimated. I think we should help others and ask for help whenever we need.
So there's no geniuses.
It's our natural instinct to try and want to be a genius, but we should fight that and actually try to collaborate as much as we can, early, often.
Don't be afraid of collaboration.
And pay attention to what your tools are doing to you and the people you work with, 'cause they do affect your collaborative behavior.
And finally, make sure you're paying attention to when you collaborate: not too early, not too late. There's a critical sweet spot for success in collaboration.
And of course, there's actually a secret to all this that you probably shouldn't share outside of this room, but believe it or not, if you actually do all these things, people will think you're a genius. Because it's not the typical thing that people do - people don't make themselves vulnerable, they're not open to influence.
Thursday, May 9, 2013
Simple uwsgi + wsgi app
No Nginx, using uWSGI embedded HTTP server.
First, we create a Python virtual environment and install uswgi in it:
Then we run uwsgi pointing it to our wsgi application:
myapp.py:
Now you see a simple "Hello world" page on URL http://localhost:8080/?name=Victor.
First, we create a Python virtual environment and install uswgi in it:
vic@vic-X202E ~/projects » mkvirtualenv -p /usr/bin/python uwsgi Running virtualenv with interpreter /usr/bin/python New python executable in uwsgi/bin/python Installing setuptools............................done. Installing pip...............done. [uwsgi] vic@vic-X202E ~/projects » pip install uwsgi Downloading/unpacking uwsgi Downloading uwsgi-1.9.9.tar.gz (617kB): 617kB downloaded Running setup.py egg_info for package uwsgi ... Successfully installed uwsgi Cleaning up...
Then we run uwsgi pointing it to our wsgi application:
[uwsgi] vic@vic-X202E ~/projects/test-uwsgi » uwsgi --http :8080 --wsgi myapp:app *** Starting uWSGI 1.9.9 (64bit) on [Thu May 9 23:07:54 2013] *** compiled with version: 4.7.3 on 09 May 2013 18:40:27 os: Linux-3.8.0-19-generic #29-Ubuntu SMP Wed Apr 17 18:16:28 UTC 2013 nodename: vic-X202E machine: x86_64 clock source: unix pcre jit disabled detected number of CPU cores: 4 current working directory: /home/vic/projects/test-uwsgi detected binary path: /home/vic/projects/.envs/uwsgi/bin/uwsgi *** WARNING: you are running uWSGI without its master process manager *** your processes number limit is 28786 your memory page size is 4096 bytes detected max file descriptor number: 1024 lock engine: pthread robust mutexes uWSGI http bound on 127.0.0.1:8080 fd 4 spawned uWSGI http 1 (pid: 8456) uwsgi socket 0 bound to TCP address 127.0.0.1:54513 (port auto-assigned) fd 3 Python version: 2.7.4 (default, Apr 19 2013, 18:30:41) [GCC 4.7.3] *** Python threads support is disabled. You can enable it with --enable-threads *** Python main interpreter initialized at 0x2034e10 your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 72688 bytes (70 KB) for 1 cores *** Operational MODE: single process *** WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x2034e10 pid: 8455 (default app) *** uWSGI is running in multiple interpreter mode *** spawned uWSGI worker 1 (and the only) (pid: 8455, cores: 1)
myapp.py:
import cgi def app(environ, start_response): parameters = cgi.parse_qs(environ.get('QUERY_STRING', '')) # get the `name` parameter if exists name = parameters.get('name', ['World'])[0] # return headers start_response('200 OK', [('Content-Type', 'text/html')]) # return body return ['Hello %s!' % name]
Now you see a simple "Hello world" page on URL http://localhost:8080/?name=Victor.
Thursday, May 2, 2013
"Good enough" is good enough!
A good talk by Alex Martelli:
Our culture's default assumption is that everybody should always be striving for perfection -- settling for anything less is seen as a regrettable compromise. This is wrong in most software development situations: focus instead on keeping the software simple, just "good enough", launch it early, and iteratively improve, enhance, and re-factor it. This is how software success is achieved!
Getting started with automated testing
A really good talk on testing practices:
Getting started with automated testing
Subscribe to:
Posts (Atom)