<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>-::dougmccall.com::-</title>
	<atom:link href="http://www.dougmccall.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dougmccall.com</link>
	<description>I can know it!</description>
	<lastBuildDate>Sat, 23 Apr 2011 13:33:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Fixing Google Contacts CSV Export</title>
		<link>http://www.dougmccall.com/2010/12/21/fixing-google-contacts-csv-export/</link>
		<comments>http://www.dougmccall.com/2010/12/21/fixing-google-contacts-csv-export/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 16:12:50 +0000</pubDate>
		<dc:creator>Doug McCall</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[contacts]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[labels]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.dougmccall.com/?p=60</guid>
		<description><![CDATA[It&#8217;s the annual &#8220;painstakingly write out a ton of Christmas cards and mail them&#8221; time of the year again, however this year I&#8217;ve set out (and succeeded) to make Erin&#8217;s life a little easier. You see, I found this fantastic article that described how one could simply export a Google contacts list to CSV and]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s the annual &#8220;painstakingly write out a ton of Christmas cards and mail them&#8221; time of the year again, however this year I&#8217;ve set out (and succeeded) to make Erin&#8217;s life a little easier.</p>
<p>You see, I found this fantastic <a title="article" href="http://gigaom.com/apple/how-to-printing-mailing-labels-from-address-book/" target="_blank">article</a> that described how one could simply export a Google contacts list to CSV and use the Avery Designer Pro (I&#8217;m using the mac version) to map the columns from the export to generate the labels.  This sounded incredibly easy, and so I set out to try to simplify our Christmas card mailing process&#8230;</p>
<p>After blindly following the guide (see above), I quickly realized there was a <em>huge</em> issue &#8211; Google does not do <em>anything</em> to ensure the resulting CSV file is formatted properly.  While there are many, many columns in the CSV export (including individual fields for the various components of an address), Google has taken the easy way out and simply filled in the &#8220;formatted&#8221; address column along with all of the line breaks occurring from typing the address in.  The end result was the Avery software printing out 2 (or more) separate labels for every contact, with their address being split across them.  So, I decided to fix the CSV file.</p>
<p><span id="more-60"></span>I ended up writing this script in Python, solely because of the built-in CSV library.  I know the new version of Ruby (1.9+) merged the fastercsv gem in, however I just didn&#8217;t want to mess with it.  Essentially, the script does two things:</p>
<ol>
<li>Fixes the &#8220;formatted&#8221; address column to remove any line breaks</li>
<li>Breaks the address up and puts the parts in to their respective columns</li>
</ol>
<p>After loading the &#8220;fixed&#8221; google export file in to the Avery designer, I was able to add the name, address, po box, city, state and zipcode fields to the labels and everything worked like a charm.</p>
<p>At some point, I may get around to turning this in to a a service so one could simply upload the original version and download the fixed, however I just don&#8217;t really have an abundance of time and I wouldn&#8217;t want anyone freaking out about privacy concerns &#8211; so feel free to just download the script and use it.</p>
<p style="padding-left: 30px;">

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #483d8b;">''</span><span style="color: #483d8b;">'
Copyright (c) 2010 Doug McCall [dhm116@dougmccall.com]
&nbsp;
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the &quot;Software&quot;), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
&nbsp;
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
&nbsp;
THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
'</span><span style="color: #483d8b;">''</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">Tkinter</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">csv</span>, tkFileDialog
&nbsp;
master = Tk<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
master.<span style="color: black;">withdraw</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Get the CSV file</span>
filename = tkFileDialog.<span style="color: black;">askopenfilename</span><span style="color: black;">&#40;</span>filetypes=<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'CSV Files'</span>, <span style="color: #483d8b;">'.csv'</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
people = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>filename, <span style="color: #483d8b;">&quot;rb&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
rows = people.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># We've got the rows, so close the actual file</span>
people.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Remove the header row so it's not processed</span>
header = rows.<span style="color: black;">pop</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Start a list of corrected addresses</span>
fixed = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Iterate through the rows of data</span>
<span style="color: #ff7700;font-weight:bold;">for</span> row <span style="color: #ff7700;font-weight:bold;">in</span> rows:
    <span style="color: #808080; font-style: italic;"># Store this row in something else in case we can't directly manipulate the row data</span>
    data = row
&nbsp;
    <span style="color: #808080; font-style: italic;"># This should probably be corrected, but for now just arbitrarily pick some length</span>
    <span style="color: #808080; font-style: italic;"># for the contact line to be longer than</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>row<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">50</span>:
        <span style="color: #808080; font-style: italic;">#print &quot;Adding new address line&quot;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># If we already have some corrected addresses, append a new line</span>
        <span style="color: #808080; font-style: italic;"># * This probably isn't necessary any more now that I'm feeding the</span>
        <span style="color: #808080; font-style: italic;">#   fixed data as a list to the CSV reader</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>fixed<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:
            index = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>fixed<span style="color: black;">&#41;</span> - <span style="color: #ff4500;">1</span>
            fixed<span style="color: black;">&#91;</span>index<span style="color: black;">&#93;</span> = <span style="color: #483d8b;">''</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>fixed<span style="color: black;">&#91;</span>index<span style="color: black;">&#93;</span>, <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Add the data to the list of corrected data with any carriage returns removed</span>
        fixed.<span style="color: black;">append</span><span style="color: black;">&#40;</span>data.<span style="color: black;">rstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">#print &quot;\t&quot; + fixed[len(fixed) - 1]</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #808080; font-style: italic;"># We've found a fragmented address line</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">#print &quot;\tAdding split address line&quot;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Strip off the carriage return at the end</span>
        data = data.<span style="color: black;">rstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">#print &quot;\t\t&quot; + data</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Join this fragmented address line to the previous line of data</span>
        index = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>fixed<span style="color: black;">&#41;</span> - <span style="color: #ff4500;">1</span>
        fixed<span style="color: black;">&#91;</span>index<span style="color: black;">&#93;</span> = <span style="color: #483d8b;">', '</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>fixed<span style="color: black;">&#91;</span>index<span style="color: black;">&#93;</span>, data<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">#print &quot;\tFixed version&quot;</span>
        <span style="color: #808080; font-style: italic;">#print &quot;\t\t&quot; + fixed[index]</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">#if data.count(',,,,,,,,,,,,,,,,,,,,,,,') == 0:</span>
        <span style="color: #808080; font-style: italic;">#    print 'Looking for the next full address'</span>
        <span style="color: #808080; font-style: italic;">#    row_start = True</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Put the header row back in the corrected data</span>
fixed.<span style="color: black;">insert</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>,header<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Load the corrected data in to the CSV reader to more easily manipulate the columns</span>
spamReader = <span style="color: #dc143c;">csv</span>.<span style="color: black;">reader</span><span style="color: black;">&#40;</span>fixed, delimiter=<span style="color: #483d8b;">','</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Ask the user where to save the resulting data    </span>
filename = tkFileDialog.<span style="color: black;">asksaveasfilename</span><span style="color: black;">&#40;</span>filetypes=<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'CSV Files'</span>, <span style="color: #483d8b;">'.csv'</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
f2 = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>filename, <span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span>
&nbsp;
writer = <span style="color: #dc143c;">csv</span>.<span style="color: black;">writer</span><span style="color: black;">&#40;</span>f2, delimiter=<span style="color: #483d8b;">','</span><span style="color: black;">&#41;</span>
&nbsp;
rownum = <span style="color: #ff4500;">0</span>
<span style="color: #ff7700;font-weight:bold;">for</span> row <span style="color: #ff7700;font-weight:bold;">in</span> spamReader:
    <span style="color: #ff7700;font-weight:bold;">if</span> rownum <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:
        <span style="color: #808080; font-style: italic;"># Print out the fully corrected address for debugging</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>rownum<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;: &quot;</span> + row<span style="color: black;">&#91;</span><span style="color: #ff4500;">36</span><span style="color: black;">&#93;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Isolate the address parts</span>
        addr = row<span style="color: black;">&#91;</span><span style="color: #ff4500;">36</span><span style="color: black;">&#93;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">','</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Obtain the State and Zip code from the last part of the address</span>
        state_zip = addr.<span style="color: black;">pop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># If we're not using state abbreviations and there is a space in the state</span>
        <span style="color: #808080; font-style: italic;"># name, we need to merge those back together</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>state_zip<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">2</span>:
            state_zip<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> = state_zip<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> + <span style="color: #483d8b;">&quot; &quot;</span> + state_zip<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
&nbsp;
            <span style="color: #808080; font-style: italic;"># Get rid of the unneeded parts from the merge</span>
            state_zip.<span style="color: black;">pop</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Combine the state and zip back in with the address</span>
        addr.<span style="color: black;">extend</span><span style="color: black;">&#40;</span>state_zip<span style="color: black;">&#41;</span>
        <span style="color: #808080; font-style: italic;">#print addr</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Set the address column data</span>
        row<span style="color: black;">&#91;</span><span style="color: #ff4500;">37</span><span style="color: black;">&#93;</span> = addr<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Set the city</span>
        row<span style="color: black;">&#91;</span><span style="color: #ff4500;">38</span><span style="color: black;">&#93;</span> = addr<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span>.<span style="color: black;">lstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># If there is a secondary address (apt. num, etc.)</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>addr<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">4</span>:
            row<span style="color: black;">&#91;</span><span style="color: #ff4500;">39</span><span style="color: black;">&#93;</span> = addr<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Set the state</span>
        row<span style="color: black;">&#91;</span><span style="color: #ff4500;">40</span><span style="color: black;">&#93;</span> = addr<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;"># Set the zip code</span>
        row<span style="color: black;">&#91;</span><span style="color: #ff4500;">41</span><span style="color: black;">&#93;</span> = addr<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">#print row</span>
&nbsp;
    writer.<span style="color: black;">writerow</span><span style="color: black;">&#40;</span>row<span style="color: black;">&#41;</span>
    rownum += <span style="color: #ff4500;">1</span>
&nbsp;
f2.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

</p>
<p style="padding-left: 30px;">This requires python 2.6 or 2.7 (might work on older version, but I haven&#8217;t tested).</p>
<p style="padding-left: 30px;">Just run the script using &#8216;<strong>python fix-addresses.py</strong>&#8216; and it will prompt you for the original csv file and where you would like to save the results.</p>
<p>I&#8217;d love to hear back if anyone makes improvements!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougmccall.com/2010/12/21/fixing-google-contacts-csv-export/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solving a Permutations problem</title>
		<link>http://www.dougmccall.com/2010/04/19/solving-a-permutations-problem/</link>
		<comments>http://www.dougmccall.com/2010/04/19/solving-a-permutations-problem/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 04:49:23 +0000</pubDate>
		<dc:creator>Doug McCall</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[permutations]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.dougmccall.com/?p=35</guid>
		<description><![CDATA[An example javascript algorithm for generating all permutations without repeating elements for a given power-set.]]></description>
			<content:encoded><![CDATA[<p>The wife and I have been having problems settling on baby names for our first child (coming any day now!), so I decided that I&#8217;d see if I couldn&#8217;t help out with a simple web app that would let us put in the names we are considering and spit out all of the possible permutations.  After performing a modicum of research in to combination and permutation algorithms for both javascript and ruby (I decided the fastest way to get this done was with rails), I quickly realized that my problem wasn&#8217;t as simple as most of these algorithms made it out to be.  See, I didn&#8217;t need all of the permutations of an array of size <em>n</em>, as that represented all of the names and not just the few that usually make up someones first and middle name(s).  What I needed was an algorithm that listed all of the permutations of an array for a given resulting array size without repetition.  I remember finding a particular example that generated permutations in to power-sets, which I could have then just filtered out anything that didn&#8217;t match the power-set the user specified, however I can&#8217;t recall why that approach didn&#8217;t work out.<br />
<span id="more-35"></span><br />
Long story short, I really did not find anything (javascript or ruby) that fit the bill, so I was stuck having to come up with my own.  It ended up being pretty simplistic once it was all said an done as most of the work is just merging the arrays together.  I decided to write this in javascript for a couple reasons &#8211; 1) it was much easier (and hence faster) since I am much more familiar with actionscript than ruby, and 2) I wanted a simple way to update the results on the page without having to write all of the rails code necessary to achieve the same results.  The downside to having this as pure javascript is that it is client-side intensive once you increase the number of names included.</p>
<p>Let me start with an example of what I&#8217;m talking about:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Given an array [0,1,2,3], generate all permutations for a set of 2 numbers</span>
     <span style="color: #006600; font-style: italic;">// [0,1], [0,2], [0,3], [0,4], [1,0], [1,2]...[3,2]</span>
<span style="color: #006600; font-style: italic;">// Generate all permutations for a set of 3</span>
     <span style="color: #006600; font-style: italic;">// [0,1,2], [0,1,3], [0,2,1], [0,2,3], [0,3,1]...[3,2,1]</span></pre></div></div>

<p>Here is the code I came up with:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> generateCombinations<span style="color: #009900;">&#40;</span>array<span style="color: #339933;">,</span> r<span style="color: #339933;">,</span> callback<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> length <span style="color: #339933;">=</span> array.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> results <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&lt;</span> length<span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> rows <span style="color: #339933;">=</span> recurse<span style="color: #009900;">&#40;</span>array<span style="color: #339933;">,</span> x<span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> r<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//mergeResults(results, rows);</span>
    <span style="color: #003366; font-weight: bold;">var</span> rowslength <span style="color: #339933;">=</span> rows.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> y <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&lt;</span> rowslength<span style="color: #339933;">;</span> y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      results.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>rows<span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  callback<span style="color: #009900;">&#40;</span>results<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> recurse<span style="color: #009900;">&#40;</span>array<span style="color: #339933;">,</span> index<span style="color: #339933;">,</span> level<span style="color: #339933;">,</span> r<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> num <span style="color: #339933;">=</span> array.<span style="color: #660066;">splice</span><span style="color: #009900;">&#40;</span>index<span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> row <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&lt;</span> array.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>level <span style="color: #339933;">&lt;</span> r <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">var</span> combo <span style="color: #339933;">=</span> mergeResults<span style="color: #009900;">&#40;</span>num<span style="color: #339933;">,</span>recurse<span style="color: #009900;">&#40;</span>array<span style="color: #339933;">,</span> x<span style="color: #339933;">,</span> level <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> r<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #003366; font-weight: bold;">var</span> combolength <span style="color: #339933;">=</span> combo.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> y <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> y <span style="color: #339933;">&lt;</span> combolength<span style="color: #339933;">;</span> y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
        row.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>combo<span style="color: #009900;">&#91;</span>y<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
      row.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>num.<span style="color: #660066;">concat</span><span style="color: #009900;">&#40;</span>array<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  array.<span style="color: #660066;">splice</span><span style="color: #009900;">&#40;</span>index<span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> num<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">return</span> row<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> mergeResults<span style="color: #009900;">&#40;</span>target<span style="color: #339933;">,</span> source<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> length <span style="color: #339933;">=</span> source.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> results <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&lt;</span> length<span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    results.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>target.<span style="color: #660066;">concat</span><span style="color: #009900;">&#40;</span>source<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">return</span> results<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> generateButtonClick<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> n <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;one&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;two&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;three&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;four&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;five&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> r <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;howmany&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> startswith <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'startswith'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> contains <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'contains'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> result <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;namelist&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    result.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
    generateCombinations<span style="color: #009900;">&#40;</span>n<span style="color: #339933;">,</span> r<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>combo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> x <span style="color: #339933;">&lt;</span> combo.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">name</span> <span style="color: #339933;">=</span> combo<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> li <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Element<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">update</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>startswith <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
          <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>combo<span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> startswith<span style="color: #009900;">&#41;</span>
            li <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>contains <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066;">name</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>contains<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
          li <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>li <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
          result.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>li<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>So, being that I was using this to generate baby name combinations, I added a couple filters that allowed us to see only the permutations that started with a selected name, or only those that contained a selected name, or a combination of the two.</p>
<p>Obviously there is lots of room for improvement, both in the algorithm and in the functionality provided.  Being able to dynamically substitute spelling variations in the output or being able to mark a particular combination as liked for future retrieval would definitely be handy.  I would like to go back (someday) and re-implement the algorithm in ruby and leverage the rails framework to perform the permutation calculations on the server-side.</p>
<p>Anyways, I hope someone can make use of this or improve upon it for future use.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougmccall.com/2010/04/19/solving-a-permutations-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Syntax Highlighter Test</title>
		<link>http://www.dougmccall.com/2010/02/22/syntax-highlighter-test/</link>
		<comments>http://www.dougmccall.com/2010/02/22/syntax-highlighter-test/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 02:12:47 +0000</pubDate>
		<dc:creator>Doug McCall</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[highlighter]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[secure]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://www.dougmccall.com/?p=10</guid>
		<description><![CDATA[I thought I&#8217;d test out this syntax highlighter by showing an example of creating a secure download site in PHP&#8230; So, let me preface this by saying that I wanted a dead simple way to manage multiple users, each with separate files and passwords, all with some resemblance to a secured site using Auth-Digest authentication. ]]></description>
			<content:encoded><![CDATA[<p>I thought I&#8217;d test out this syntax highlighter by showing an example of creating a secure download site in PHP&#8230;</p>
<p><span id="more-10"></span></p>
<p>So, let me preface this by saying that I wanted a dead simple way to manage multiple users, each with separate files and passwords, all with some resemblance to a secured site using Auth-Digest authentication.  To me that meant no databases involved and no files accessible directly from the site root.</p>
<p>What I ended up with was this &#8211; a folder located outside the site root that contains sub-folders for each user.  Each sub-folder represents a particular user &#8211; at the moment, the folder name is the user name, however that could easily be changed.  Within that folder is a password file called &#8220;.auth.txt&#8221; which, obviously, contains the users password.</p>
<p><ins datetime="2010-02-26T01:26:22+00:00">Update:</p>
<p>I realized that I screwed up the logic that actually retrieved the file for the user, so that is fixed now.</ins></p>
<p>So, here we go:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$realm</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Restricted area'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$logged_in</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$users</span> <span style="color: #339933;">=</span> loadUsers<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/home/dhm116/Secured&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//var_dump($users);</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_AUTH_DIGEST'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.1 401 Unauthorized'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WWW-Authenticate: Digest realm=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$realm</span><span style="color: #339933;">.</span>
           <span style="color: #0000ff;">'&quot;,qop=&quot;auth&quot;,nonce=&quot;'</span><span style="color: #339933;">.</span><span style="color: #990000;">uniqid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;,opaque=&quot;'</span><span style="color: #339933;">.</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$realm</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'You may not access this area without properly authenticating'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// analyze the PHP_AUTH_DIGEST variable</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> http_digest_parse<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_AUTH_DIGEST'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span>
    <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.1 401 Unauthorized'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WWW-Authenticate: Digest realm=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$realm</span><span style="color: #339933;">.</span>
			   <span style="color: #0000ff;">'&quot;,qop=&quot;auth&quot;,nonce=&quot;'</span><span style="color: #339933;">.</span><span style="color: #990000;">uniqid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;,opaque=&quot;'</span><span style="color: #339933;">.</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$realm</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Wrong Credentials!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// generate the valid response</span>
<span style="color: #000088;">$A1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$realm</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;pwd&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$A2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_METHOD'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uri'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$valid_response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$A1</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nonce'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nc'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cnonce'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'qop'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span><span style="color: #000088;">$A2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'response'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$valid_response</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.1 401 Unauthorized'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WWW-Authenticate: Digest realm=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$realm</span><span style="color: #339933;">.</span>
		   <span style="color: #0000ff;">'&quot;,qop=&quot;auth&quot;,nonce=&quot;'</span><span style="color: #339933;">.</span><span style="color: #990000;">uniqid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;,opaque=&quot;'</span><span style="color: #339933;">.</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$realm</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Wrong Credentials!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// ok, valid username &amp; password</span>
<span style="color: #666666; font-style: italic;">//echo 'Your are logged in as: ' . $data['username'];</span>
<span style="color: #000088;">$logged_in</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// function to parse the http auth header</span>
<span style="color: #000000; font-weight: bold;">function</span> http_digest_parse<span style="color: #009900;">&#40;</span><span style="color: #000088;">$txt</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// protect against missing data</span>
    <span style="color: #000088;">$needed_parts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'nonce'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'nc'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cnonce'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'qop'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'username'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'uri'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'response'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'|'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$needed_parts</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@('</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$keys</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">')=(?:([\'&quot;])([^\2]+?)\2|([^\s,]+))@'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$txt</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #339933;">,</span> PREG_SET_ORDER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$m</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$m</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$m</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span> ? <span style="color: #000088;">$m</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$m</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$needed_parts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$m</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$needed_parts</span> ? <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;file&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$logged_in</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	send_download<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;file&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> send_download<span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$file_path</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/home/dhm116/Secured/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$filename</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$file_size</span><span style="color: #339933;">=@</span><span style="color: #990000;">filesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: application/x-zip-compressed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-disposition: attachment; filename=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$filename</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Length: <span style="color: #006699; font-weight: bold;">$file_size</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">readfile</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> loadUsers <span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// create a handler for the directory</span>
    <span style="color: #000088;">$handler</span> <span style="color: #339933;">=</span> <span style="color: #990000;">opendir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// keep going until all files in directory have been read</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">readdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handler</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// if $file isn't this directory or its parent, </span>
        <span style="color: #666666; font-style: italic;">// add it to the results array</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'.'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'..'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$myFile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$directory</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/.auth.txt&quot;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$myFile</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$fh</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$myFile</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// Load and set the user password</span>
				<span style="color: #000088;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;pwd&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fh</span><span style="color: #339933;">,</span> <span style="color: #990000;">filesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$myFile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
				<span style="color: #666666; font-style: italic;">// Set the files within that user directory</span>
				<span style="color: #000088;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;files&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> dirList<span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// tidy up: close the handler</span>
    <span style="color: #990000;">closedir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// done!</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$users</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> dirList <span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// create an array to hold directory list</span>
    <span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// create a handler for the directory</span>
    <span style="color: #000088;">$handler</span> <span style="color: #339933;">=</span> <span style="color: #990000;">opendir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// keep going until all files in directory have been read</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">readdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handler</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// if $file isn't this directory or its parent, </span>
        <span style="color: #666666; font-style: italic;">// add it to the results array</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'.'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'..'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'.auth.txt'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// tidy up: close the handler</span>
    <span style="color: #990000;">closedir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// done!</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$results</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;html&gt;
	&lt;head&gt;&lt;h1&gt;Secure Download Area&lt;/h1&gt;&lt;/head&gt;
	&lt;body&gt;
		&lt;p&gt;Files available for <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/p&gt;
		&lt;ul&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span>
			<span style="color: #000088;">$filelist</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;files&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filelist</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;li&gt;&lt;a href=&quot;securedownload.php?user=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;file=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Download <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/li&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;/ul&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.dougmccall.com/2010/02/22/syntax-highlighter-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rewiring</title>
		<link>http://www.dougmccall.com/2010/01/27/rewiring/</link>
		<comments>http://www.dougmccall.com/2010/01/27/rewiring/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 14:04:15 +0000</pubDate>
		<dc:creator>Doug McCall</dc:creator>
				<category><![CDATA[diy]]></category>

		<guid isPermaLink="false">http://www.dougmccall.com/?p=7</guid>
		<description><![CDATA[So, I&#8217;ve finally gotten around to running CAT6 and Coax around to the various rooms in our house that needed them.  Having a gigabit network running is definitely a step of from a spotty wireless 54G connection &#8211; plus now we have 2 wireless N access points running.  One AP is upstairs and one is]]></description>
			<content:encoded><![CDATA[<p>So, I&#8217;ve finally gotten around to running CAT6 and Coax around to the various rooms in our house that needed them.  Having a gigabit network running is definitely a step of from a spotty wireless 54G connection &#8211; plus now we have 2 wireless N access points running.  One AP is upstairs and one is downstairs, allowing our laptops to roam to either one (since they&#8217;re on different channels).</p>
<p><span id="more-7"></span>I still can&#8217;t figure out why the wireless signal between floors is so shotty.  I thought it might have been our 5GHz phones, but I turned all of those off once to see what effect it had&#8230;which turned out to be none.  Anyone have any scientific analysis to share?</p>
<p>I still need to finish running the Coax and CAT6 to the attic, but that&#8217;s another can of worms entirely.  See, I also need to run new power and lighting in the attic, which wouldn&#8217;t be so bad except that the flooring runs <em>under</em> the walls up there.  This means that I need to pop the baseboards off, pull out one of the floor boards to expose the joists and then run the wiring through.  Sounds easy enough&#8230;.except when you throw in 100 year old plaster and not wanting to have to do large quantities of plaster repairs <img src='http://www.dougmccall.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougmccall.com/2010/01/27/rewiring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Back to the internets</title>
		<link>http://www.dougmccall.com/2010/01/27/back-to-the-internets/</link>
		<comments>http://www.dougmccall.com/2010/01/27/back-to-the-internets/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 13:52:43 +0000</pubDate>
		<dc:creator>Doug McCall</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.dougmccall.com/?p=3</guid>
		<description><![CDATA[I haven&#8217;t been posting anything for a while since I&#8217;ve switched web hosts, so I hope to change that.  Erin and I have been busy getting some last-minute home renovations completed before our baby boy comes in May!!! I hope to begin getting my portfolio online as well as posting new music whenever I/we come]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t been posting anything for a while since I&#8217;ve switched web hosts, so I hope to change that.  Erin and I have been busy getting some last-minute home renovations completed before our baby boy comes in May!!!</p>
<p>I hope to begin getting my portfolio online as well as posting new music whenever I/we come up with something worth listening to &#8211; so stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougmccall.com/2010/01/27/back-to-the-internets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

