5 years, 100 Facebook fans, 300 posts, 1000 comments later: we celebrate the blog. Thank you for all the readers for keeping up with us.
PythonTidy does not lint or validate Python source code – it rewrites it to follow PEP-8 (and other) configured rules.
PythonTidy is very useful if you need to
Adhering PEP-8 is also must when you are using a text editor which highlights linting errors in your source code while typing. If your source code is full of unneeded style errors you’ll miss the actual linting errors among them.
PythonTidy was created by Chuck Rhode.
The basic PythonTidy works from the command line. However, in this blog I show how to use PythonTidy plugin, by Andreas Zeidler, in Sublime Text 2 code editor with one key press integration. Sublime Text 2 has very powerful Python linting support through SublimeLinterl package, highlighting style and linting errors when you type.
First install PythonTidy using git (note: Sublime Text 2 own package control installer does not work due to usage of Git submodules, you need to do this from command line).
Below is a screenshot with two style errors (no space after comma, bad number of newlines between module main level code blocks).
Now you simply press CONTRL+CMD+ALT+T: your source is fixed:
PythonTidy uses ~/.pythontidy.xml configuration file. A default setting value which most people probably want to change is the line length – PythonTidy shortens your line to 76 characters by default as recommended by PEP-8, and this is really quite short for the modern widescreens, wasting a lot of space. (I know there are some crazy people using tmux + vim + some other terminal stuff from golden early 80s and splitting their screen to 12 mini squares, but most of us don’t do that…)
<config> <parm name="COL_LIMIT" value="int(1000)" /> <parm name="SHEBANG" value="" /> <parm name="PARENTHESIZE_TUPLE_DISPLAY" value="bool(False)" /> <parm name="ADD_BLANK_LINES_AROUND_COMMENTS" value="bool(False)" /> <parm name="ADD_BLANK_LINE_AFTER_DOC_STRING" value="bool(False)" /> <parm name="MAX_SEPS_FUNC_DEF" value="int(99)" /> <parm name="MAX_SEPS_FUNC_REF" value="int(99)" /> <parm name="WRAP_DOC_STRINGS" value="bool(False)" /> <parm name="NORMALIZE_DOC_STRINGS" value="bool(False)" /> </config>
Note: Looks like you cannot add XML comments in config for now.
Please post as a comment if you know any other text editors with PythonTidy or background PEP-8’ing support. I am especially interest how one could intergrate this with Eclipse + PyDev.
Often when inspecting an UNIX server as a sysadmin you need to find and kill a (hung) process running with a certain command line arguments.
ps -Af|grep -i "xcmd" ... list of all processes running on the server matching xcmd here ...
Even though chaining commands is something UNIX philosophy encourages there exist specific commands for finding processes and killing them. pgrep searches from processes and pkill kills them. The sister commands use the same syntax.
Here is an example. We have a cron script which will open a SSH tunnel for the background. Then this tunnel is used to communicate with remote server by other processes in the same script. Sometimes, however, SSH tunnel can hang due to network reasons. The tunnel is started with command in this is used in one of /etc/cron.d scripts:
# daemon mode + do not open remote shell ssh -fN example.com -L 2244:internal.example.com:22
(If you are planning to create more robust solution it is suggested to use lock files instead where the process id is written each time the background process is started. However, here we discuss about the solution which is quick to implement and easy to understand.)
First we note this problem by inspecting the process list by the traditional means:
ps -Af|grep -i ssh
And in the output we see the bad process – we verify it is not working as the tunneled port indeed does not communicate with the remote server:
root 8292 1 0 09:37 ? 00:00:00 ssh example.com -L 2244:internal.example.com:22 -fN
Now we can see if pgrep also can find this process by matching full command line (-f switch)
pgrep -f 'ssh example.com' 8292
And now, we simply put a command at the beginning of our cron script to kill the previous tunnel, regardless if it is hung or not, wen running the script. Please note that the side effect is that this will kill all other SSH commands with the same command line on the server: in our case it does not matter, as the tunnel should be only started and maintained by this one cron script.
#!/bin/sh # Kill existing pipes if they are hung pkill -f 'ssh example.com' ssh example.com -L 2244:internal.example.com:22 -fN # script goes here...
Animated GIF images are a good method for demonstrating your application, library or framework UI functionality and features: as one picture tells more than thousand words, one animation tells more than your average megapolis telephone directory.
(The example screen capture courtesy of jQuery Interdependencies)
The benefits of animated GIFs
Here are short instructions how to create animated GIF screen recordings on OSX.
Screencast videos can be recorded with OSX’s own QuickTime player – no additional applications needed (since OSX Lion?). QuickTime player works scaring well. Just choose File > New Screen Recording and choose the area which you want to record
The resulting h264 MPEG5 as .mov file needs to be post-processed to animated GIF. I found GIFBrewery (~5 USD) suitable for this purpose. You could do it by hand with free software, but GIFBrewery provides nice “tune settings and see live preview” style functionality which saves a lot of your valuable time.
Note: I had a bug in GIFBrewery where the animation colors got screwed up if I tried to to move starting frame (probably related to h264 key framing?).
Try to make the target area as small as possible. Resize your browser window, zoom out fonts, use lower resolution and such tricks.
You can do further cropping in GIFBrewery.
Set animated GIF frames per second to low number like 3 -5 frames per second. FPS is not usually critical factor for screen recordings where your purpose is to demostrate the UI element interaction.
OSX may do font subpixel antialiasing by default (some more info). You might want to turn off this for screen recordings, as subpixel antialiasing is tied to (your own) monitor and may create funny looking color artifacts on other displays when your recording is being viewed.
To turn it off in Terminal:
defaults -currentHost write -globalDomain AppleFontSmoothing -int 2
defaults -currentHost delete -globalDomain AppleFontSmoothing
You need to restart the applications after changing this setting. The easiest way to test the setting on Finder is:
killall Finder # Will autorestart
ImageOptim is an OSX application which will optimize all dragged and dropped images in place. For me, it provided 33% saving in the GIF size for GIFBrewery exported files.