For example if I paste this:
---
thing:
description: "Oh boy."
stuff:
- "i am a string"
- null
- ~
- "null"
from django.db import connection | |
def queryset_to_postgres(qs): | |
""" | |
Given a `QuerySet`, return a correctly formatted (but not pretty-printed) sql string that can be run | |
on postgres. | |
For debugging only, as `cursor.mogrify` is specific to psycopg2, not part of python db api. | |
Needed because the usual `str(qs.query)` gives generic sql that may not execute correctly on postgres, | |
eg. case-sensitive names may not be cased correctly. |
In [3]: from django.test import RequestFactory | |
In [4]: rf = RequestFactory() | |
In [5]: req = rf.get('/foo', {'bar': ['baz', 'bat']}) | |
In [6]: req # this looks like expected: | |
Out[6]: <WSGIRequest: GET '/foo?bar=baz&bar=bat'> | |
In [7]: req.GET['bar'] # Why does this give me only one value? |
# Find slowest queries | |
grep "^SELECT " mysql-slowquery.log | cut -d ' ' -f 1-5 | sort | uniq -c | sort -n | |
# Now find times for one of those queries. Wrap in single quotes and backslash-escape wildcards | |
QUERY='^SELECT count(\*) FROM `foo` INNER JOIN `blah`' | |
grep -B2 "$QUERY" mysql-slowquery.log | grep Query_time | cut -d ' ' -f 3 | sort -n |
For example if I paste this:
---
thing:
description: "Oh boy."
stuff:
- "i am a string"
- null
- ~
- "null"
$ convert --version | |
Version: ImageMagick 6.6.9-7 2014-03-06 Q16 http://www.imagemagick.org | |
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC | |
Features: OpenMP | |
$ for i in `seq 10`; do time /usr/bin/env MAGICK_TIME_LIMIT=1 convert test.jpg test.png || echo FAILED; done | |
real 0m19.098s | |
user 0m18.652s | |
sys 0m0.112s |
$ convert --version | |
Version: ImageMagick 6.8.9-8 Q16 x86_64 2014-10-14 http://www.imagemagick.org | |
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC | |
Features: DPC OpenMP | |
Delegates: fontconfig freetype jng jpeg pangocairo png x xml zlib | |
$ for i in `seq 10`; do time /usr/bin/env MAGICK_TIME_LIMIT=1s convert test.jpg test.png || echo FAILED; done | |
real 0m6.919s | |
user 0m6.648s |
""" | |
TL/DR: | |
Never instantiate mock.Mock() directly. | |
Instead use either mock.create_autospec(YourClass) OR mock.patch('YourClass', autospec=True). | |
The "spec" feature of Mock is great, it helps avoid your mocked API drifting out of sync with your real API. | |
But there is a gotcha if you are mocking classes directly - it's easy to mock the class but you need to | |
ensure the spec applies to the *instance* as well. | |
""" |
# It accepts a precision?? | |
In [13]: print '%.5s' % "Oh hi this is a long string" | |
Oh hi | |
# It magically knows whether you need a unicode or bytestring representation. | |
In [10]: class Foo2(object): | |
....: def __str__(self): return "stringy" | |
....: def __unicode__(self): return u"unicodey" |
searching for ghc in path. | |
found ghc at /usr/bin/ghc | |
("/usr/bin/ghc",["--numeric-version"]) | |
/usr/bin/ghc is version 7.6.3 | |
looking for tool "ghc-pkg" near compiler in /usr/bin | |
found ghc-pkg in /usr/bin/ghc-pkg | |
("/usr/bin/ghc-pkg",["--version"]) | |
/usr/bin/ghc-pkg is version 7.6.3 | |
("/usr/bin/ghc",["--supported-languages"]) | |
("/usr/bin/ghc",["--info"]) |
diff -u -r /usr/local/lib/python2.7/dist-packages/pinocchio/stopwatch.py /home/vagrant/tmp/pinocchio/stopwatch.py | |
--- /usr/local/lib/python2.7/dist-packages/pinocchio/stopwatch.py 2014-02-19 18:55:30.000000000 +0000 | |
+++ /home/vagrant/tmp/pinocchio/stopwatch.py 2014-02-19 18:50:40.064935116 +0000 | |
@@ -37,6 +37,14 @@ | |
default=".nose-stopwatch-times", | |
help="Store test timing results in this file.") | |
+ parser.add_option("--stopwatch-report-slowest", | |
+ action="store", | |
+ dest="stopwatch_report_slowest", |