<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Madphilosopher's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 17:48:28 GMT</pubDate>
    <description>DZone Snippets: Madphilosopher's Code Snippets</description>
    <item>
      <title>Python CGI script to display client's IP address</title>
      <link>http://snippets.dzone.com/posts/show/1840</link>
      <description>When run as a cgi script, this will print the client's IP address.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import cgi&lt;br /&gt;import os&lt;br /&gt;&lt;br /&gt;print "Content-type: text/html"&lt;br /&gt;print ""&lt;br /&gt;&lt;br /&gt;print cgi.escape(os.environ["REMOTE_ADDR"])&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 04 Apr 2006 19:54:21 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1840</guid>
      <author>madphilosopher (Darren Paul Griffith)</author>
    </item>
    <item>
      <title>sox audio editor settings for companding voice</title>
      <link>http://snippets.dzone.com/posts/show/1497</link>
      <description>I used the following sox audio editor settings to do dynamic compression on voice.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;sox in.wav out.wav lowpass 4000 compand 0.1,0.3 -60,-60,-30,-15,-20,-12,-4,-8,-2,-7 -2&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 16 Feb 2006 11:37:58 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1497</guid>
      <author>madphilosopher (Darren Paul Griffith)</author>
    </item>
    <item>
      <title>Create a single JPG gallery from an image archive</title>
      <link>http://snippets.dzone.com/posts/show/878</link>
      <description>The following comes from &lt;a href="http://ascii.textfiles.com/archives/000137.html"&gt;Jason Scott&lt;/a&gt; and is posted here with permission under the &lt;a href="http://creativecommons.org/licenses/by-sa/1.0/"&gt;Creative Commons Attribution-ShareAlike License&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The script expands a zip or rar archive of images, makes thumbnails, and compiles the thumbnails into a single JPG to represent what's in the archive. Requires &lt;a href="http://www.imagemagick.org/"&gt;ImageMagick&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;# GALLERATE: Turn a zip of images into a gallery.&lt;br /&gt;# From Jason Scott. http://ascii.textfiles.com/archives/000137.html&lt;br /&gt;if [ -f "$1" ]&lt;br /&gt;   then&lt;br /&gt;   rm -rf .galleryworld&lt;br /&gt;   echo "[%] Preparting to squat out $1...."&lt;br /&gt;   mkdir .galleryworld&lt;br /&gt;   cd .galleryworld&lt;br /&gt;   unzip -j "../$1"&lt;br /&gt;   unrar e -ep "../$1"&lt;br /&gt;   echo "[%] WHY DOES IT HURT!!!!"&lt;br /&gt;   montage +frame +shadow +label -tile 7 *.JPG *.GIF *.gif *.jpg *.bmp *.png *.PNG *.BMP "../$1.jpg"&lt;br /&gt;   cd ..&lt;br /&gt;   rm -rf .galleryworld&lt;br /&gt;   ls -l "$1.jpg"&lt;br /&gt;  else&lt;br /&gt;  echo "No such file, assmaster."&lt;br /&gt;fi&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Usage:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;GALLERATE [file]&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;where [file] is the zip or rar archive of images to be processed.</description>
      <pubDate>Wed, 09 Nov 2005 07:05:13 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/878</guid>
      <author>madphilosopher (Darren Paul Griffith)</author>
    </item>
    <item>
      <title>Filter all URLs from standard input</title>
      <link>http://snippets.dzone.com/posts/show/877</link>
      <description>Code:&lt;br /&gt;&lt;br /&gt;Put the following in a file named url_scrape.py.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env python&lt;br /&gt;'''Prints a list of URLs that are found in standard input.&lt;br /&gt;&lt;br /&gt;It will only find URLs between quotes ("" or '') and starting with http://&lt;br /&gt;'''&lt;br /&gt;&lt;br /&gt;import re&lt;br /&gt;import sys&lt;br /&gt;&lt;br /&gt;# Pattern for fully-qualified URLs:&lt;br /&gt;url_pattern = re.compile('''["']http://[^+]*?['"]''')&lt;br /&gt;&lt;br /&gt;# build list of all URLs found in standard input&lt;br /&gt;s = sys.stdin.read()&lt;br /&gt;all = url_pattern.findall(s)&lt;br /&gt;&lt;br /&gt;# output all the URLs&lt;br /&gt;for i in all:&lt;br /&gt;    print i.strip('"').strip("'")&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Example Usage:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;wget -O - http://madphilosopher.ca/ | ./url_scrape.py | sort | uniq&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 09 Nov 2005 06:42:16 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/877</guid>
      <author>madphilosopher (Darren Paul Griffith)</author>
    </item>
    <item>
      <title>Scan the FreeBSD ports collection and print one-line summary for each port</title>
      <link>http://snippets.dzone.com/posts/show/876</link>
      <description>The FreeBSD ports collection is a skelton of installable software on a local FreeBSD machine. This small utility lets you scan the collection by category, to find out what software is available in that category. Call the script portinfo.py. &lt;br /&gt;&lt;br /&gt;A deeper explanation of the script can be found &lt;a href="http://madphilosopher.ca/code/portinfo-script/"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;"""Scans a directory under /usr/ports/ and gives the portname and comment for each port found."""&lt;br /&gt;&lt;br /&gt;import os&lt;br /&gt;import os.path&lt;br /&gt;import sys&lt;br /&gt;&lt;br /&gt;def findmakefiles(curdir):&lt;br /&gt;    '''goes one level deep under curdir to find and act on the Makefiles.'''&lt;br /&gt;&lt;br /&gt;    for name in os.listdir(curdir):&lt;br /&gt;        pathname =  os.path.join(curdir,  name, 'Makefile')  # COMMENTs are found in the Makefiles&lt;br /&gt;        if os.path.isfile(pathname):&lt;br /&gt;            processmakefile(name, pathname)&lt;br /&gt;&lt;br /&gt;def processmakefile(name, pathname):&lt;br /&gt;    '''grabs the port's COMMENT from the Makefile.'''&lt;br /&gt;    f = open(pathname)&lt;br /&gt;    data = f.readlines()&lt;br /&gt;    for line in data:&lt;br /&gt;        if line[0:7] == 'COMMENT':&lt;br /&gt;            try:&lt;br /&gt;                comment = line.strip().split('\t')[1]   # most COMMENTs are tab delimited&lt;br /&gt;            except:&lt;br /&gt;                comment = line.strip()                  # some are not, so just print the whole line&lt;br /&gt;            print "%-15s  %s" % (name, comment)&lt;br /&gt;&lt;br /&gt;    f.close()&lt;br /&gt;&lt;br /&gt;def usage():&lt;br /&gt;    print 'Usage: portinfo.py /usr/ports/[category]'&lt;br /&gt;    sys.exit(1)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if __name__ == '__main__':&lt;br /&gt;&lt;br /&gt;    # get directory from command line&lt;br /&gt;    args = sys.argv[1:]&lt;br /&gt;    if len(args) == 1:&lt;br /&gt;        curdir = args[0]&lt;br /&gt;    else:&lt;br /&gt;        usage()&lt;br /&gt;    &lt;br /&gt;##    curdir = '/usr/ports/security/'&lt;br /&gt; &lt;br /&gt;    # scan this directory   &lt;br /&gt;    if os.path.isdir(curdir):&lt;br /&gt;        findmakefiles(curdir)&lt;br /&gt;    else:&lt;br /&gt;        sys.stdout = sys.stderr&lt;br /&gt;        print "'%s' is not a valid directory." % curdir&lt;br /&gt;        usage()&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 09 Nov 2005 06:15:49 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/876</guid>
      <author>madphilosopher (Darren Paul Griffith)</author>
    </item>
    <item>
      <title>Shell script to look up words at dictionary.com from the command line</title>
      <link>http://snippets.dzone.com/posts/show/875</link>
      <description>The following will look up a word on dictionary.com from the command line, where $1 is the word you want to look up, entered in as a parameter on the command line. (Lynx is a text-based browser that handles the html-to-text conversion for us.)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/sh &lt;br /&gt;lynx -dump -nolist -pseudo_inlines                \&lt;br /&gt;  'http://dictionary.reference.com/search?q='$1'&amp;r=67'  \&lt;br /&gt;  | tail -n +13 | less -r&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 09 Nov 2005 05:54:19 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/875</guid>
      <author>madphilosopher (Darren Paul Griffith)</author>
    </item>
  </channel>
</rss>
