My First Markdown Post

Conversion to Markdown Progress
Next TODO: My Python Idioms
Posting in Markdown Result Summary
I LIKE IT πŸ™‚
WordPress uses Markdown Extra
See “Here’s the Source” below.
N.B. In the source Backtick stands for `
My Rules

  • I’ll publish in the Text Editor NOT the Visual Editor
  • For Main Headings I’ll use: Header 2 == HASH HASH item
  • For Sub Headings: Bold == STAR STAR item STAR STAR
  • For Anchored Main Headings: HASH HASH Item LBRACE HASH item RBRACE
  • For links to Anchors: LSQBRACKET Modules LSQBRACKET (HASH modules)

Sample Python Code Snippet

#!/usr/local/bin/python2.7
r"""
search.py recursively searches searchPath for the fileNamePattern Producing a listing of matching paths 

Usage:   search.py  searchPath                           fileNamePattern
Example: search.py  C:\1d\PeacebookPj\Peacebook-env\     templates
"""
import glob
import sys
import os
import fnmatch

def main(argv=None):
  N_ARGS = 2
  if argv == None: argv=sys.argv
  args = argv[1:]  
  if len(args) != N_ARGS or "-h" in args or "--help" in args:
    print __doc__
    sys.exit(2)
  searchPath = args[0]; fileNamePattern = args[1]

  #see fred lundh http://mail.python.org/pipermail/python-list/2001-February/069987.html & GlobDirectoryWalker below
  for file in GlobDirectoryWalker(searchPath, fileNamePattern):
    print (file)


class GlobDirectoryWalker:
  # a forward iterator that traverses a directory tree

  def __init__(self, directory, pattern="*"):
    self.stack = [directory]
    self.pattern = pattern
    self.files = []
    self.index = 0

  def __getitem__(self, index):
    while 1:
      try:
        file = self.files[self.index]
        self.index = self.index + 1
      except IndexError:
        # pop next directory from stack
        self.directory = self.stack.pop()
        self.files = os.listdir(self.directory)
        self.index = 0
      else:
        # got a filename
        fullname = os.path.join(self.directory, file)
        if os.path.isdir(fullname) and not os.path.islink(fullname):
          self.stack.append(fullname)
        if fnmatch.fnmatch(file, self.pattern):
            return fullname


if __name__ == '__main__':
  sys.exit(main())

OK. Let’s see how it all looks. I hit Publish.

Here’s the Source
N.B. Backtick stands for `

**My Rules**
* I'll publish in the Text Editor NOT the Visual Editor
* I'll use only bold for headings
**Sample Python Code Snippet**
Backtick Backtick Backtick python
#!/usr/local/bin/python2.7
r"""
search.py recursively searches searchPath for the fileNamePattern Producing a listing of matching paths 

Usage:   search.py  searchPath                           fileNamePattern
Example: search.py  C:\1d\PeacebookPj\Peacebook-env\     templates
"""
import glob
import sys
import os
import fnmatch

def main(argv=None):
  N_ARGS = 2
  if argv == None: argv=sys.argv
  args = argv[1:]  
  if len(args) != N_ARGS or "-h" in args or "--help" in args:
    print __doc__
    sys.exit(2)
  searchPath = args[0]; fileNamePattern = args[1]

  #see fred lundh http://mail.python.org/pipermail/python-list/2001-February/069987.html & GlobDirectoryWalker below
  for file in GlobDirectoryWalker(searchPath, fileNamePattern):
    print (file)


class GlobDirectoryWalker:
  # a forward iterator that traverses a directory tree

  def __init__(self, directory, pattern="*"):
    self.stack = [directory]
    self.pattern = pattern
    self.files = []
    self.index = 0

  def __getitem__(self, index):
    while 1:
      try:
        file = self.files[self.index]
        self.index = self.index + 1
      except IndexError:
        # pop next directory from stack
        self.directory = self.stack.pop()
        self.files = os.listdir(self.directory)
        self.index = 0
      else:
        # got a filename
        fullname = os.path.join(self.directory, file)
        if os.path.isdir(fullname) and not os.path.islink(fullname):
          self.stack.append(fullname)
        if fnmatch.fnmatch(file, self.pattern):
            return fullname


if __name__ == '__main__':
  sys.exit(main())
Backtick Backtick Backtick 

OK. Let's see how it all looks. I hit Publish.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s