obda.net

Redirect STDIN in a Shell Script

Add a comment

cheat-sheet articles are about code snippets that I need every once in a while, and which I constantly forget about.

If you have a shell script, and want to redirect all input it receives via STDIN to another script or program, use <&0:

#!/bin/zsh
/path/to/another/script.pl --script-args <&0

Finding All Loggers in Python

Add a comment

cheat-sheet articles are about code snippets that I need every once in a while, and which I constantly forget about.

logging.Logger.manager.loggerDict holds a dictionary of all loggers that have been requested.

>>> import logging
>>> logging.Logger.manager.loggerDict
{}
>>> logging.getLogger('foo')
<logging.Logger object at 0x7f11d4d104d0>
>>> logging.getLogger('bar')
<logging.Logger object at 0x7f11d4cb7ad0>
>>> logging.Logger.manager.loggerDict
{'foo': <logging.Logger object at 0x7f11d4d104d0>,
'bar': <logging.Logger object at 0x7f11d4cb7ad0>}

Found at http://code.activestate.com/lists/python-list/621740/.

Zsh History Expansion

1 comment

cheat-sheet articles are about code snippets that I need every once in a while, and which I constantly forget about.

Shortcut Description
!! the entire previous command
!!^ the first argument from the previous command
!!* all arguments from the previous command
!!:n the n-th word from the previous command
!!$ the last word from the previous command
!# the entire current command line (typed in so far)
!#^ the first argument from the current command line
!#* all arguments from the current command line
!#:n the n-th word from the current command line
!#$ the last word from the current command line

For more information, read Andrew Grangaard’s Zsh history expansion article.